diff --git a/bot/.env b/bot/.env deleted file mode 100644 index f63c199..0000000 --- a/bot/.env +++ /dev/null @@ -1 +0,0 @@ -DISCORD_BOT_TOKEN="" diff --git a/bot/botlog.js b/bot/botlog.js deleted file mode 100644 index 16ffae7..0000000 --- a/bot/botlog.js +++ /dev/null @@ -1,157 +0,0 @@ -const { Client, MessageEmbed, MessageActionRow, MessageButton } = require("discord.js"); -const options = { intents: [3276799] }; -const client = new Client(options); - -const fs = require("fs"); -const config = JSON.parse(fs.readFileSync("./config.json", 'utf8')); - -//bot join & bot leave -client.on('guildCreate',async guild => { - try { - let px = config.prefix; - const guildId = guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (fs.existsSync(settingsFilePath)) { - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings?.prefix) { - px = settings.prefix; - } - } - const sendEmbed = new MessageEmbed() - .setTitle("導入ありがとうございます!") - .setThumbnail(client.user.displayAvatarURL()) - .setDescription(`プレフィックスは ${px} です!\n**${px}setup** を実行してサーバーの保護を開始します!`) - .setFooter({text: `${px}prefix {new prefix} でプレフィックスを変更できます`}) - .addFields([ - { - name: 'サポートサーバー', - value: 'https://discord.gg/yKW8wWKCnS' - } - ]) - .setColor(config.color); - const sendCh = guild?.systemChannel; - if (sendCh) { - await sendCh.send({ embeds: [sendEmbed] }); - } - } catch (e) { - console.error(e); - } - const ch = client.channels.cache.get(config.log_channel); - await ch.send(`**${guild.name}** (${guild.id}) に参加しました`); - setTimeout(()=>{ - ch.send(`guild_info ${guild.id}`); - },3000) -}) -client.on('interactionCreate', async interaction => { - const allowedUser = '957885295251034112'; - if (interaction.member.id !== allowedUser) return; - if (!interaction.isButton()) return; - if (interaction.customId.startsWith('guild_invite')){ - const guildId = interaction.customId.split('-')[1] - const guild = client.guilds.cache.get(guildId); - if (!guild) return interaction.reply({content:'指定されたサーバーが見つかりませんでした',ephemeral:true}); - try{ - const invites = await guild.invites.fetch(); - if (invites.size > 0) { - const inviteLinks = invites.map(invite => invite.url); - interaction.reply({ content: inviteLinks.join('\n'), ephemeral: true }); - } else { - try { - const channel = guild.channels.cache.find(channel => channel.type === 'GUILD_TEXT' && channel.permissionsFor(guild.me).has('CREATE_INSTANT_INVITE')) || undefined; - if(!channel) return interaction.reply({content:`Error creating invite.`,ephemeral:true}); - const createdInvite = await guild.invites.create(channel.id, {maxUses: 0, maxAge: 0}) - interaction.reply({content:`No valid invites found. Created a new invite:\nhttps://discord.gg/${createdInvite.code}`,ephemeral:true}); - } catch (error) { - interaction.reply({content:`Error creating invite.`,ephemeral:true}); - console.error(error) - } - } - }catch(e){ - interaction.reply({content:`Error getting invite.`,ephemeral:true}); - console.error(e) - } - } - if (interaction.customId.startsWith('guild_leave')){ - await interaction.deferReply({ephemeral:true}) - const guildId = interaction.customId.split('-')[1] - const guild = client.guilds.cache.get(guildId); - if (!guild) return await interaction.editReply({content:'指定されたサーバーが見つかりませんでした',ephemeral:true}); - try { - await guild.leave(); - await interaction.editReply({content:`${guild.name} から退出しました`,ephemeral:true}); - } catch (error) { - console.error(`${guild.name} からの退出に失敗しました:`, error); - await interaction.editReply({content:`${guild.name} からの退出に失敗しました`,ephemeral:true}); - } - } -}) -client.on('guildDelete', guild => { - const ch = client.channels.cache.get(config.log_channel); - ch.send(`**${guild.name}** (${guild.id}) から退出しました`); -}) - -function replaces(input, replacements) { - let output = input; - - for (const [search, replace] of replacements) { - const regex = new RegExp(search, 'g'); - output = output.replace(regex, replace); - } - - return output; -} - -// コマンドを実行するユーザーのID -const allowedUser = config.bot_owner; - -// m#guild_invite {serverID} というコマンドが入力された場合の処理 -client.on('messageCreate', async message => { - if (!message.content.startsWith('guild_info')) return; - if (message.author.id === client.user.id){ - if(message.channel.id !== config.log_channel){ - return; - } - } else { - if (message.author.id !== allowedUser) { - return; - } - } - const args = message.content.slice('guild_info'.length).trim().split(/ +/); - const guildId = args[0]; - if(!guildId) return message.channel.send('IDを指定してください') - const guild = await client.guilds.fetch(guildId) || null; - if(!guild) return message.channel.send('サーバーが見つかりませんでした') - const ch = message.channel - const members = await guild.members.fetch(); - let bot = 0; - members.forEach(member => { - if (member.user.bot) { - bot++; - } - }); - const owner = await guild.members.fetch(guild.ownerId); - const embed = new MessageEmbed() - .setTitle('サーバー情報') - .setThumbnail(guild.iconURL()) - .addField(`name`,`${guild.name}`) - .addField(`ID`,`${guild.id}`) - .addField(`owner`,`${owner.user.tag} (ID: ${guild.ownerId})`) - .addField(`member count`,`**${guild.memberCount}** members (**${guild.memberCount - bot}** users, **${bot}** bots)`) - .setColor('GREEN'); - const row = new MessageActionRow() - .addComponents( - new MessageButton() - .setCustomId(`guild_invite-${guild.id}`) - .setLabel('Get invite for this server') - .setStyle('PRIMARY') - ) - .addComponents( - new MessageButton() - .setCustomId(`guild_leave-${guild.id}`) - .setLabel('Leave bot from this server') - .setStyle('DANGER') - ) - ch.send({embeds: [embed],components: [row]}); -}); - -client.login(process.env.DISCORD_BOT_TOKEN); \ No newline at end of file diff --git a/bot/commands/0-help.js b/bot/commands/0-help.js deleted file mode 100644 index d9d4870..0000000 --- a/bot/commands/0-help.js +++ /dev/null @@ -1,104 +0,0 @@ -const { MessageEmbed, MessageActionRow, MessageButton } = require("discord.js"); -const fs = require('fs') - -module.exports = { - name: 'help', - usage: 'help', - aliases: ['h'], - description: 'ヘルプを表示します', - async execute(client, message, args, config) { - - let prefix = config.prefix; - const guildId = message.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (fs.existsSync(settingsFilePath)) { - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings?.prefix) { - prefix = settings.prefix; - } - } - - const commands = client.commands; - const pageSize = 5; // 1ページあたりのコマンド数 - const totalPages = Math.ceil(commands.size / pageSize); - - let page = 1; - - const generateEmbed = () => { - const startIdx = (page - 1) * pageSize; - const endIdx = startIdx + pageSize; - const currentCommands = Array.from(commands.values()).slice(startIdx, endIdx); - - const description = currentCommands.map(cmd => `**${prefix}${cmd.usage}** ${cmd.aliases?.length > 0 ? `(aliases: \`${cmd.aliases.join(', ')}\`)` : ''} ${cmd.description ?? '説明がありません'}`).join('\n'); - const embed = new MessageEmbed() - .setTitle(`ヘルプ - ${page}/${totalPages} (${commands.size} commands)`) - .setDescription(description) - .addFields([ - { - name: '招待', - value: `[Invite Link](https://discord.com/api/oauth2/authorize?client_id=${client.user.id}&permissions=8&scope=bot%20applications.commands)` - }, - { - name: 'サポートサーバー', - value: config.support - }, - { - name: 'ドキュメント', - value: config.docs - } - ]) - .setColor(config.color) - .setFooter({ text: `prefix => ${prefix} | {} => required, () => optional` }); - - return embed; - }; - - const row = new MessageActionRow() - .addComponents( - new MessageButton() - .setCustomId('prev') - .setLabel('Prev') - .setEmoji('1085574066674614272') - .setStyle('PRIMARY'), - new MessageButton() - .setCustomId('delete') - .setLabel('Delete') - .setStyle('DANGER'), - new MessageButton() - .setCustomId('next') - .setLabel('Next') - .setEmoji('1085573995694395412') - .setStyle('PRIMARY') - ); - - const messageComponent = await message.channel.send({ - embeds: [generateEmbed()], - components: [row], - }); - - const filter = (interaction) => { - return interaction.customId === 'prev' || interaction.customId === 'next'; - }; - - const collector = messageComponent.createMessageComponentCollector({ filter, time: 300000 }); // 5分間ボタンが有効 - - collector.on('collect', async (interaction) => { - if (interaction.customId === 'prev') { - page = page > 1 ? page - 1 : totalPages; // 前のページに移動、ページが1の場合は最後のページにループ - } else if (interaction.customId === 'next') { - page = page < totalPages ? page + 1 : 1; // 次のページに移動、最後のページの場合は最初のページにループ - } - - await interaction.update({ embeds: [generateEmbed()] }); - }); - - collector.on('end', () => { - row.components.forEach(component => { - if (component.customId !== 'delete') { - component.setDisabled(true); - } - }); - messageComponent.edit({ components: [row] }); - }); - }, -}; diff --git a/bot/commands/0-ping.js b/bot/commands/0-ping.js deleted file mode 100644 index 764b28a..0000000 --- a/bot/commands/0-ping.js +++ /dev/null @@ -1,28 +0,0 @@ -const { MessageEmbed } = require("discord.js"); - -module.exports = { - name: 'ping', - usage: 'ping', - aliases: [], - description: 'Ping値を表示します', - async execute(client, message, args, config) { - const embed = new MessageEmbed() - .setTitle('Pong!') - .addFields( - [ - { - name: 'Web Socket', - value: `${client.ws.ping} ms` - }, - { - name: 'API Endpoint', - value: `${Date.now() - message.createdTimestamp} ms` - } - ] - ) - .setColor(config.color) - .setTimestamp() - - await message.reply({ embeds: [embed] }); - }, -}; \ No newline at end of file diff --git a/bot/commands/0-prefix.js b/bot/commands/0-prefix.js deleted file mode 100644 index 7b0280b..0000000 --- a/bot/commands/0-prefix.js +++ /dev/null @@ -1,64 +0,0 @@ -const { MessageEmbed } = require("discord.js"); -const fs = require("fs"); - -module.exports = { - name: 'prefix', - usage: 'prefix {new prefix}', - aliases: [], - description: 'プレフィックスを変更します', - async execute(client, message, args, config) { - const err_embed = new MessageEmbed() - .setTitle("プレフィックス") - if (!message.member.permissions.has("ADMINISTRATOR")) { - err_embed.setDescription(`❌ 管理者権限が必要です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - let prefix = config.prefix; - const guildId = message.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (fs.existsSync(settingsFilePath)) { - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings?.prefix) { - prefix = settings.prefix; - } - } - - if (!fs.existsSync(settingsFilePath)) { - err_embed.setDescription(`❌ 先に ${prefix}setup を実行してください`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - - if (args.length < 1) { - err_embed.setDescription(`❌ 値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - let px = args[0]; - if (px.length > 5) { - err_embed.setDescription(`❌ プレフィックスが長すぎます`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - px = px.toLowerCase() === 'reset' ? null : px; - prefix = px === null ? config.prefix : px; - settings.prefix = px; - fs.writeFileSync(settingsFilePath, JSON.stringify(settings, null, 2)); - try { - const embed = new MessageEmbed() - .setTitle("プレフィックス") - .setDescription(`✅ プレフィックスを${px === null?'リセット':` ${px} に変更`}しました`) - .setFooter({text: `リセットする場合は ${prefix}prefix reset と送信してください`}) - .setColor(config.color); - await message.channel.send({ embeds: [embed] }) - } catch (e) { - err_embed.setDescription(`❌ エラーが発生しました`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - console.error(e); - } - }, -}; \ No newline at end of file diff --git a/bot/commands/0-setup.js b/bot/commands/0-setup.js deleted file mode 100644 index 8953950..0000000 --- a/bot/commands/0-setup.js +++ /dev/null @@ -1,258 +0,0 @@ -const { MessageEmbed } = require("discord.js"); -const fs = require("fs"); - -const cooldowns = new Map(); - -module.exports = { - name: 'setup', - usage: 'setup', - aliases: ['s'], - description: 'セットアップします', - async execute(client, message, args, config) { - - const cooldownKey = message.guild.id; - - const startTime = Date.now(); - let setupMessage = `✅ セットアップ開始`; - const embed = new MessageEmbed() - .setTitle("セットアップ") - .setDescription(setupMessage) - .setColor(config.color); - if (!message.guild.me.permissions.has("ADMINISTRATOR") || !message.member.permissions.has("ADMINISTRATOR")) { - setupMessage = `❌ 管理者権限が必要です`; - embed.setDescription(setupMessage).setColor('RED'); - await message.channel.send({ embeds: [embed] }); - return; - } - - if (cooldowns.has(cooldownKey)) { - const cooldownTime = cooldowns.get(cooldownKey); - const currentTime = Date.now(); - - if (currentTime < cooldownTime) { - const remainingTime = Math.ceil((cooldownTime - currentTime) / 1000); // 秒単位で残り時間を計算 - const remainingMinutes = Math.floor(remainingTime / 60); - const remainingSeconds = remainingTime % 60; - setupMessage = `❌ クールダウン中です (残り ${remainingMinutes != 0 ? `${remainingMinutes} 分 `: ''}${remainingSeconds} 秒)`; - embed.setDescription(setupMessage).setColor('RED'); - const msg = await message.channel.send({ embeds: [embed] }); - return; - } - } - - const msg = await message.channel.send({ embeds: [embed] }); - const cooldownTimeInSeconds = 180; - const cooldownEndTime = startTime + cooldownTimeInSeconds * 1000; - cooldowns.set(cooldownKey, cooldownEndTime); - - try { - const guildId = message.guild.id; - const guildSettings = { - guild_name: message.guild.name, - prefix: null, - mods: [], - channel: { - category: "", - log: "", - msglog: "", - invite: "", - nuke: [], - }, - role: { - muted: "", - autos: [], - }, - setting: { - disable: false, - antispam: true, - antiinvite: true, - antilink: false, - antingwords: true, - ticket_number: { - category: null, - }, - timeout: { - days: 0, - hours: 0, - minutes: 2, - seconds: 0, - antispam: true, - antiinvite: true, - antilink: false, - antingwords: false, - }, - }, - ignore_channels: [], - ignore_roles: [], - ignore_users: [], - ngwords: [], - muted_users: [], - }; - const settingsFilePath = `./settings/${guildId}.json`; - - if (fs.existsSync(settingsFilePath)) { - setupMessage = setupMessage + `\n✅ 既に設定ファイルが存在します`; - } else { - fs.writeFileSync(settingsFilePath, JSON.stringify(guildSettings, null, 2)); - setupMessage = setupMessage + `\n✅ 設定ファイル作成完了`; - } - - embed.setDescription(setupMessage); - await msg.edit({ embeds: [embed] }); - - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - - let category; - if (settings.channel?.category && message.guild.channels.cache.get(settings.channel?.category)) { - setupMessage = setupMessage + `\n✅ 既にカテゴリーが存在します`; - category = message.guild.channels.cache.get(settings.channel?.category); - } else { - category = await message.guild.channels.create('ProteCat', { - type: 'GUILD_CATEGORY', - permissionOverwrites: [ - { - id: message.guild.roles.everyone.id, - deny: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'EMBED_LINKS'], - }, - { - id: client.user.id, - allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'EMBED_LINKS'], - }, - ], - }); - setupMessage = setupMessage + `\n✅ カテゴリー作成完了`; - settings.channel.category = category.id; - fs.writeFileSync(settingsFilePath, JSON.stringify(settings, null, 2)); - } - - let auditLogChannel; - if (settings.channel?.log && message.guild.channels.cache.get(settings.channel?.log)) { - setupMessage = setupMessage + `\n✅ 既にaudit-logチャンネルが存在します`; - auditLogChannel = message.guild.channels.cache.get(settings.channel?.log); - auditLogChannel.setParent(category); - } else { - auditLogChannel = await message.guild.channels.create('protecat-audit-log', { - type: 'GUILD_TEXT', - parent: category, - permissionOverwrites: [ - { - id: message.guild.roles.everyone.id, - deny: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'EMBED_LINKS'], - }, - { - id: client.user.id, - allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'EMBED_LINKS'], - }, - ], - }); - setupMessage = setupMessage + `\n✅ audit-logチャンネル作成完了`; - settings.channel.log = auditLogChannel.id; - fs.writeFileSync(settingsFilePath, JSON.stringify(settings, null, 2)); - } - - let messageLogChannel; - if (settings.channel?.msglog && message.guild.channels.cache.get(settings.channel?.msglog)) { - setupMessage = setupMessage + `\n✅ 既にmessage-logチャンネルが存在します`; - messageLogChannel = message.guild.channels.cache.get(settings.channel?.msglog); - messageLogChannel.setParent(category); - } else { - messageLogChannel = await message.guild.channels.create('protecat-message-log', { - type: 'GUILD_TEXT', - parent: category, - permissionOverwrites: [ - { - id: message.guild.roles.everyone.id, - deny: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'EMBED_LINKS'], - }, - { - id: client.user.id, - allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'EMBED_LINKS'], - }, - ], - }); - setupMessage = setupMessage + `\n✅ message-logチャンネル作成完了`; - settings.channel.msglog = messageLogChannel.id; - fs.writeFileSync(settingsFilePath, JSON.stringify(settings, null, 2)); - } - - let inviteLogChannel; - if (settings.channel?.invite && message.guild.channels.cache.get(settings.channel?.invite)) { - setupMessage = setupMessage + `\n✅ 既にinvite-logチャンネルが存在します`; - inviteLogChannel = message.guild.channels.cache.get(settings.channel?.invite); - inviteLogChannel.setParent(category); - } else { - inviteLogChannel = await message.guild.channels.create('protecat-invite-log', { - type: 'GUILD_TEXT', - parent: category, - permissionOverwrites: [ - { - id: message.guild.roles.everyone.id, - deny: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'EMBED_LINKS'], - }, - { - id: client.user.id, - allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'EMBED_LINKS'], - }, - ], - }); - setupMessage = setupMessage + `\n✅ invite-logチャンネル作成完了`; - settings.channel.invite = inviteLogChannel.id; - fs.writeFileSync(settingsFilePath, JSON.stringify(settings, null, 2)); - } - - let mutedRole; - - if (settings.role?.muted && message.guild.roles.cache.get(settings.role?.muted)) { - setupMessage = setupMessage + `\n✅ 既にMuted Userロールが存在します`; - mutedRole = message.guild.roles.cache.get(settings.role?.muted); - } else { - const highestRole = message.guild.roles.cache - .filter((role) => role.managed === false && role.comparePositionTo(message.guild.me.roles.highest) < 0) - .sort((a, b) => b.comparePositionTo(a)) - .first(); - mutedRole = await message.guild.roles.create({ - name: 'Muted User', - permissions: [], - position: highestRole.position - 1, - mentionable: false, - color: '#000001' - }); - setupMessage = setupMessage + `\n✅ Muted Userロール作成完了`; - settings.role.muted = mutedRole.id; - fs.writeFileSync(settingsFilePath, JSON.stringify(settings, null, 2)); - } - - embed.setDescription(setupMessage); - await msg.edit({ embeds: [embed] }); - - const channels = await message.guild.channels.cache.filter(channel => !channel.type.includes("THREAD")); - - let count = 0; - let setupMessageWithoutCount = setupMessage; - for (const [_, channel] of channels) { - try{ - await channel.permissionOverwrites.edit(mutedRole, { - VIEW_CHANNEL: false, - CONNECT: false, - SEND_MESSAGES: false - }) - } catch (e) { - console.error(e) - } - count = count + 1; - if (count % 10 == 0 || count == channels.size) { - let endTime = Date.now(); - let time = (endTime - startTime) / 1000; - setupMessageWithoutCount = setupMessage + `\n✅ ${count}/${channels.size} チャンネル設定更新完了${count == channels.size ? `\n✅ 全ての設定が完了しました (${time} 秒)`: ''}`; - embed.setDescription(setupMessageWithoutCount); - await msg.edit({ embeds: [embed] }); - } - } - } catch (e) { - setupMessage = setupMessage + `\n❌ エラーが発生しました`; - embed.setDescription(setupMessage).setColor('RED'); - await msg.edit({ embeds: [embed] }); - console.error(e); - } - }, -}; diff --git a/bot/commands/1-disable.js b/bot/commands/1-disable.js deleted file mode 100644 index 2e00b1d..0000000 --- a/bot/commands/1-disable.js +++ /dev/null @@ -1,63 +0,0 @@ -const { MessageEmbed } = require("discord.js"); -const fs = require("fs"); - -module.exports = { - name: 'disable', - usage: 'disable {mode}', - aliases: ['d'], - description: 'サーバー保護設定を変更します (mode: `true, false`)', - async execute(client, message, args, config) { - const err_embed = new MessageEmbed() - .setTitle("サーバー保護設定") - if (!message.member.permissions.has("ADMINISTRATOR")) { - err_embed.setDescription(`❌ 管理者権限が必要です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - let prefix = config.prefix; - const guildId = message.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (fs.existsSync(settingsFilePath)) { - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings?.prefix) { - prefix = settings.prefix; - } - } - - if (!fs.existsSync(settingsFilePath)) { - err_embed.setDescription(`❌ 先に ${prefix}setup を実行してください`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - - if (args.length < 1) { - err_embed.setDescription(`❌ 値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - let mode = args[0].toLowerCase(); - if (mode !== 'true' && mode !== 'false') { - err_embed.setDescription(`❌ {mode} の値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - mode = mode === 'true' ? true : false; - settings.setting.disable = mode; - fs.writeFileSync(settingsFilePath, JSON.stringify(settings, null, 2)); - try { - const embed = new MessageEmbed() - .setTitle("サーバー保護設定") - .setDescription(`✅ サーバー保護を **${mode?'無効':'有効'}** にしました`) - .setFooter({text: `再び ${mode?'有効':'無効'} にする場合は ${prefix}disable ${mode?false:true} と送信してください`}) - .setColor(config.color); - await message.channel.send({ embeds: [embed] }) - } catch (e) { - err_embed.setDescription(`❌ エラーが発生しました`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - console.error(e); - } - }, -}; \ No newline at end of file diff --git a/bot/commands/1-showfile.js b/bot/commands/1-showfile.js deleted file mode 100644 index 12f6e99..0000000 --- a/bot/commands/1-showfile.js +++ /dev/null @@ -1,37 +0,0 @@ -const { MessageEmbed } = require("discord.js"); -const fs = require("fs"); - -module.exports = { - name: 'showfile', - usage: 'showfile', - aliases: ['sf'], - description: '設定ファイル(json形式)を表示します', - async execute(client, message, args, config) { - const err_embed = new MessageEmbed() - .setTitle("設定ファイル"); - - let prefix = config.prefix; - const guildId = message.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (fs.existsSync(settingsFilePath)) { - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings?.prefix) { - prefix = settings.prefix; - } - } - - if (!fs.existsSync(settingsFilePath)) { - err_embed.setDescription(`❌ 先に ${prefix}setup を実行してください`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - try { - await message.channel.send({ content: `${message.guild.name} の設定ファイルです`, files: [settingsFilePath] }); - } catch (e) { - console.error(e); - err_embed.setDescription(`❌ エラーが発生しました`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - } - }, -} diff --git a/bot/commands/1-showinfo.js b/bot/commands/1-showinfo.js deleted file mode 100644 index 2c97143..0000000 --- a/bot/commands/1-showinfo.js +++ /dev/null @@ -1,180 +0,0 @@ -const { MessageEmbed, MessageActionRow, MessageButton } = require("discord.js"); -const fs = require("fs"); - -module.exports = { - name: 'showinfo', - usage: 'showinfo (type)', - aliases: ['si'], - description: '情報を表示します (type: `mods, channels, roles, users, nukes, autoroles, ngwords`)', - async execute(client, message, args, config) { - const err_embed = new MessageEmbed() - .setTitle("情報"); - - let prefix = config.prefix; - const guildId = message.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (fs.existsSync(settingsFilePath)) { - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings?.prefix) { - prefix = settings.prefix; - } - } - - if (!fs.existsSync(settingsFilePath)) { - err_embed.setDescription(`❌ 先に ${prefix}setup を実行してください`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - const mods_roles = settings?.mods; - const ignore_channels = settings?.ignore_channels; - const ignore_roles = settings?.ignore_roles; - const ignore_users = settings?.ignore_users; - const ngwords = settings?.ngwords; - const auto_roles = settings.role?.autos; - const nuke_channels = settings.channel?.nuke; - const timeout = settings.setting?.timeout; - const mods = []; - const channels = []; - const roles = []; - const users = []; - const autoroles = []; - const nukes = []; - for (const role of mods_roles) { - mods.push(`<@&${role}>`) - } - for (const channel of ignore_channels) { - channels.push(`<#${channel}>`) - } - for (const role of ignore_roles) { - roles.push(`<@&${role}>`) - } - for (const user of ignore_users) { - users.push(`<@${user}>`) - } - for (const channel of nuke_channels) { - nukes.push(`<#${channel}>`) - } - for (const role of auto_roles) { - autoroles.push(`<@&${role}>`) - } - - const row = new MessageActionRow() - .addComponents( - new MessageButton() - .setCustomId('delete') - .setLabel('Delete') - .setStyle('DANGER'), - ) - - if (args.length > 0) { - const type = args[0].toLowerCase() - if (type !== 'mods' && type !== 'channels' && type !== 'roles' && type !== 'users' && type !== 'nukes' && type !== 'ngwords' && type !== 'autoroles') { - err_embed.setDescription(`❌ (type) の値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - try { - const show_type = { mods, channels, roles, users, nukes, autoroles, ngwords } - const type_embed = new MessageEmbed() - .setTitle("情報") - .setThumbnail(message.guild.iconURL()) - .setDescription(`### ${type}${show_type[type].length > 0?` - ${show_type[type].length} ${show_type[type].length == 1?type.slice(0, -1):type}`:' - 未設定'}\n${show_type[type].join(' , ')}`) - .setColor(config.color); - await message.channel.send({ embeds: [type_embed], components: [row] }); - } catch (e) { - console.error(e); - err_embed.setDescription(`❌ エラーが発生しました`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - } - } else { - const time = { - days: settings.setting?.timeout?.days, - hours: settings.setting?.timeout?.hours, - minutes: settings.setting?.timeout?.minutes, - seconds: settings.setting?.timeout?.seconds, - } - const embed = new MessageEmbed() - .setTitle("情報") - .setThumbnail(message.guild.iconURL()) - .setDescription(`## サーバー保護: ${!settings.setting?.disable ? '有効': '無効'}\n**antispam**: ${settings.setting?.antispam} (timeout: ${timeout?.antispam})\n**antiinvite**: ${settings.setting?.antiinvite} (timeout: ${timeout?.antiinvite})\n**antilink**: ${settings.setting?.antilink} (timeout: ${timeout?.antilink})\n**antingwords**: ${settings.setting?.antingwords} (timeout: ${timeout?.antingwords})\n**timeoutperiod**: ${time?.days!=0?`${time?.days} 日 `:''}${time?.hours!=0?`${time?.hours} 時間 `:''}${time?.minutes!=0?`${time?.minutes} 分 `:''}${time?.seconds!=0?`${time?.seconds} 秒 `:''}`) - .setColor(config.color); - const category = settings.setting.ticket_number?.category; - const fieldValue = [ - { - name: 'プレフィックス', - value: prefix - }, - { - name: 'チケットカテゴリー', - value: (category && message.guild.channels.cache.get(category)) ? `<#${category}>` : 'デフォルト' - } - ]; - - const maxItemsToShow = 5; // 最大表示アイテム数 - - function formatItems(items, itemName) { - if (items.length > maxItemsToShow) { - const extraItemsCount = items.length - maxItemsToShow; - items = items.slice(0, maxItemsToShow); - items.push(`+ ${extraItemsCount} ${extraItemsCount == 1?itemName.slice(0, -1):itemName}`); - } - return items.join(' , '); - } - - if (mods.length > 0) { - fieldValue.push({ - name: 'モデレーターロール', - value: formatItems(mods, 'roles') - }); - } - if (channels.length > 0) { - fieldValue.push({ - name: 'ホワイトリストチャンネル', - value: formatItems(channels, 'channels') - }); - } - if (roles.length > 0) { - fieldValue.push({ - name: 'ホワイトリストロール', - value: formatItems(roles, 'roles') - }); - } - if (users.length > 0) { - fieldValue.push({ - name: 'ホワイトリストユーザー', - value: formatItems(users, 'users') - }); - } - if (ngwords.length > 0) { - fieldValue.push({ - name: 'NGワード', - value: formatItems(ngwords, 'ngwords') - }); - } - if (nukes.length > 0) { - fieldValue.push({ - name: '再生成チャンネル', - value: formatItems(nukes, 'nukes') - }); - } - if (autoroles.length > 0) { - fieldValue.push({ - name: '自動付与ロール', - value: formatItems(autoroles, 'autoroles') - }); - } - - try { - if (fieldValue.length > 0) { - embed.addFields(fieldValue); - } - await message.channel.send({ embeds: [embed], components: [row] }); - } catch (e) { - console.error(e); - err_embed.setDescription(`❌ エラーが発生しました`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - } - } - }, -} diff --git a/bot/commands/1-showmute.js b/bot/commands/1-showmute.js deleted file mode 100644 index 0f3a38e..0000000 --- a/bot/commands/1-showmute.js +++ /dev/null @@ -1,53 +0,0 @@ -const { MessageEmbed } = require("discord.js"); -const fs = require("fs"); - -module.exports = { - name: 'showmute', - usage: 'showmute', - aliases: ['sm'], - description: 'ミュートユーザーを表示します', - async execute(client, message, args, config) { - const err_embed = new MessageEmbed() - .setTitle("ミュートユーザー") - - let prefix = config.prefix; - const guildId = message.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (fs.existsSync(settingsFilePath)) { - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings?.prefix) { - prefix = settings.prefix; - } - } - - if (!fs.existsSync(settingsFilePath)) { - err_embed.setDescription(`❌ 先に ${prefix}setup を実行してください`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - const muted_users = settings?.muted_users; - let description = '存在しません' - if (muted_users.length > 0) { - const mentions = []; - for (const user of muted_users) { - const member = await message.guild.members.cache.get(user); - if (!member) continue; - mentions.push(`<@${member.user.id}>`) - } - if (mentions.length > 0) description = mentions.join(' , ') - } - try { - const embed = new MessageEmbed() - .setTitle("ミュートユーザー") - .setDescription(description) - .setColor(config.color); - await message.channel.send({ embeds: [embed] }) - } catch (e) { - err_embed.setDescription(`❌ エラーが発生しました`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - console.error(e); - } - }, -}; \ No newline at end of file diff --git a/bot/commands/1-userinfo.js b/bot/commands/1-userinfo.js deleted file mode 100644 index 1552538..0000000 --- a/bot/commands/1-userinfo.js +++ /dev/null @@ -1,94 +0,0 @@ -const { MessageEmbed, MessageActionRow, MessageButton } = require("discord.js"); -const fs = require("fs"); - -module.exports = { - name: 'userinfo', - usage: 'userinfo (user)', - aliases: ['ui'], - description: 'ユーザーの情報を表示します', - async execute(client, message, args, config) { - const err_embed = new MessageEmbed() - .setTitle("ユーザー情報"); - - let prefix = config.prefix; - const guildId = message.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (fs.existsSync(settingsFilePath)) { - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings?.prefix) { - prefix = settings.prefix; - } - } - - if (!fs.existsSync(settingsFilePath)) { - err_embed.setDescription(`❌ 先に ${prefix}setup を実行してください`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - const userId = args[0]?.replace(/<@|!|>/g,'') || message.author.id; - const member = message.guild.members.cache.get(userId); - if (!member) { - err_embed.setDescription(`❌ ユーザーが存在しません`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - const mods = settings?.mods; - const isAdmin = message.member.permissions.has("ADMINISTRATOR"); - const isMod = hasRole(userId, mods); - function hasRole(id, mods) { - let count = 0; - const roles = message.guild.members.cache.get(id).roles?.cache; - if (!roles) { - return false; - } - for (const role of roles.values()) { - if (mods.includes(role.id)) { - count++; - } - } - return count > 0; - } - try { - const roles = []; - const roleIds = await member.roles.cache.map((role) => role.id); - for (const roleId of roleIds) { - const role = `<@&${roleId}>` - roles.push(role); - } - const maxItemsToShow = 10; // 最大表示アイテム数 - function formatItems(items, itemName) { - if (items.length > maxItemsToShow) { - const extraItemsCount = items.length - maxItemsToShow; - items = items.slice(0, maxItemsToShow); - items.push(`+ ${extraItemsCount} ${extraItemsCount == 1?itemName.slice(0, -1):itemName}`); - } - return items.join(' , '); - } - const embed = new MessageEmbed() - .setTitle('ユーザー情報') - .setThumbnail(member.displayAvatarURL()) - .setDescription(`${member}\nName: ${member.user.tag.split('#')[1] === '0' ? member.user.username : member.user.tag}\n${member.user.id}`) - .setColor(config.color) - .addFields([ - { - name: 'Admin?', - value: `${isAdmin}` - }, - { - name: 'Mod?', - value: `${isMod}` - }, - { - name: 'ロール', - value: formatItems(roles, 'roles') - } - ]) - await message.channel.send({ embeds: [embed] }) - } catch (e) { - console.error(e); - err_embed.setDescription(`❌ エラーが発生しました`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - } - }, -} \ No newline at end of file diff --git a/bot/commands/2-autorole.js b/bot/commands/2-autorole.js deleted file mode 100644 index 7ed908d..0000000 --- a/bot/commands/2-autorole.js +++ /dev/null @@ -1,104 +0,0 @@ -const { MessageEmbed } = require("discord.js"); -const fs = require("fs"); - -module.exports = { - name: 'autorole', - usage: 'autorole {mode} (roles...)', - aliases: ['ar'], - description: '自動付与ロールを追加/削除します(mode: `add, remove, reset`)', - async execute(client, message, args, config) { - const err_embed = new MessageEmbed() - .setTitle("自動付与ロール"); - - if (!message.member.permissions.has("ADMINISTRATOR")) { - err_embed.setDescription(`❌ 管理者権限が必要です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - let prefix = config.prefix; - const guildId = message.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (fs.existsSync(settingsFilePath)) { - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings?.prefix) { - prefix = settings.prefix; - } - } - - if (!fs.existsSync(settingsFilePath)) { - err_embed.setDescription(`❌ 先に ${prefix}setup を実行してください`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - - if (args.length < 1) { - err_embed.setDescription(`❌ 値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - const mode = args[0].toLowerCase(); - if (mode === 'reset') { - settings.role.autos = []; - fs.writeFileSync(settingsFilePath, JSON.stringify(settings, null, 2)); - const embed = new MessageEmbed() - .setTitle("自動付与ロール") - .setDescription(`✅ ロールをリセットしました`) - .setColor(config.color); - - await message.channel.send({embeds: [embed]}); - return; - } - - if (args.length < 2) { - err_embed.setDescription(`❌ 値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - if (mode !== 'add' && mode !== 'remove') { - err_embed.setDescription(`❌ {mode} の値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - const roles = args.slice(1); - const result = []; - for (const role of roles) { - const roleId = role.replace(/<@&|>/g,''); - if (message.guild.roles.cache.get(roleId)) { - result.push(roleId); - } - } - console.log(result); - - try { - if (mode === 'add') { - for (const item of result) { - if (!settings.role.autos.includes(item)) { - settings.role.autos.push(item); - } - } - } else if (mode === 'remove') { - if (settings.role.autos) { - settings.role.autos = settings.role.autos.filter(item => !result.includes(item)); - } - } - - fs.writeFileSync(settingsFilePath, JSON.stringify(settings, null, 2)); - - const embed = new MessageEmbed() - .setTitle("自動付与ロール") - .setDescription(`✅ ロールを更新しました`) - .setColor(config.color); - - await message.channel.send({embeds: [embed]}); - } catch (e) { - console.error(e); - err_embed.setDescription(`❌ エラーが発生しました`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - } - }, -} \ No newline at end of file diff --git a/bot/commands/2-ignore.js b/bot/commands/2-ignore.js deleted file mode 100644 index fa97e9f..0000000 --- a/bot/commands/2-ignore.js +++ /dev/null @@ -1,137 +0,0 @@ -const { MessageEmbed } = require("discord.js"); -const fs = require("fs"); - -module.exports = { - name: 'ignore', - usage: 'ignore {mode} {type} (values...)', - aliases: ['i'], - description: '要素をホワイトリストに追加/削除します(mode: `add, remove, reset` type: `channels, roles, users`)', - async execute(client, message, args, config) { - const err_embed = new MessageEmbed() - .setTitle("ホワイトリスト"); - - if (!message.member.permissions.has("ADMINISTRATOR")) { - err_embed.setDescription(`❌ 管理者権限が必要です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - let prefix = config.prefix; - const guildId = message.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (fs.existsSync(settingsFilePath)) { - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings?.prefix) { - prefix = settings.prefix; - } - } - - if (!fs.existsSync(settingsFilePath)) { - err_embed.setDescription(`❌ 先に ${prefix}setup を実行してください`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - - if (args.length < 2) { - err_embed.setDescription(`❌ 値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - const mode = args[0].toLowerCase(); - const type = args[1].toLowerCase(); - if (mode === 'reset') { - if (type === 'users' || type === 'roles' || type === 'channels') { - settings[`ignore_${type}`] = []; - fs.writeFileSync(settingsFilePath, JSON.stringify(settings, null, 2)); - const embed = new MessageEmbed() - .setTitle("ホワイトリスト") - .setDescription(`✅ 設定をリセットしました`) - .setColor(config.color); - - await message.channel.send({embeds: [embed]}); - } - return; - } - - if (args.length < 3) { - err_embed.setDescription(`❌ 値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - if (mode !== 'add' && mode !== 'remove') { - err_embed.setDescription(`❌ {mode} の値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - const opts = args.slice(2); - console.log(opts); - const result = []; - - if (type === 'users') { - await message.guild.members.fetch(); - for (const opt of opts) { - const id = opt.replace(/<@|!|>/g,''); - const member = message.guild.members.cache.get(id); - if (member) { - result.push(id); - } - } - } else if (type === 'roles') { - await message.guild.roles.fetch(); - for (const opt of opts) { - const id = opt.replace(/<@&|>/g,''); - const role = message.guild.roles.cache.get(id); - if (role) { - result.push(id); - } - } - } else if (type === 'channels') { - await message.guild.channels.fetch(); - for (const opt of opts) { - const id = opt.replace(/<#|>/g,''); - const channel = message.guild.channels.cache.get(id); - if (channel) { - result.push(id); - } - } - } else { - err_embed.setDescription(`❌ {type} の値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - console.log(result); - - try { - if (mode === 'add') { - for (const item of result) { - if (!settings[`ignore_${type}`].includes(item)) { - settings[`ignore_${type}`].push(item); - } - } - } else if (mode === 'remove') { - if (settings[`ignore_${type}`]) { - settings[`ignore_${type}`] = settings[`ignore_${type}`].filter(item => !result.includes(item)); - } - } - - fs.writeFileSync(settingsFilePath, JSON.stringify(settings, null, 2)); - - const embed = new MessageEmbed() - .setTitle("ホワイトリスト") - .setDescription(`✅ 設定を更新しました`) - .setColor(config.color); - - await message.channel.send({embeds: [embed]}); - } catch (e) { - console.error(e); - err_embed.setDescription(`❌ エラーが発生しました`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - } - }, -}; \ No newline at end of file diff --git a/bot/commands/2-modrole.js b/bot/commands/2-modrole.js deleted file mode 100644 index 896c51e..0000000 --- a/bot/commands/2-modrole.js +++ /dev/null @@ -1,104 +0,0 @@ -const { MessageEmbed } = require("discord.js"); -const fs = require("fs"); - -module.exports = { - name: 'moderator', - usage: 'pc!moderator {mode} (roles...)', - aliases: ['mod'], - description: 'モデレーターロールを追加/削除します(mode: `add, remove, reset`)', - async execute(client, message, args, config) { - const err_embed = new MessageEmbed() - .setTitle("モデレーターロール"); - - if (!message.member.permissions.has("ADMINISTRATOR")) { - err_embed.setDescription(`❌ 管理者権限が必要です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - let prefix = config.prefix; - const guildId = message.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (fs.existsSync(settingsFilePath)) { - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings?.prefix) { - prefix = settings.prefix; - } - } - - if (!fs.existsSync(settingsFilePath)) { - err_embed.setDescription(`❌ 先に ${prefix}setup を実行してください`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - - if (args.length < 1) { - err_embed.setDescription(`❌ 値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - const mode = args[0].toLowerCase(); - if (mode === 'reset') { - settings.mods = []; - fs.writeFileSync(settingsFilePath, JSON.stringify(settings, null, 2)); - const embed = new MessageEmbed() - .setTitle("モデレーターロール") - .setDescription(`✅ ロールをリセットしました`) - .setColor(config.color); - - await message.channel.send({embeds: [embed]}); - return; - } - - if (args.length < 2) { - err_embed.setDescription(`❌ 値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - if (mode !== 'add' && mode !== 'remove') { - err_embed.setDescription(`❌ {mode} の値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - const roles = args.slice(1); - const result = []; - for (const role of roles) { - const roleId = role.replace(/<@&|>/g,''); - if (message.guild.roles.cache.get(roleId)) { - result.push(roleId); - } - } - console.log(result); - - try { - if (mode === 'add') { - for (const item of result) { - if (!settings.mods?.includes(item)) { - settings.mods.push(item); - } - } - } else if (mode === 'remove') { - if (settings.mods) { - settings.mods = settings.role.autos.filter(item => !result.includes(item)); - } - } - - fs.writeFileSync(settingsFilePath, JSON.stringify(settings, null, 2)); - - const embed = new MessageEmbed() - .setTitle("モデレーターロール") - .setDescription(`✅ ロールを更新しました`) - .setColor(config.color); - - await message.channel.send({embeds: [embed]}); - } catch (e) { - console.error(e); - err_embed.setDescription(`❌ エラーが発生しました`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - } - }, -} \ No newline at end of file diff --git a/bot/commands/2-ngwords.js b/bot/commands/2-ngwords.js deleted file mode 100644 index 635bbce..0000000 --- a/bot/commands/2-ngwords.js +++ /dev/null @@ -1,98 +0,0 @@ -const { MessageEmbed } = require("discord.js"); -const fs = require("fs"); - -module.exports = { - name: 'ngwords', - usage: 'ngwords {mode} (words...)', - aliases: ['ng'], - description: 'NGワードを追加/削除します(mode: `add, remove, reset`)', - async execute(client, message, args, config) { - const err_embed = new MessageEmbed() - .setTitle("NGワード"); - - if (!message.member.permissions.has("ADMINISTRATOR")) { - err_embed.setDescription(`❌ 管理者権限が必要です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - let prefix = config.prefix; - const guildId = message.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (fs.existsSync(settingsFilePath)) { - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings?.prefix) { - prefix = settings.prefix; - } - } - - if (!fs.existsSync(settingsFilePath)) { - err_embed.setDescription(`❌ 先に ${prefix}setup を実行してください`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - - if (args.length < 1) { - err_embed.setDescription(`❌ 値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - const mode = args[0].toLowerCase(); - if (mode === 'reset') { - settings.ngwords = []; - fs.writeFileSync(settingsFilePath, JSON.stringify(settings, null, 2)); - const embed = new MessageEmbed() - .setTitle("NGワード") - .setDescription(`✅ ワード一覧をリセットしました`) - .setColor(config.color); - - await message.channel.send({embeds: [embed]}); - return; - } - - if (args.length < 2) { - err_embed.setDescription(`❌ 値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - if (mode !== 'add' && mode !== 'remove') { - err_embed.setDescription(`❌ {mode} の値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - const result = args.slice(1); - console.log(result); - - try { - if (mode === 'add') { - for (const item of result) { - if (!settings.ngwords.includes(item)) { - settings.ngwords.push(item); - } - } - } else if (mode === 'remove') { - if (settings.ngwords) { - settings.ngwords = settings.ngwords.filter(item => !result.includes(item)); - } - } - - fs.writeFileSync(settingsFilePath, JSON.stringify(settings, null, 2)); - - const embed = new MessageEmbed() - .setTitle("NGワード") - .setDescription(`✅ ワード一覧を更新しました`) - .setColor(config.color); - - await message.channel.send({embeds: [embed]}); - } catch (e) { - console.error(e); - err_embed.setDescription(`❌ エラーが発生しました`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - } - }, -} \ No newline at end of file diff --git a/bot/commands/2-setting.js b/bot/commands/2-setting.js deleted file mode 100644 index 31c417e..0000000 --- a/bot/commands/2-setting.js +++ /dev/null @@ -1,70 +0,0 @@ -const { MessageEmbed } = require("discord.js"); -const fs = require("fs"); - -module.exports = { - name: 'setting', - usage: 'setting {mode} {type}', - aliases: ['set'], - description: '設定を変更します(mode: `true, false` type: `antispam, antiinvite, antilink, antingwords`)', - async execute(client, message, args, config) { - const err_embed = new MessageEmbed() - .setTitle("設定"); - - if (!message.member.permissions.has("ADMINISTRATOR")) { - err_embed.setDescription(`❌ 管理者権限が必要です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - let prefix = config.prefix; - const guildId = message.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (fs.existsSync(settingsFilePath)) { - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings?.prefix) { - prefix = settings.prefix; - } - } - - if (!fs.existsSync(settingsFilePath)) { - err_embed.setDescription(`❌ 先に ${prefix}setup を実行してください`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - if (args.length < 2) { - err_embed.setDescription(`❌ 値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - let mode = args[0].toLowerCase(); - if (mode !== 'true' && mode !== 'false') { - err_embed.setDescription(`❌ {mode} の値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - mode = mode === 'true' ? true : false; - const type = args[1].toLowerCase(); - if (type !== 'antispam' && type !== 'antiinvite' && type !== 'antilink' && type !== 'antingwords' && type !== 'timeout') { - err_embed.setDescription(`❌ {type} の値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - try { - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - settings.setting[type] = mode; - fs.writeFileSync(settingsFilePath, JSON.stringify(settings, null, 2)); - - const embed = new MessageEmbed() - .setTitle("設定") - .setDescription(`✅ 設定を更新しました`) - .setColor(config.color); - - await message.channel.send({embeds: [embed]}); - } catch (e) { - console.error(e); - err_embed.setDescription(`❌ エラーが発生しました`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - } - }, -} \ No newline at end of file diff --git a/bot/commands/2-settingnuke.js b/bot/commands/2-settingnuke.js deleted file mode 100644 index efe234a..0000000 --- a/bot/commands/2-settingnuke.js +++ /dev/null @@ -1,114 +0,0 @@ -const { MessageEmbed } = require("discord.js"); -const fs = require("fs"); - -module.exports = { - name: 'settingnuke', - usage: 'settingnuke {mode} (channels...)', - aliases: ['sn'], - description: '再生成チャンネルを追加/削除します(mode: `add, remove, reset`)', - async execute(client, message, args, config) { - const err_embed = new MessageEmbed() - .setTitle("再生成チャンネル"); - - if (!message.member.permissions.has("ADMINISTRATOR")) { - err_embed.setDescription(`❌ 管理者権限が必要です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - let prefix = config.prefix; - const guildId = message.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (fs.existsSync(settingsFilePath)) { - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings?.prefix) { - prefix = settings.prefix; - } - } - - if (!fs.existsSync(settingsFilePath)) { - err_embed.setDescription(`❌ 先に ${prefix}setup を実行してください`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - - if (args.length < 1) { - err_embed.setDescription(`❌ 値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - const mode = args[0].toLowerCase(); - if (mode === 'reset') { - settings.channel.nuke = []; - fs.writeFileSync(settingsFilePath, JSON.stringify(settings, null, 2)); - const embed = new MessageEmbed() - .setTitle("再生成チャンネル") - .setDescription(`✅ 設定をリセットしました`) - .setColor(config.color); - - await message.channel.send({ embeds: [embed] }); - return; - } - - if (args.length < 2) { - err_embed.setDescription(`❌ 値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - if (mode !== 'add' && mode !== 'remove') { - err_embed.setDescription(`❌ {mode} の値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - const opts = args.slice(1); - console.log(opts); - const result = []; - - await message.guild.channels.fetch(); - for (const opt of opts) { - const id = opt.replace(/<#|>/g,''); - const channel = message.guild.channels.cache.get(id); - if (channel && isTextOrVoiceChannel(channel)) { - result.push(id); - } - } - - function isTextOrVoiceChannel(channel) { - return channel.type === 'GUILD_TEXT' || channel.type === 'GUILD_VOICE'; - } - - console.log(result); - - try { - if (mode === 'add') { - for (const item of result) { - if (!settings.channel?.nuke.includes(item)) { - settings.channel.nuke.push(item); - } - } - } else if (mode === 'remove') { - if (settings.channel?.nuke) { - settings.channel.nuke = settings.channel?.nuke.filter(item => !result.includes(item)); - } - } - - fs.writeFileSync(settingsFilePath, JSON.stringify(settings, null, 2)); - - const embed = new MessageEmbed() - .setTitle("再生成チャンネル") - .setDescription(`✅ 設定を更新しました`) - .setColor(config.color); - - await message.channel.send({embeds: [embed]}); - } catch (e) { - console.error(e); - err_embed.setDescription(`❌ エラーが発生しました`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - } - }, -}; \ No newline at end of file diff --git a/bot/commands/2-settingtimeout.js b/bot/commands/2-settingtimeout.js deleted file mode 100644 index 07648f1..0000000 --- a/bot/commands/2-settingtimeout.js +++ /dev/null @@ -1,70 +0,0 @@ -const { MessageEmbed } = require("discord.js"); -const fs = require("fs"); - -module.exports = { - name: 'settingtimeout', - usage: 'settingtimeout {mode} {type}', - aliases: ['st'], - description: 'タイムアウト設定を変更します(mode: `true, false` type: `antispam, antiinvite, antilink, antingwords`)', - async execute(client, message, args, config) { - const err_embed = new MessageEmbed() - .setTitle("タイムアウト設定"); - - if (!message.member.permissions.has("ADMINISTRATOR")) { - err_embed.setDescription(`❌ 管理者権限が必要です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - let prefix = config.prefix; - const guildId = message.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (fs.existsSync(settingsFilePath)) { - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings?.prefix) { - prefix = settings.prefix; - } - } - - if (!fs.existsSync(settingsFilePath)) { - err_embed.setDescription(`❌ 先に ${prefix}setup を実行してください`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - if (args.length < 2) { - err_embed.setDescription(`❌ 値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - let mode = args[0].toLowerCase(); - if (mode !== 'true' && mode !== 'false') { - err_embed.setDescription(`❌ {mode} の値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - mode = mode === 'true' ? true : false; - const type = args[1].toLowerCase(); - if (type !== 'antispam' && type !== 'antiinvite' && type !== 'antilink' && type !== 'antingwords' && type !== 'timeout') { - err_embed.setDescription(`❌ {type} の値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - try { - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - settings.setting.timeout[type] = mode; - fs.writeFileSync(settingsFilePath, JSON.stringify(settings, null, 2)); - - const embed = new MessageEmbed() - .setTitle("タイムアウト設定") - .setDescription(`✅ 設定を更新しました`) - .setColor(config.color); - - await message.channel.send({embeds: [embed]}); - } catch (e) { - console.error(e); - err_embed.setDescription(`❌ エラーが発生しました`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - } - }, -} \ No newline at end of file diff --git a/bot/commands/2-ticketcategory.js b/bot/commands/2-ticketcategory.js deleted file mode 100644 index 65aa7a7..0000000 --- a/bot/commands/2-ticketcategory.js +++ /dev/null @@ -1,64 +0,0 @@ -const { MessageEmbed } = require("discord.js"); -const fs = require("fs"); - -module.exports = { - name: 'ticketcategory', - usage: 'ticketcategory {category}', - aliases: ['tc'], - description: 'チケットの作成先のカテゴリーを変更します', - async execute(client, message, args, config) { - const err_embed = new MessageEmbed() - .setTitle("チケットカテゴリー") - if (!message.member.permissions.has("ADMINISTRATOR")) { - err_embed.setDescription(`❌ 管理者権限が必要です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - let prefix = config.prefix; - const guildId = message.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (fs.existsSync(settingsFilePath)) { - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings?.prefix) { - prefix = settings.prefix; - } - } - - if (!fs.existsSync(settingsFilePath)) { - err_embed.setDescription(`❌ 先に ${prefix}setup を実行してください`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - - if (args.length < 1) { - err_embed.setDescription(`❌ 値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - let categoryId = args[0].replace(/<#|>/g,''); - const category = message.guild.channels.cache.get(categoryId); - if (categoryId !== 'reset' && (!category || category?.type !== 'GUILD_CATEGORY')) { - err_embed.setDescription(`❌ {category} が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - categoryId = categoryId.toLowerCase() === 'reset' ? null : categoryId; - settings.setting.ticket_number.category = categoryId; - fs.writeFileSync(settingsFilePath, JSON.stringify(settings, null, 2)); - try { - const embed = new MessageEmbed() - .setTitle("チケットカテゴリー") - .setDescription(`✅ チケットカテゴリーを${categoryId === null?'リセット':` <#${categoryId}> に変更`}しました`) - .setFooter({text: `リセットする場合は ${prefix}ticketcategory reset と送信してください`}) - .setColor(config.color); - await message.channel.send({ embeds: [embed] }) - } catch (e) { - err_embed.setDescription(`❌ エラーが発生しました`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - console.error(e); - } - }, -}; \ No newline at end of file diff --git a/bot/commands/2-timeoutperiod.js b/bot/commands/2-timeoutperiod.js deleted file mode 100644 index 6ca5294..0000000 --- a/bot/commands/2-timeoutperiod.js +++ /dev/null @@ -1,137 +0,0 @@ -const { MessageEmbed } = require("discord.js"); -const fs = require("fs"); - -module.exports = { - name: 'timeoutperiod', - usage: 'timeoutperiod {time} {type}', - aliases: ['tp'], - description: 'タイムアウト設定を変更します(type: `days, hours, minutes, seconds`)', - async execute(client, message, args, config) { - const err_embed = new MessageEmbed() - .setTitle("タイムアウト期間設定"); - - function isNonNegativeInteger(number) { - if (isNaN(number)) { - return false; - } - if (typeof number !== 'number') { - return false; - } - if (number >= 0 && Number.isInteger(number)) { - return true; - } else { - return false; - } - } - - if (!message.member.permissions.has("ADMINISTRATOR")) { - err_embed.setDescription(`❌ 管理者権限が必要です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - let prefix = config.prefix; - const guildId = message.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (fs.existsSync(settingsFilePath)) { - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings?.prefix) { - prefix = settings.prefix; - } - } - - if (!fs.existsSync(settingsFilePath)) { - err_embed.setDescription(`❌ 先に ${prefix}setup を実行してください`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - if (args.length < 2) { - err_embed.setDescription(`❌ 値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - const time = parseFloat(args[0]); - if (!isNonNegativeInteger(time)) { - err_embed.setDescription(`❌ {time} の値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - const type = args[1].toLowerCase(); - if (type !== 'days' && type !== 'hours' && type !== 'minutes' && type !== 'seconds') { - err_embed.setDescription(`❌ {type} の値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - try { - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (type === 'days') { - if (time > 28) { - err_embed.setDescription(`❌ {time} の値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - } - if (type === 'hours') { - if (time > 23) { - err_embed.setDescription(`❌ {time} の値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - } - if (type === 'minutes') { - if (time > 59) { - err_embed.setDescription(`❌ {time} の値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - } - if (type === 'seconds') { - if (time > 59) { - err_embed.setDescription(`❌ {time} の値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - } - settings.setting.timeout[type] = time; - - if ( - ( - settings.setting.timeout.days + - settings.setting.timeout.hours + - settings.setting.timeout.minutes + - settings.setting.timeout.seconds - ) > 28 - ) { - settings.setting.timeout.days = 28; - settings.setting.timeout.hours = 0; - settings.setting.timeout.minutes = 0; - settings.setting.timeout.seconds = 0; - } - if ( - ( - settings.setting.timeout.days + - settings.setting.timeout.hours + - settings.setting.timeout.minutes + - settings.setting.timeout.seconds - ) == 0 - ) { - settings.setting.timeout.minutes = 2; - } - - fs.writeFileSync(settingsFilePath, JSON.stringify(settings, null, 2)); - - const embed = new MessageEmbed() - .setTitle("タイムアウト期間設定") - .setDescription(`✅ 設定を更新しました`) - .setColor(config.color); - - await message.channel.send({embeds: [embed]}); - } catch (e) { - console.error(e); - err_embed.setDescription(`❌ エラーが発生しました`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - } - }, -} \ No newline at end of file diff --git a/bot/commands/3-mute.js b/bot/commands/3-mute.js deleted file mode 100644 index 16ce59f..0000000 --- a/bot/commands/3-mute.js +++ /dev/null @@ -1,160 +0,0 @@ -const { MessageEmbed } = require("discord.js"); -const fs = require("fs"); - -module.exports = { - name: 'mute', - usage: 'mute {mode} (users...)', - aliases: ['m'], - description: 'ミュートユーザーを追加/削除します(mode: `add, remove, reset`)', - async execute(client, message, args, config) { - const err_embed = new MessageEmbed() - .setTitle("ミュート"); - - try { - if (!message.member.permissions.has("ADMINISTRATOR")) { - err_embed.setDescription(`❌ 管理者権限が必要です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - let prefix = config.prefix; - const guildId = message.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (fs.existsSync(settingsFilePath)) { - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings?.prefix) { - prefix = settings.prefix; - } - } - - if (!fs.existsSync(settingsFilePath)) { - err_embed.setDescription(`❌ 先に ${prefix}setup を実行してください`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - - if (args.length < 1) { - err_embed.setDescription(`❌ 値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - const mode = args[0].toLowerCase(); - if (mode === 'reset') { - const muted_users = settings?.muted_users; - if (muted_users.length > 0) { - const role = await message.guild.roles.cache.get(settings.role?.muted); - if (role) { - for (const user of muted_users) { - const member = await message.guild.members.cache.get(user); - if (member) { - member.roles.remove(settings.role.muted, 'Reset muted user') - } - } - } - } - settings.muted_users = []; - fs.writeFileSync(settingsFilePath, JSON.stringify(settings, null, 2)); - const embed = new MessageEmbed() - .setTitle("ミュート") - .setDescription(`✅ ミュートユーザーをリセットしました`) - .setColor(config.color); - - await message.channel.send({embeds: [embed]}); - return; - } - - const role = await message.guild.roles.cache.get(settings.role?.muted); - - if (!role) { - err_embed.setDescription(`❌ **Muted User** ロールが存在しません`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - if (args.length < 2) { - err_embed.setDescription(`❌ 値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - if (mode !== 'add' && mode !== 'remove') { - err_embed.setDescription(`❌ {mode} の値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - const usersBase = args.slice(1); - const userIds = []; - for (const user of usersBase) { - const userId = user.replace(/<@|!|>/g,'') - const member = message.guild.members.cache.get(userId); - if (member) { - userIds.push(userId); - } - } - console.log(userIds); - - if (mode === 'add') { - for (const userId of userIds) { - const member = await message.guild.members.cache.get(userId); - if (!member) continue; - const roleIds = await member.roles.cache.map(role => role.id); - console.log(roleIds) - for (const roleId of roleIds) { - try { - if (message.guild.roles.cache.get(roleId)) { - await member.roles.remove(roleId, 'Add muted user'); - } - } catch (e) { - console.log('Failed to remove.') - } - - try { - await member.roles.add(settings.role.muted, 'Add muted user'); - } catch (e) { - console.log('Failed to add.') - } - } - } - } else if (mode === 'remove') { - for (const userId of userIds) { - const member = await message.guild.members.cache.get(userId); - if (member) { - try { - await member.roles.remove(settings.role.muted, 'Remove muted user'); - } catch (e) { - console.log('Failed to remove.') - } - } - } - } - - const embed = new MessageEmbed() - .setTitle("ミュート") - .setDescription(`✅ ミュートユーザーを更新しました`) - .setColor(config.color); - const mentions = []; - for (const userId of userIds) { - const member = await message.guild.members.cache.get(userId); - if (!member) continue; - mentions.push(`<@${userId}>`) - } - if (mentions.length > 0) { - embed.addFields([ - { - name: mode, - value: mentions.join(' , ') - } - ]) - } - await message.channel.send({ embeds: [embed] }); - } catch (e) { - console.error(e); - err_embed.setDescription(`❌ エラーが発生しました`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - } - }, -} diff --git a/bot/commands/3-rolepanel.js b/bot/commands/3-rolepanel.js deleted file mode 100644 index ff8360c..0000000 --- a/bot/commands/3-rolepanel.js +++ /dev/null @@ -1,372 +0,0 @@ -const { MessageEmbed, MessageActionRow, MessageSelectMenu } = require("discord.js"); -const fs = require("fs"); - -module.exports = { - name: 'rolepanel', - usage: 'rolepanel {mode} (values...)', - aliases: ['rp'], - description: 'ロールパネルを操作します (mode: `help, create, add, remove, copy, change, refresh`)', - async execute(client, message, args, config) { - const err_embed = new MessageEmbed() - .setTitle('ロールパネル'); - const embed = new MessageEmbed() - .setColor(config.color) - if (!message.member.permissions.has("ADMINISTRATOR")) { - err_embed.setDescription(`❌ 管理者権限が必要です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - let prefix = config.prefix; - const guildId = message.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (fs.existsSync(settingsFilePath)) { - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings?.prefix) { - prefix = settings.prefix; - } - } - if (args.length < 1) { - err_embed.setDescription(`❌ 値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - try { - const mode = args[0].toLowerCase(); - const replied = message?.reference; - - // help - if (mode === 'help') { - const helpContents = [ - { - usage: 'help', - description: 'ロールパネルのヘルプを表示します' - }, - { - usage: 'create {type} {roles...}', - description: 'ロールパネルを作成します (type: `normal, single`)' - }, - { - usage: 'add {roles...}', - description: 'ロールパネルにロールを追加します {+reply}' - }, - { - usage: 'remove {roles...}', - description: 'ロールパネルからロールを削除します {+reply}' - }, - { - usage: 'copy', - description: 'ロールパネルをコピーします {+reply}' - }, - { - usage: 'change', - description: 'ロールパネルのタイプを変更します {+reply}' - }, - { - usage: 'refresh', - description: 'ロールパネルを整理します {+reply}' - } - ]; - const helpDescription = helpContents.map(content => `**${prefix}rolepanel ${content.usage}** ${content.description ?? '説明がありません'}`).join('\n') - embed.setTitle('ロールパネルヘルプ'); - embed.setDescription(helpDescription); - embed.setFooter({ text: `prefix => ${prefix} | {} => required, () => optional` }); - await message.channel.send({ embeds: [embed] }); - return; - }; - - if (!fs.existsSync(settingsFilePath)) { - err_embed.setDescription(`❌ 先に ${prefix}setup を実行してください`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - }; - - // create - if (mode === 'create') { - if (args.length < 3) { - err_embed.setDescription(`❌ 値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - const type = args[1].toLowerCase(); - if (type !== 'normal' && type !== 'single') { - err_embed.setDescription(`❌ {type} の値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - const data = args.slice(2); - if (data.length > 20) { - err_embed.setDescription(`❌ 値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - const roles = []; - for (const role of data) { - const roleId = role.replace(/<@&|>/g,''); - const isExist = await message.guild.roles.cache.get(roleId); - if (isExist) roles.push(roleId); - } - const panelDescription = roles.map(role => `<@&${role}>`).join('\n'); - const options = []; - for (const role of roles) { - const roleName = await message.guild.roles.cache.get(role).name; - options.push( - { - label: roleName, - value: role - } - ) - } - const customId = type === 'single' ? 'single-rp' : 'rp'; - const row = new MessageSelectMenu().setCustomId(customId).setPlaceholder('ロールを選択してください').addOptions(options).setMinValues(1).setMaxValues(1); - const menu = new MessageActionRow() - .addComponents(row); - embed.setTitle(type === 'single' ? 'ロールパネル (複数選択不可)' : 'ロールパネル'); - embed.setDescription(panelDescription); - embed.setFooter(customId); - await message.channel.send({ embeds: [embed], components: [menu] }); - await message.delete(); - await message.channel.send('✅ 成功しました') - .then(msg => { - setTimeout(async () => { - await msg.delete(); - }, 3000) - }); - return; - } - - if (!replied) { - err_embed.setDescription(`❌ ロールパネルを選択してください`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - const repliedMessage = await message.channel.messages.fetch(replied.messageId); - - if (repliedMessage.author.id !== client.user.id || !repliedMessage.embeds[0]?.title?.includes('ロールパネル') || repliedMessage.embeds[0]?.color == 15548997) { - err_embed.setDescription(`❌ ロールパネルを選択してください`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - if (repliedMessage.embeds[0]?.title === 'ロールパネルヘルプ') { - err_embed.setDescription(`❌ ロールパネルを選択してください`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - // add - else if (mode === 'add') { - const type = repliedMessage.embeds[0].footer.text; - const roles = args.slice(1); - if (roles.length < 1) { - err_embed.setDescription(`❌ 値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - const oldPanel = repliedMessage.embeds[0].description; - const roleIds = oldPanel.replace(/<@&|>/g,'').split('\n'); - const oldRoleIdsLength = roleIds.length; - for (const role of roles) { - const roleId = role.replace(/<@&|>/g,''); - const isExist = await message.guild.roles.cache.get(roleId) && !roleIds.includes(roleId); - if (isExist) roleIds.push(roleId); - } - if (oldRoleIdsLength == roleIds.length || roleIds.length > 20) { - err_embed.setDescription(`❌ 値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - const panelDescription = roleIds.map(role => `<@&${role}>`).join('\n'); - const options = []; - for (const role of roleIds) { - const roleName = await message.guild.roles.cache.get(role).name; - options.push( - { - label: roleName, - value: role - } - ) - } - const customId = type === 'single-rp' ? 'single-rp' : 'rp'; - const row = new MessageSelectMenu().setCustomId(customId).setPlaceholder('ロールを選択してください').addOptions(options).setMinValues(1).setMaxValues(1); - const menu = new MessageActionRow() - .addComponents(row); - embed.setTitle(type === 'single-rp' ? 'ロールパネル (複数選択不可)' : 'ロールパネル') - embed.setDescription(panelDescription); - embed.setFooter(customId); - await repliedMessage.edit({ embeds: [embed], components: [menu] }); - await message.delete(); - await message.channel.send('✅ 成功しました') - .then(msg => { - setTimeout(async () => { - await msg.delete(); - }, 3000) - }); - return; - } - - // remove - else if (mode === 'remove') { - const type = repliedMessage.embeds[0].footer.text; - const roles = args.slice(1); - const oldPanel = repliedMessage.embeds[0].description; - const oldRoleIds = oldPanel.replace(/<@&|>/g,'').split('\n'); - const removeRoles = []; - for (const role of roles) { - const roleId = role.replace(/<@&|>/g,''); - const isExist = oldRoleIds.includes(roleId); - if (isExist) removeRoles.push(roleId); - } - const roleIds = oldRoleIds.filter(roleId => !removeRoles.includes(roleId)); - const panelDescription = roleIds.map(role => `<@&${role}>`).join('\n'); - const options = []; - for (const role of roleIds) { - const roleName = await message.guild.roles.cache.get(role).name; - options.push( - { - label: roleName, - value: role - } - ) - } - if (options.length == 0) { - await repliedMessage.delete(); - await message.channel.send('✅ 成功しました') - .then(msg => { - setTimeout(async () => { - await msg.delete(); - }, 3000) - }); - return; - } - const customId = type === 'single-rp' ? 'single-rp' : 'rp'; - const row = new MessageSelectMenu().setCustomId(customId).setPlaceholder('ロールを選択してください').addOptions(options).setMinValues(1).setMaxValues(1); - const menu = new MessageActionRow() - .addComponents(row); - embed.setTitle(type === 'single-rp' ? 'ロールパネル (複数選択不可)' : 'ロールパネル') - embed.setDescription(panelDescription); - embed.setFooter(customId); - await repliedMessage.edit({ embeds: [embed], components: [menu] }); - await message.delete(); - await message.channel.send('✅ 成功しました') - .then(msg => { - setTimeout(async () => { - await msg.delete(); - }, 3000) - }); - return; - } - - // copy - else if (mode === 'copy') { - const embed = repliedMessage.embeds[0]; - const menu = repliedMessage.components[0]; - await message.channel.send({ embeds: [embed], components: [menu] }); - await message.delete(); - await message.channel.send('✅ 成功しました') - .then(msg => { - setTimeout(async () => { - await msg.delete(); - }, 3000) - }) - return; - } - - // change - else if (mode === 'change') { - const panelEmbed = repliedMessage.embeds[0]; - const type = panelEmbed.footer.text; - const customId = type !== 'single-rp' ? 'single-rp' : 'rp'; - panelEmbed.setTitle(type !== 'single-rp' ? 'ロールパネル (複数選択不可)' : 'ロールパネル') - panelEmbed.setFooter(customId); - const oldPanel = repliedMessage.embeds[0].description; - const roleIds = oldPanel.replace(/<@&|>/g,'').split('\n'); - const options = []; - for (const role of roleIds) { - const roleName = await message.guild.roles.cache.get(role).name; - options.push( - { - label: roleName, - value: role - } - ) - } - const row = new MessageSelectMenu().setCustomId(customId).setPlaceholder('ロールを選択してください').addOptions(options).setMinValues(1).setMaxValues(1); - const menu = new MessageActionRow() - .addComponents(row); - await repliedMessage.edit({ embeds: [panelEmbed], components: [menu] }); - await message.delete(); - await message.channel.send('✅ 成功しました') - .then(msg => { - setTimeout(async () => { - await msg.delete(); - }, 3000) - }); - return; - } - - // refresh - else if (mode === 'refresh') { - const type = repliedMessage.embeds[0].footer.text; - const oldPanel = repliedMessage.embeds[0].description; - const oldRoleIds = oldPanel.replace(/<@&|>/g,'').split('\n'); - const removeRoles = []; - for (const roleId of oldRoleIds) { - const isExist = message.guild.roles.cache.get(roleId); - if (!isExist) removeRoles.push(roleId); - } - const roleIds = oldRoleIds.filter(roleId => !removeRoles.includes(roleId)); - const panelDescription = roleIds.map(role => `<@&${role}>`).join('\n'); - const options = []; - for (const role of roleIds) { - const roleName = await message.guild.roles.cache.get(role).name; - options.push( - { - label: roleName, - value: role - } - ) - } - if (options.length == 0) { - await repliedMessage.delete(); - await message.channel.send('✅ 成功しました') - .then(msg => { - setTimeout(async () => { - await msg.delete(); - }, 3000) - }); - return; - } - const customId = type === 'single-rp' ? 'single-rp' : 'rp'; - const row = new MessageSelectMenu().setCustomId(customId).setPlaceholder('ロールを選択してください').addOptions(options).setMinValues(1).setMaxValues(1); - const menu = new MessageActionRow() - .addComponents(row); - embed.setTitle(type === 'single-rp' ? 'ロールパネル (複数選択不可)' : 'ロールパネル') - embed.setDescription(panelDescription); - embed.setFooter(customId); - await repliedMessage.edit({ embeds: [embed], components: [menu] }); - await message.delete(); - await message.channel.send('✅ 成功しました') - .then(msg => { - setTimeout(async () => { - await msg.delete(); - }, 3000) - }); - return; - } - - // other - else { - err_embed.setDescription(`❌ {mode} の値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - }; - } catch (e) { - console.error(e); - err_embed.setDescription('❌ エラーが発生しました').setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - } - }, -} \ No newline at end of file diff --git a/bot/commands/3-ticket.js b/bot/commands/3-ticket.js deleted file mode 100644 index 3c5f678..0000000 --- a/bot/commands/3-ticket.js +++ /dev/null @@ -1,60 +0,0 @@ -const { MessageEmbed, MessageActionRow, MessageButton } = require("discord.js"); -const fs = require("fs"); - -module.exports = { - name: 'ticket', - usage: 'ticket (description)', - aliases: ['t'], - description: '認証パネルを設置します', - async execute(client, message, args, config) { - const err_embed = new MessageEmbed() - .setTitle("認証"); - if (!message.member.permissions.has("ADMINISTRATOR")) { - err_embed.setDescription(`❌ 管理者権限が必要です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - let prefix = config.prefix; - const guildId = message.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (fs.existsSync(settingsFilePath)) { - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings?.prefix) { - prefix = settings.prefix; - } - } - - if (!fs.existsSync(settingsFilePath)) { - err_embed.setDescription(`❌ 先に ${prefix}setup を実行してください`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - const embed = new MessageEmbed() - .setTitle("チケット") - .setColor(config.color) - - let explanation = "下のボタンを押してチケットを作成できます" - if (args.length > 0) { - explanation = args.join(' ') - } - embed.setDescription(explanation); - const row = new MessageActionRow() - .addComponents( - new MessageButton() - .setCustomId(`ticket`) - .setEmoji('🎫') - .setLabel('チケット作成') - .setStyle('SUCCESS'), - ) - try { - await message.channel.send({ embeds: [embed], components: [row] }); - await message.delete() - } catch (e) { - console.error(e); - err_embed.setDescription(`❌ エラーが発生しました`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - } - }, -}; \ No newline at end of file diff --git a/bot/commands/3-verify.js b/bot/commands/3-verify.js deleted file mode 100644 index 7348c1e..0000000 --- a/bot/commands/3-verify.js +++ /dev/null @@ -1,78 +0,0 @@ -const { MessageEmbed, MessageActionRow, MessageButton } = require("discord.js"); -const fs = require("fs"); - -module.exports = { - name: 'verify', - usage: 'verify {role} (description)', - aliases: ['v'], - description: '認証パネルを設置します', - async execute(client, message, args, config) { - const err_embed = new MessageEmbed() - .setTitle("認証"); - if (!message.member.permissions.has("ADMINISTRATOR")) { - err_embed.setDescription(`❌ 管理者権限が必要です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - let prefix = config.prefix; - const guildId = message.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (fs.existsSync(settingsFilePath)) { - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings?.prefix) { - prefix = settings.prefix; - } - } - - if (!fs.existsSync(settingsFilePath)) { - err_embed.setDescription(`❌ 先に ${prefix}setup を実行してください`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - if (args.length < 1) { - err_embed.setDescription(`❌ 値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - const roleId = args[0].replace(/<@&|>/g,''); - const role = message.guild.roles.cache.get(roleId); - if (!role) { - err_embed.setDescription(`❌ {role} の値が不正です`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - return; - } - - const embed = new MessageEmbed() - .setTitle("認証") - .setColor(config.color) - .addFields([ - { - name: '付与されるロール', - value: `${role}` - } - ]) - .setFooter({text: 'DMに送信される画像内の文字列を送信してください\n※大文字か小文字かは問いません\n30 秒以内に答えを送信してください'}) - if (args.length > 1) { - const explanation = args.slice(1)?.join(' ') - embed.setDescription(explanation); - } - const row = new MessageActionRow() - .addComponents( - new MessageButton() - .setCustomId(`verify-${roleId}`) - .setEmoji('✅') - .setLabel('認証') - .setStyle('SUCCESS'), - ) - try { - await message.channel.send({ embeds: [embed], components: [row] }); - await message.delete() - } catch (e) { - console.error(e); - err_embed.setDescription(`❌ エラーが発生しました`).setColor('RED'); - await message.channel.send({ embeds: [err_embed] }); - } - }, -}; \ No newline at end of file diff --git a/bot/config.json b/bot/config.json deleted file mode 100644 index 6662d40..0000000 --- a/bot/config.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "prefix": "pc!", - "color": "#a260bf", - "bot_owner": "957885295251034112", - "support": "https://discord.gg/yKW8wWKCnS", - "docs": "https://otoneko1102.github.io/ProteCat/", - "log_channel": "1155428802730659901" -} \ No newline at end of file diff --git a/bot/functions/automod.js b/bot/functions/automod.js deleted file mode 100644 index 1ba1455..0000000 --- a/bot/functions/automod.js +++ /dev/null @@ -1,936 +0,0 @@ -const { Client, MessageEmbed } = require("discord.js"); -const fs = require("fs"); -const options = { intents: [3276799] }; -const client = new Client(options); - -const { inviteTracker } = require("discord-inviter"), tracker = new inviteTracker(client); - -const config = JSON.parse(fs.readFileSync("./config.json", 'utf8')); -let prefix = config.prefix; - -const spamUsers = new Map(); - -client.on("messageCreate", async message => { - if (message.author.bot) return; - if (message.content === `<@${client.user.id}>` || message.content === `<@!${client.user.id}>`) { - let px = config.prefix; - const guildId = message.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (fs.existsSync(settingsFilePath)) { - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings?.prefix) { - px = settings.prefix; - } - } - try { - await message.reply(`プレフィックスは ${px} です`); - } catch (e) { - console.error(e); - } - } -}) - -client.on("ready", async () => { - console.log(`automod.js OK!`); - setInterval(async () => { - client.user.setPresence({ - activities: [ - { - name: `${prefix}help | ${client.guilds.cache.size} servers to Protect`, - type: 'WATCHING' - } - ], - status: 'online', - }) - - const timeZoneOffset = 9; // 日本時間はUTC+9 - const time = new Date(new Date().getTime() + timeZoneOffset * 60 * 60 * 1000); - const hour = 2; - if (time.getHours() % hour == 0 && time.getMinutes() % 60 == 0) { - client.guilds.cache.forEach(async (guild) => { - const guildId = guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (!fs.existsSync(settingsFilePath)) return; - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - settings.guild_name = guild.name; - fs.writeFileSync(settingsFilePath, JSON.stringify(settings, null, 2)); - if (settings.setting.disable === true) return; - const channelIds = settings.channel?.nuke || []; - const newChannels = []; - - if (channelIds.length > 0) { - let ignore_channels = settings?.ignore_channels; - for (const channelId of channelIds) { - const channel = guild.channels.cache.get(channelId); - if (channel) { - try { - await channel.delete(); - await channel.clone().then(async (ch) => { - const embed = new MessageEmbed() - .setTitle("チャンネル再生成") - .setDescription(`**${channel.name}** を再生成しました`) - .setFooter(`次は ${(time.getHours() + hour) % 24}:00 です`) - .setTimestamp() - .setColor(config.color); - await ch.send({ embeds: [embed] }); - newChannels.push(ch.id); - if (ignore_channels?.includes(channel.id)) { - ignore_channels = ignore_channels.filter(item => item !== channel.id); - ignore_channels.push(ch.id); - settings.ignore_channels = ignore_channels; - } - }); - } catch (e) { - console.error("チャンネルの再生成失敗", e); - } - } - } - settings.channel.nuke = newChannels; - fs.writeFileSync(settingsFilePath, JSON.stringify(settings, null, 2)); - } - }); - console.log("チャンネル再生成完了") - } - }, 60000); -}); - -client.on("messageCreate", async message => { - if (message.author.bot || message.member?.permissions.has('ADMINISTRATOR')) return; - const guildId = message.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (!fs.existsSync(settingsFilePath)) return; - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings.setting?.disable === true) return; - const mods = settings?.mods; - if (hasRole(message, mods)) return; - const roleIds = message.member.roles.cache.map((role) => role.id); - function isIgnore(channelId, roleIds, userId, settings) { - if (settings.ignore_channels?.includes(channelId)) return true; - if (roleIds.some(roleId => settings.ignore_roles?.includes(roleId))) return true; - if (settings.ignore_users?.includes(userId)) return true; - return false; - } - if (isIgnore(message.channel.id, roleIds, message.author.id, settings)) return; - - const regex = /([A-Za-z\d]{24})\.([A-Za-z\d-_]{6})\.([A-Za-z\d-_]{27})|([A-Za-z\d-_]{59})\.([A-Za-z\d-_]{27})/g; - if (!message.content.match(regex)) return; - try { - await message.guild.members.fetch(); - const embed = new MessageEmbed() - .setTitle("トークンを検出しました") - .setThumbnail(message.author.displayAvatarURL()) - .setDescription(`実行者: ${message.member}\nName: **${message.author.tag.split('#')[1] === '0' ? message.author.username : message.author.tag}**\nID: ${message.author.id}`) - .setColor(config.color); - const ch = message.channel; - embed.addFields = ([ - { - name: "チャンネル", - value: `${ch} (**${ch.name}**, ID: ${ch.id})` - } - ]); - try{await message.delete()}catch{console.error('x: delete')} - const time = { - days: settings.setting?.timeout?.days, - hours: settings.setting?.timeout?.hours, - minutes: settings.setting?.timeout?.minutes, - seconds: settings.setting?.timeout?.seconds, - } - const timeout = (time?.days * 86400000) + (time?.hours * 360000) + (time?.minutes * 60000) + (time?.seconds * 1000); - try{await message.member.timeout(timeout, "トークンの送信")}catch{console.error('x: timeout')} - embed.setFooter({text: `${time?.days!=0?`${time?.days} 日 `:''}${time?.hours!=0?`${time?.hours} 時間 `:''}${time?.minutes!=0?`${time?.minutes} 分 `:''}${time?.seconds!=0?`${time?.seconds} 秒 `:''}の間タイムアウトしました`}) - await message.channel.send({embeds: [embed]}); - if (settings.channel?.log && message.guild.channels.cache.get(settings.channel?.log)) { - const channel = message.guild.channels.cache.get(settings.channel?.log); - await channel.send({embeds: [embed]}); - try { - message.member.send({ embeds: [embed] }) - } catch (e) { - console.error(e) - } - } - } catch (e) { - console.error(e); - } -}) - -client.on("messageUpdate", async (oldMessage, newMessage) => { - if (newMessage.author.bot || newMessage.member?.permissions.has('ADMINISTRATOR')) return; - const guildId = newMessage.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (!fs.existsSync(settingsFilePath)) return; - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings.setting?.disable === true) return; - const mods = settings?.mods; - if (hasRole(newMessage, mods)) return; - const roleIds = newMessage.member.roles.cache.map((role) => role.id); - function isIgnore(channelId, roleIds, userId, settings) { - if (settings.ignore_channels?.includes(channelId)) return true; - if (roleIds.some(roleId => settings.ignore_roles?.includes(roleId))) return true; - if (settings.ignore_users?.includes(userId)) return true; - return false; - } - if (isIgnore(newMessage.channel.id, roleIds, newMessage.author.id, settings)) return; - - const regex = /([A-Za-z\d]{24})\.([A-Za-z\d-_]{6})\.([A-Za-z\d-_]{27})|([A-Za-z\d-_]{59})\.([A-Za-z\d-_]{27})/g; - if (!newMessage.content.match(regex)) return; - try { - await newMessage.guild.members.fetch(); - const embed = new MessageEmbed() - .setTitle("トークンを検出しました") - .setThumbnail(newMessage.author.displayAvatarURL()) - .setDescription(`実行者: ${newMessage.member}\nName: **${newMessage.author.tag.split('#')[1] === '0' ? newMessage.author.username : newMessage.author.tag}**\nID: ${newMessage.author.id}`) - .setColor(config.color); - const time = { - days: settings.setting?.timeout?.days, - hours: settings.setting?.timeout?.hours, - minutes: settings.setting?.timeout?.minutes, - seconds: settings.setting?.timeout?.seconds, - } - try{await newMessage.delete()}catch{console.error('x: delete')} - const timeout = (time?.days * 86400000) + (time?.hours * 360000) + (time?.minutes * 60000) + (time?.seconds * 1000); - try{await newMessage.member.timeout(timeout, "トークンの送信")}catch{console.error('x: timeout')} - embed.setFooter({text: `${time?.days!=0?`${time?.days} 日 `:''}${time?.hours!=0?`${time?.hours} 時間 `:''}${time?.minutes!=0?`${time?.minutes} 分 `:''}${time?.seconds!=0?`${time?.seconds} 秒 `:''}の間タイムアウトしました`}) - await newMessage.channel.send({ embeds: [embed] }); - if (settings.channel?.log && newMessage.guild.channels.cache.get(settings.channel?.log)) { - const channel = newMessage.guild.channels.cache.get(settings.channel?.log); - await channel.send({ embeds: [embed] }); - try { - newMessage.member.send({ embeds: [embed] }) - } catch (e) { - console.error(e) - } - } - } catch (e) { - console.error(e); - } -}); - -client.on("messageCreate", async message => { - if (message.author.bot || message.member?.permissions.has('ADMINISTRATOR')) return; - const guildId = message.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (!fs.existsSync(settingsFilePath)) return; - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings.setting?.disable === true || settings.setting?.antiinvite === false) return; - const mods = settings?.mods; - if (hasRole(message, mods)) return; - const roleIds = message.member.roles.cache.map((role) => role.id); - function isIgnore(channelId, roleIds, userId, settings) { - if (settings.ignore_channels?.includes(channelId)) return true; - if (roleIds.some(roleId => settings.ignore_roles?.includes(roleId))) return true; - if (settings.ignore_users?.includes(userId)) return true; - return false; - } - if (isIgnore(message.channel.id, roleIds, message.author.id, settings)) return; - - const regex = /(https?:\/\/)?(www\.)?(discord\.gg|discordapp\.com\/invite)\/[a-zA-Z0-9]+/gi; - if (!message.content.match(regex)) return; - try { - await message.guild.members.fetch(); - const embed = new MessageEmbed() - .setTitle("招待リンクを検出しました") - .setThumbnail(message.author.displayAvatarURL()) - .setDescription(`実行者: ${message.member}\nName: **${message.author.tag.split('#')[1] === '0' ? message.author.username : message.author.tag}**\nID: ${message.author.id}`) - .setColor(config.color); - const ch = message.channel; - embed.addFields = ([ - { - name: "チャンネル", - value: `${ch} (**${ch.name}**, ID: ${ch.id})` - } - ]); - try{await message.delete()}catch{console.error('x: delete')} - if (settings.setting?.timeout?.antiinvite) { - const time = { - days: settings.setting?.timeout?.days, - hours: settings.setting?.timeout?.hours, - minutes: settings.setting?.timeout?.minutes, - seconds: settings.setting?.timeout?.seconds, - } - const timeout = (time?.days * 86400000) + (time?.hours * 360000) + (time?.minutes * 60000) + (time?.seconds * 1000); - try{await message.member.timeout(timeout, "招待リンクの送信")}catch{console.error('x: timeout')} - embed.setFooter({text: `${time?.days!=0?`${time?.days} 日 `:''}${time?.hours!=0?`${time?.hours} 時間 `:''}${time?.minutes!=0?`${time?.minutes} 分 `:''}${time?.seconds!=0?`${time?.seconds} 秒 `:''}の間タイムアウトしました`}) - } - await message.channel.send({embeds: [embed]}); - if (settings.channel?.log && message.guild.channels.cache.get(settings.channel?.log)) { - const channel = message.guild.channels.cache.get(settings.channel?.log); - await channel.send({embeds: [embed]}); - try { - message.member.send({ embeds: [embed] }) - } catch (e) { - console.error(e) - } - } - } catch (e) { - console.error(e); - } -}) - -client.on("messageUpdate", async (oldMessage, newMessage) => { - if (newMessage.author.bot || newMessage.member?.permissions.has('ADMINISTRATOR')) return; - const guildId = newMessage.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (!fs.existsSync(settingsFilePath)) return; - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings.setting?.disable === true || settings.setting?.antiinvite === false) return; - const mods = settings?.mods; - if (hasRole(newMessage, mods)) return; - const roleIds = newMessage.member.roles.cache.map((role) => role.id); - function isIgnore(channelId, roleIds, userId, settings) { - if (settings.ignore_channels?.includes(channelId)) return true; - if (roleIds.some(roleId => settings.ignore_roles?.includes(roleId))) return true; - if (settings.ignore_users?.includes(userId)) return true; - return false; - } - if (isIgnore(newMessage.channel.id, roleIds, newMessage.author.id, settings)) return; - - const regex = /(https?:\/\/)?(www\.)?(discord\.gg|discordapp\.com\/invite)\/[a-zA-Z0-9]+/gi; - if (!newMessage.content.match(regex)) return; - try { - await newMessage.guild.members.fetch(); - const embed = new MessageEmbed() - .setTitle("招待リンクを検出しました") - .setThumbnail(newMessage.author.displayAvatarURL()) - .setDescription(`実行者: ${newMessage.member}\nName: **${newMessage.author.tag.split('#')[1] === '0' ? newMessage.author.username : newMessage.author.tag}**\nID: ${newMessage.author.id}`) - .setColor(config.color); - try{await newMessage.delete()}catch{console.error('x: delete')} - if (settings.setting?.timeout?.antiinvite) { - const time = { - days: settings.setting?.timeout?.days, - hours: settings.setting?.timeout?.hours, - minutes: settings.setting?.timeout?.minutes, - seconds: settings.setting?.timeout?.seconds, - } - const timeout = (time?.days * 86400000) + (time?.hours * 360000) + (time?.minutes * 60000) + (time?.seconds * 1000); - try{await newMessage.member.timeout(timeout, "招待リンクの送信")}catch{console.error('x: timeout')} - embed.setFooter({text: `${time?.days!=0?`${time?.days} 日 `:''}${time?.hours!=0?`${time?.hours} 時間 `:''}${time?.minutes!=0?`${time?.minutes} 分 `:''}${time?.seconds!=0?`${time?.seconds} 秒 `:''}の間タイムアウトしました`}) - } - await newMessage.channel.send({embeds: [embed]}); - if (settings.channel?.log && newMessage.guild.channels.cache.get(settings.channel?.log)) { - const channel = newMessage.guild.channels.cache.get(settings.channel?.log); - await channel.send({embeds: [embed]}); - try { - newMessage.member.send({ embeds: [embed] }) - } catch (e) { - console.error(e) - } - } - } catch (e) { - console.error(e); - } -}) - -client.on("messageCreate", async message => { - if (message.author.bot || message.member?.permissions.has('ADMINISTRATOR')) return; - const guildId = message.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (!fs.existsSync(settingsFilePath)) return; - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings.setting?.disable === true || settings.setting?.antilink === false) return; - const mods = settings?.mods; - if (hasRole(message, mods)) return; - const roleIds = message.member.roles.cache.map((role) => role.id); - function isIgnore(channelId, roleIds, userId, settings) { - if (settings.ignore_channels?.includes(channelId)) return true; - if (roleIds.some(roleId => settings.ignore_roles?.includes(roleId))) return true; - if (settings.ignore_users?.includes(userId)) return true; - return false; - } - if (isIgnore(message.channel.id, roleIds, message.author.id, settings)) return; - - const regex = /https?:\/\/\S+/gi; - const discordRegex = /(https?:\/\/)?(www\.)?(discord\.gg|discordapp\.com\/invite)\/[a-zA-Z0-9]+/gi; - const contentToCheck = message.content; - - if (!regex.test(contentToCheck) || discordRegex.test(contentToCheck)) return; - try { - await message.guild.members.fetch(); - const embed = new MessageEmbed() - .setTitle("リンクを検出しました") - .setThumbnail(message.author.displayAvatarURL()) - .setDescription(`実行者: ${message.member}\nName: **${message.author.tag.split('#')[1] === '0' ? message.author.username : message.author.tag}**\nID: ${message.author.id}`) - .setColor(config.color); - const ch = message.channel; - embed.addFields = ([ - { - name: "チャンネル", - value: `${ch} (**${ch.name}**, ID: ${ch.id})` - } - ]); - try{await message.delete()}catch{console.error('x: delete')} - if (settings.setting?.timeout?.antiilink) { - const time = { - days: settings.setting?.timeout?.days, - hours: settings.setting?.timeout?.hours, - minutes: settings.setting?.timeout?.minutes, - seconds: settings.setting?.timeout?.seconds, - } - const timeout = (time?.days * 86400000) + (time?.hours * 360000) + (time?.minutes * 60000) + (time?.seconds * 1000); - try{await message.member.timeout(timeout, "リンクの送信")}catch{console.error('x: timeout')} - embed.setFooter({text: `${time?.days!=0?`${time?.days} 日 `:''}${time?.hours!=0?`${time?.hours} 時間 `:''}${time?.minutes!=0?`${time?.minutes} 分 `:''}${time?.seconds!=0?`${time?.seconds} 秒 `:''}の間タイムアウトしました`}) - } - await message.channel.send({embeds: [embed]}); - if (settings.channel?.log && message.guild.channels.cache.get(settings.channel?.log)) { - const channel = message.guild.channels.cache.get(settings.channel?.log); - await channel.send({embeds: [embed]}); - try { - message.member.send({ embeds: [embed] }) - } catch (e) { - console.error(e) - } - } - } catch (e) { - console.error(e); - } -}) - -client.on("messageUpdate", async (oldMessage, newMessage) => { - if (newMessage.author.bot || newMessage.member?.permissions.has('ADMINISTRATOR')) return; - - const guildId = newMessage.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - - if (!fs.existsSync(settingsFilePath)) return; - - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - - if (settings.setting?.disable === true || settings.setting?.antilink === false) return; - const mods = settings?.mods; - if (hasRole(newMessage, mods)) return; - const roleIds = newMessage.member.roles.cache.map((role) => role.id); - - function isIgnore(channelId, roleIds, userId, settings) { - if (settings.ignore_channels?.includes(channelId)) return true; - if (roleIds.some(roleId => settings.ignore_roles?.includes(roleId))) return true; - if (settings.ignore_users?.includes(userId)) return true; - return false; - } - - if (isIgnore(newMessage.channel.id, roleIds, newMessage.author.id, settings)) return; - - const regex = /https?:\/\/\S+/gi; - const discordRegex = /(https?:\/\/)?(www\.)?(discord\.gg|discordapp\.com\/invite)\/[a-zA-Z0-9]+/gi; - const contentToCheck = newMessage.content; - - if (!regex.test(contentToCheck) || discordRegex.test(contentToCheck)) return; - - try { - await newMessage.guild.members.fetch(); - - const embed = new MessageEmbed() - .setTitle("リンクを検出しました") - .setThumbnail(newMessage.author.displayAvatarURL()) - .setDescription(`実行者: ${newMessage.member}\nName: **${newMessage.author.tag.split('#')[1] === '0' ? newMessage.author.username : newMessage.author.tag}**\nID: ${newMessage.author.id}`) - .setColor(config.color); - try{await newMessage.delete()}catch{console.error('x: delete')} - if (settings.setting?.timeout?.antiilink) { - const time = { - days: settings.setting?.timeout?.days, - hours: settings.setting?.timeout?.hours, - minutes: settings.setting?.timeout?.minutes, - seconds: settings.setting?.timeout?.seconds, - } - const timeout = (time?.days * 86400000) + (time?.hours * 360000) + (time?.minutes * 60000) + (time?.seconds * 1000); - try{await newMessage.member.timeout(timeout, "リンクの送信")}catch{console.error('x: timeout')} - embed.setFooter({text: `${time?.days!=0?`${time?.days} 日 `:''}${time?.hours!=0?`${time?.hours} 時間 `:''}${time?.minutes!=0?`${time?.minutes} 分 `:''}${time?.seconds!=0?`${time?.seconds} 秒 `:''}の間タイムアウトしました`}) - } - await newMessage.channel.send({ embeds: [embed] }); - if (settings.channel?.log && newMessage.guild.channels.cache.get(settings.channel?.log)) { - const channel = newMessage.guild.channels.cache.get(settings.channel?.log); - await channel.send({ embeds: [embed] }); - try { - newMessage.member.send({ embeds: [embed] }) - } catch (e) { - console.error(e) - } - } - } catch (e) { - console.error(e); - } -}); - -client.on("messageCreate", async message => { - if (message.author.bot || message.member?.permissions.has('ADMINISTRATOR')) return; - const guildId = message.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (!fs.existsSync(settingsFilePath)) return; - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings.setting?.disable === true || settings.setting?.antingwords === false) return; - const mods = settings?.mods; - if (hasRole(message, mods)) return; - const roleIds = message.member.roles.cache.map((role) => role.id); - function isIgnore(channelId, roleIds, userId, settings) { - if (settings.ignore_channels?.includes(channelId)) return true; - if (roleIds.some(roleId => settings.ignore_roles?.includes(roleId))) return true; - if (settings.ignore_users?.includes(userId)) return true; - return false; - } - if (isIgnore(message.channel.id, roleIds, message.author.id, settings)) return; - - const regex = settings?.ngwords; - if (regex.length == 0) return; - if (!regex.includes(message.content)) return; - try { - await message.guild.members.fetch(); - const embed = new MessageEmbed() - .setTitle("NGワードを検出しました") - .setThumbnail(message.author.displayAvatarURL()) - .setDescription(`実行者: ${message.member}\nName: **${message.author.tag.split('#')[1] === '0' ? message.author.username : message.author.tag}**\nID: ${message.author.id}`) - .setColor(config.color); - const ch = message.channel; - embed.addFields = ([ - { - name: "チャンネル", - value: `${ch} (**${ch.name}**, ID: ${ch.id})` - } - ]); - try{await message.delete()}catch{console.error('x: delete')} - if (settings.setting?.timeout?.antingwords) { - const time = { - days: settings.setting?.timeout?.days, - hours: settings.setting?.timeout?.hours, - minutes: settings.setting?.timeout?.minutes, - seconds: settings.setting?.timeout?.seconds, - } - const timeout = (time?.days * 86400000) + (time?.hours * 360000) + (time?.minutes * 60000) + (time?.seconds * 1000); - try{await message.member.timeout(timeout, "NGワードの送信")}catch{console.error('x: timeout')} - embed.setFooter({text: `${time?.days!=0?`${time?.days} 日 `:''}${time?.hours!=0?`${time?.hours} 時間 `:''}${time?.minutes!=0?`${time?.minutes} 分 `:''}${time?.seconds!=0?`${time?.seconds} 秒 `:''}の間タイムアウトしました`}) - } - await message.channel.send({embeds: [embed]}); - if (settings.channel?.log && message.guild.channels.cache.get(settings.channel?.log)) { - const channel = message.guild.channels.cache.get(settings.channel?.log); - await channel.send({embeds: [embed]}); - try { - message.member.send({ embeds: [embed] }) - } catch (e) { - console.error(e) - } - } - } catch (e) { - console.error(e); - } -}) - -client.on("messageUpdate", async (oldMessage, newMessage) => { - if (newMessage.author.bot || newMessage.member?.permissions.has('ADMINISTRATOR')) return; - - const guildId = newMessage.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (!fs.existsSync(settingsFilePath)) return; - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - const mods = settings?.mods; - if (hasRole(newMessage, mods)) return; - const roleIds = newMessage.member.roles.cache.map((role) => role.id); - function isIgnore(channelId, roleIds, userId, settings) { - if (settings.ignore_channels?.includes(channelId)) return true; - if (roleIds.some(roleId => settings.ignore_roles?.includes(roleId))) return true; - if (settings.ignore_users?.includes(userId)) return true; - return false; - } - if (isIgnore(newMessage.channel.id, roleIds, newMessage.author.id, settings)) return; - - const regex = settings?.ngwords; - if (regex.length == 0) return; - if (!regex.includes(newMessage.content)) return; - try { - await newMessage.delete(); - await newMessage.guild.members.fetch(); - const embed = new MessageEmbed() - .setTitle("NGワードを検出しました") - .setThumbnail(newMessage.author.displayAvatarURL()) - .setDescription(`実行者: ${newMessage.member}\nName: **${newMessage.author.tag.split('#')[1] === '0' ? newMessage.author.username : newMessage.author.tag}**\nID: ${newMessage.author.id}`) - .setColor(config.color); - try{await newMessage.delete()}catch{console.error('x: delete')} - if (settings.setting?.timeout?.antingwords) { - const time = { - days: settings.setting?.timeout?.days, - hours: settings.setting?.timeout?.hours, - minutes: settings.setting?.timeout?.minutes, - seconds: settings.setting?.timeout?.seconds, - } - const timeout = (time?.days * 86400000) + (time?.hours * 360000) + (time?.minutes * 60000) + (time?.seconds * 1000); - try{await newMessage.member.timeout(timeout, "NGワードの送信")}catch{console.error('x: timeout')} - embed.setFooter({text: `${time?.days!=0?`${time?.days} 日 `:''}${time?.hours!=0?`${time?.hours} 時間 `:''}${time?.minutes!=0?`${time?.minutes} 分 `:''}${time?.seconds!=0?`${time?.seconds} 秒 `:''}の間タイムアウトしました`}); - } - await newMessage.channel.send({embeds: [embed]}); - if (settings.channel?.log && newMessage.guild.channels.cache.get(settings.channel?.log)) { - const channel = newMessage.guild.channels.cache.get(settings.channel?.log); - await channel.send({embeds: [embed]}); - try { - newMessage.member.send({ embeds: [embed] }) - } catch (e) { - console.error(e) - } - } - } catch (e) { - console.error(e); - } -}); - -client.on("messageCreate", async (message) => { - if (message.author.bot || message.member?.permissions.has("ADMINISTRATOR")) return; - const userId = message.author.id; - const timestamp = Date.now(); - const content = message.content; - const id = message.id; - const guildId = message.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (!fs.existsSync(settingsFilePath)) return; - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings.setting?.disable === true || settings.setting?.antispam === false) return; - const mods = settings?.mods; - if (hasRole(message, mods)) return; - const roleIds = message.member.roles.cache.map((role) => role.id); - - function isIgnore(channelId, roleIds, userId, settings) { - if (settings.ignore_channels?.includes(channelId)) return true; - if (roleIds.some((roleId) => settings.ignore_roles?.includes(roleId))) return true; - if (settings.ignore_users?.includes(userId)) return true; - return false; - } - - if (isIgnore(message.channel.id, roleIds, message.author.id, settings)) return; - - const userSpamData = spamUsers.get(userId); - - if (userSpamData) { - const timeDifference = message.createdTimestamp - userSpamData.lastMessageTimestamp; - if (timeDifference > 4000) { - userSpamData.messageCount = 0; - } - userSpamData.messageCount++; - userSpamData.lastMessageTimestamp = message.createdTimestamp; - - if (userSpamData.messageCount >= 5) { - try { - await message.guild.members.fetch(); - const userMessages = message.channel.messages.cache.filter((msg) => { - return msg.author.id === message.author.id && msg.createdTimestamp >= (message.createdTimestamp - 10000); - }); - - userMessages.forEach(async (msg) => { - await msg.delete(); - }); - - const embed = new MessageEmbed() - .setTitle("スパムを検出しました") - .setThumbnail(message.author.displayAvatarURL()) - .setDescription(`実行者: ${message.member}\nName: **${message.author.tag.split('#')[1] === '0' ? message.author.username : message.author.tag}**\nID: ${message.author.id}`) - .setColor(config.color); - - const ch = message.channel; - embed.addFields([ - { - name: "チャンネル", - value: `${ch} (**${ch.name}**, ID: ${ch.id})` - } - ]); - try{await message.delete()}catch{console.error('x: delete')} - if (settings.setting?.timeout?.antispam) { - const time = settings.setting?.timeout; - const timeout = (time?.days * 86400000) + (time?.hours * 3600000) + (time?.minutes * 60000) + (time?.seconds * 1000); - try{await message.member.timeout(timeout, "スパム行為")}catch{console.error('x: timeout')} - embed.setFooter(`${time?.days !== 0 ? `${time?.days} 日 ` : ''}${time?.hours !== 0 ? `${time?.hours} 時間 ` : ''}${time?.minutes !== 0 ? `${time?.minutes} 分 ` : ''}${time?.seconds !== 0 ? `${time?.seconds} 秒 ` : ''}の間タイムアウトしました`); - } - - await message.channel.send({ embeds: [embed] }); - - if (settings.channel?.log && message.guild.channels.cache.get(settings.channel?.log)) { - const channel = message.guild.channels.cache.get(settings.channel?.log); - await channel.send({ embeds: [embed] }); - try { - message.member.send({ embeds: [embed] }) - } catch (e) { - console.error(e) - } - } - } catch (e) { - console.error(e); - } - } - } else { - spamUsers.set(userId, { - messageCount: 1, - lastMessageTimestamp: message.createdTimestamp, - }); - } -}); - -client.on("messageDelete", async (deletedMessage) => { - if (deletedMessage.author.bot) return; - const guildId = deletedMessage.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (!fs.existsSync(settingsFilePath)) return; - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings.setting?.disable === true) return; - - try { - const embed = new MessageEmbed() - .setTitle("メッセージが削除されました") - .setThumbnail(deletedMessage.author.displayAvatarURL()) - .setDescription(`実行者: ${deletedMessage.member}\nName: **${deletedMessage.author.tag.split('#')[1] === '0' ? deletedMessage.author.username : deletedMessage.author.tag}**\nID: ${deletedMessage.author.id}`) - .setColor('RED'); - const ch = deletedMessage.channel; - const fields = [ - { - name: "チャンネル", - value: `${ch} (**${ch.name}**, ID: ${ch.id})` - } - ]; - let content = deletedMessage.content; - if (content.length > 50) { - content = content.slice(0, 50) + '...'; - }; - - fields.push( - { - name: 'メッセージ内容', - value: content || 'メッセージ内容がありません', - } - ) - - if (deletedMessage.attachments.size > 0) { - const attachments = []; - let i = 0; - deletedMessage.attachments.each((attachment) => { - i = i + 1; - if (i <= 2) { - attachments.push(`[attachment ${i}](${attachment.proxyURL})`); - } else if (i == 3) { - attachments.push(`+ ${deletedMessage.attachments.size - i} 枚の画像`) - } - }); - - fields.push({ - name: '画像', - value: attachments.join('\n'), - }); - } - - if (fields.length > 0) { - embed.addFields(fields) - } - - if (settings.channel?.msglog && deletedMessage.guild.channels.cache.get(settings.channel?.msglog)) { - const channel = deletedMessage.guild.channels.cache.get(settings.channel?.msglog); - await channel.send({embeds: [embed]}); - } - } catch (e) { - console.error(e); - } -}); - -client.on("messageUpdate", async (oldMessage, newMessage) => { - if (newMessage.author.bot) return; - const guildId = newMessage.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (!fs.existsSync(settingsFilePath)) return; - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings.setting?.disable === true) return; - - try { - const embed = new MessageEmbed() - .setTitle("メッセージが編集されました") - .setThumbnail(newMessage.author.displayAvatarURL()) - .setDescription(`実行者: ${newMessage.member}\nName: **${newMessage.author.tag.split('#')[1] === '0' ? newMessage.author.username : newMessage.author.tag}**\nID: ${newMessage.author.id}`) - .setColor('YELLOW'); - - const ch = newMessage.channel; - const fields = [ - { - name: "チャンネル", - value: `${ch} (**${ch.name}**, ID: ${ch.id})` - } - ]; - let oldContent = oldMessage.content; - if (oldContent.length > 50) { - oldContent = oldContent.slice(0, 50) + '...'; - }; - - fields.push( - { - name: '編集前メッセージ内容', - value: oldContent || 'メッセージ内容がありません', - } - ) - - if (oldMessage.attachments.size > 0) { - const attachments = []; - let i = 0; - oldMessage.attachments.each((attachment) => { - i = i + 1; - if (i <= 2) { - attachments.push(`[attachment ${i}](${attachment.proxyURL})`); - } else if (i == 3) { - attachments.push(`+ ${oldMessage.attachments.size - i} 枚の画像`) - } - }); - - fields.push({ - name: '画像', - value: attachments.join('\n'), - }); - } - - let newContent = newMessage.content; - if (newContent.length > 50) { - newContent = newContent.slice(0, 50) + '...'; - }; - - fields.push( - { - name: '編集後のメッセージ内容', - value: newContent || 'メッセージ内容がありません', - } - ) - - if (newMessage.attachments.size > 0) { - const attachments = []; - let i = 0; - newMessage.attachments.each((attachment) => { - i = i + 1; - if (i <= 2) { - attachments.push(`[attachment ${i}](${attachment.proxyURL})`); - } else if (i == 3) { - attachments.push(`+ ${newMessage.attachments.size - i} 枚の画像`) - } - }); - - fields.push({ - name: '編集後の画像', - value: attachments.join('\n'), - }); - } - - if (fields.length > 0) { - embed.addFields(fields) - } - - if (settings.channel?.log && newMessage.guild.channels.cache.get(settings.channel?.msglog)) { - const channel = newMessage.guild.channels.cache.get(settings.channel?.msglog); - await channel.send({embeds: [embed]}); - } - } catch (e) { - console.error(e); - } -}) - -client.on("channelCreate", async channel => { - const guildId = channel.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (!fs.existsSync(settingsFilePath)) return; - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings.setting?.disable === true) return; - if (!settings.role?.muted || !channel.guild.roles.cache.get(settings.role?.muted)) return; - await channel.permissionOverwrites.edit(channel.guild.roles.cache.get(settings.role?.muted), { - VIEW_CHANNEL: false, - CONNECT: false, - SEND_MESSAGES: false - }) -}) - -tracker.on("guildMemberAdd", async (member, inviter, invite, error) => { - const guild = member.guild; - const guildId = guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (!fs.existsSync(settingsFilePath)) return; - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings.setting?.disable === true) return; - if (settings?.muted_users.includes(member.user.id)) { - const muted_role = await member.guild.roles.cache.get(settings.role.muted); - if (muted_role) { - try { - member.roles.add(muted_role, 'Muted user') - } catch (e) { - console.error(e); - } - } - } - if (settings.role?.autos.length > 0 && !member.user.bot && !settings?.muted_users.includes(member.user.id)) { - const roleIds = settings.role.autos; - for (const roleId of roleIds) { - if (member.guild.roles.cache.get(roleId)) { - try { - member.roles.add(roleId, 'Auto role') - } catch (e) { - console.error(e); - } - } - } - } - - const embed = new MessageEmbed() - .setTitle("メンバーが参加しました") - .setThumbnail(member.user.displayAvatarURL()) - .setColor(config.color); - if (invite?.code !== `Unknown`) { - try { - embed.setDescription(`<@${inviter?.id}> (**${inviter?.tag.split('#')[1] === '0'?inviter.username:inviter.tag}** ID: ${inviter?.id}) の **[${invite?.code}](${invite?.url})** を使用して参加しました\n参加者: ${member}\nName: **${member.user.tag.split('#')[1] === '0' ? member.user.username : member.user.tag}**\nID: ${member.user.id}`) - } catch (e) { - console.error(e) - } - } - if (member.user.bot) { - try { - embed.setDescription(`<@${inviter?.id}> (**${inviter?.tag.split('#')[1] === '0'?inviter.username:inviter.tag}** ID: ${inviter?.id}) が追加したBotです\n参加者: ${member}\nName: **${member.user.tag.split('#')[1] === '0' ? member.user.username : member.user.tag}**\nID: ${member.user.id}`) - } catch (e) { - console.error(e) - } - } - if (!member.user.bot && invite?.code === `Unknown`) { - try { - embed.setDescription(`参加方法は **不明** です\n参加者: ${member}\nName: **${member.user.tag.split('#')[1] === '0' ? member.user.username : member.user.tag}**\nID: ${member.user.id}`) - } catch (e) { - console.error(e) - } - } - try { - const channel = await guild.channels.cache.get(settings.channel?.invite); - if (!channel) return; - await channel.send({ embeds: [embed] }) - } catch (e) { - console.error(e) - } -}); - -function hasRole(message, mods) { - let count = 0; - const roles = message.member?.roles?.cache; - if (!roles) { - return false; - } - for (const role of roles.values()) { - if (mods.includes(role.id)) { - count++; - } - } - return count > 0; -} - -client.on('guildMemberUpdate', (oldMember, newMember) => { - const guildId = newMember.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (!fs.existsSync(settingsFilePath)) return; - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - const mutedRole = settings.role.muted; - if (settings.setting?.disable === true) return; - const newRoles = newMember.roles.cache; - const oldRoles = oldMember.roles.cache; - const userId = newMember.user.id; - // add - if (!oldRoles.has(mutedRole) && newRoles.has(mutedRole)) { - if (!settings?.muted_users.includes(userId)) { - settings.muted_users.push(userId); - fs.writeFileSync(settingsFilePath, JSON.stringify(settings, null, 2)); - } - } - // remove - if (oldRoles.has(mutedRole) && !newRoles.has(mutedRole)) { - if (settings?.muted_users.includes(userId)) { - settings.muted_users = settings?.muted_users?.filter(id => id !== userId); - fs.writeFileSync(settingsFilePath, JSON.stringify(settings, null, 2)); - } - } -}); - -client.login(process.env.DISCORD_BOT_TOKEN); \ No newline at end of file diff --git a/bot/functions/interaction.js b/bot/functions/interaction.js deleted file mode 100644 index 46a0947..0000000 --- a/bot/functions/interaction.js +++ /dev/null @@ -1,578 +0,0 @@ -const { Client, MessageEmbed, MessageActionRow, MessageButton, MessageAttachment } = require("discord.js"); -const fs = require("fs"); -const Jimp = require('jimp'); -const options = { intents: [3276799] }; -const client = new Client(options); - -const config = JSON.parse(fs.readFileSync("./config.json", 'utf8')); - -const ticketCooldowns = new Map(); -const verifyCooldowns = new Map(); - -client.on("ready", () => { - console.log(`interactions.js OK!`); -}); - -// delete -client.on("interactionCreate", async int => { - if (int.customId === 'delete') { - try { - const embed = new MessageEmbed() - .setDescription(`${int.member} によって削除済み`) - .setColor(config.color); - - await int.message.edit({ content: null, embeds: [embed], components: [] }) - } catch (e) { - console.error(e) - } - } -}) - -// rolepanel -client.on("interactionCreate", async int => { - // normal - if (int.customId === 'rp') { - const guildId = int.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - const err_embed = new MessageEmbed(); - try { - if (int.member.roles.cache.has(settings?.role?.muted)) { - err_embed.setDescription(`❌ あなたはミュートされています`).setColor('RED'); - const reply = await int.channel.send({ embeds: [err_embed] }); - setTimeout(() => { - reply.delete(); - }, 3000) - return; - } - const roleId = int.values[0]; - const role = await int.guild.roles.cache.get(roleId); - if (!role) { - err_embed.setDescription(`❌ ロールが存在しません`).setColor('RED'); - const reply = await int.channel.send({ content: `${int.member}`, embeds: [err_embed] }) - setTimeout(() => { - reply.delete(); - }, 3000) - await int.update({ - components: int.message.components.map(row => { - return { - type: 'ACTION_ROW', - components: row.components.map(component => { - if (component.customId === int.customId) { - component.options.forEach(option => option.default = false); - } - return component; - }) - } - }) - }); - return; - }; - - const member = int.guild.members.cache.get(int.user.id); - - const hasRole = member.roles.cache.some(role => role.id === roleId); - const embed = new MessageEmbed() - .setColor(config.color); - if (hasRole) { - try { - await member.roles.remove(role); - const reply = await int.channel.send({ content: `${int.member}` ,embeds: [embed.setDescription(`${role} を剥奪しました`)]}); - setTimeout(async () => { - await reply.delete(); - }, 3000) - } catch (e) { - console.error(e); - err_embed.setDescription(`❌ エラーが発生しました`).setColor('RED'); - const reply = await int.channel.send({ content: `${int.member}`, embeds: [err_embed] }) - setTimeout(async () => { - await reply.delete(); - }, 3000) - }; - } else { - try { - await member.roles.add(role); - const reply = await int.channel.send({ content: `${int.member}` ,embeds: [embed.setDescription(`${role} を付与しました`)]}); - setTimeout(async () => { - await reply.delete(); - }, 3000) - } catch (e) { - console.error(e); - err_embed.setDescription(`❌ エラーが発生しました`).setColor('RED'); - const reply = await int.channel.send({ content: `${int.member}`, embeds: [err_embed] }) - setTimeout(async () => { - await reply.delete(); - }, 3000) - }; - }; - - await int.update({ - components: int.message.components.map(row => { - return { - type: 'ACTION_ROW', - components: row.components.map(component => { - if (component.customId === int.customId) { - component.options.forEach(option => option.default = false); - } - return component; - }) - } - }) - }); - } catch (e) { - console.error(e); - err_embed.setDescription(`❌ エラーが発生しました`).setColor('RED'); - const reply = await int.channel.send({ content: `${int.member}`, embeds: [err_embed] }) - setTimeout(async () => { - await reply.delete(); - }, 3000) - } - }; - - // single - if (int.customId === 'single-rp') { - const guildId = int.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - const err_embed = new MessageEmbed(); - try { - if (int.member.roles.cache.has(settings?.role?.muted)) { - err_embed.setDescription(`❌ あなたはミュートされています`).setColor('RED'); - const reply = await int.channel.send({ embeds: [err_embed] }); - setTimeout(() => { - reply.delete(); - }, 3000) - return; - } - const roleId = int.values[0]; - const role = await int.guild.roles.cache.get(roleId); - if (!role) { - err_embed.setDescription(`❌ ロールが存在しません`).setColor('RED'); - const reply = await int.channel.send({ content: `${int.member}`, embeds: [err_embed] }) - setTimeout(() => { - reply.delete(); - }, 3000) - await int.update({ - components: int.message.components.map(row => { - return { - type: 'ACTION_ROW', - components: row.components.map(component => { - if (component.customId === int.customId) { - component.options.forEach(option => option.default = false); - } - return component; - }) - } - }) - }); - return; - }; - - const member = int.guild.members.cache.get(int.user.id); - - const hasRole = member.roles.cache.some(role => role.id === roleId); - const embed = new MessageEmbed() - .setColor(config.color); - if (hasRole) { - try { - await member.roles.remove(role); - const reply = await int.channel.send({ content: `${int.member}` ,embeds: [embed.setDescription(`${role} を剥奪しました`)]}); - setTimeout(async () => { - await reply.delete(); - }, 3000) - } catch (e) { - console.error(e); - err_embed.setDescription(`❌ エラーが発生しました`).setColor('RED'); - const reply = await int.channel.send({ content: `${int.member}`, embeds: [err_embed] }) - setTimeout(async () => { - await reply.delete(); - }, 3000) - }; - } else { - try { - const rembed = int.message.embeds[0]; - const rdescription = rembed.description; - const rroleIds = rdescription.replace(/<@&|>/g,'').split('\n'); - const rmember = int.member; - const removedRoleIds = []; - - for (const rroleId of rroleIds) { - try { - if (removedRoleIds.includes(rroleId)) continue; - const rrole = int.guild.roles.cache.get(rroleId); - if (rrole) { - await rmember.roles.remove(rrole); - removedRoleIds.push(rroleId); - } - } catch (e) { - console.error(e); - } - } - - await member.roles.add(role); - const reply = await int.channel.send({ content: `${int.member}` ,embeds: [embed.setDescription(`${role} を付与しました`)]}); - setTimeout(async () => { - await reply.delete(); - }, 3000) - } catch (e) { - console.error(e); - err_embed.setDescription(`❌ エラーが発生しました`).setColor('RED'); - const reply = await int.channel.send({ content: `${int.member}`, embeds: [err_embed] }) - setTimeout(async () => { - await reply.delete(); - }, 3000) - } - - await int.update({ - components: int.message.components.map(row => { - return { - type: 'ACTION_ROW', - components: row.components.map(component => { - if (component.customId === int.customId) { - component.options.forEach(option => option.default = false); - } - return component; - }) - } - }) - }); - } - } catch (e) { - console.error(e); - err_embed.setDescription(`❌ エラーが発生しました`).setColor('RED'); - const reply = await int.channel.send({ content: `${int.member}`, embeds: [err_embed] }) - setTimeout(async () => { - await reply.delete(); - }, 3000) - } - } -}) - -// ticket -client.on("interactionCreate", async int => { - if (int.customId === 'ticket') { - await int.deferReply({ ephemeral: true }); - const err_embed = new MessageEmbed() - .setTitle("チケット") - const userId = int.user.id; - const max = 3; - await int.guild.channels.fetch(); - const ticketChannels = await int.guild.channels.cache.filter(ch => ch?.topic === `in-${int.message.id}-${userId}`); - if (ticketChannels.size >= max) { - err_embed.setDescription(`❌ 利用中のチケットが既に上限数あります`).setColor('RED'); - int.editReply({ embeds: [err_embed] }); - return; - } - - if (ticketCooldowns.has(`${userId}-${int.message.id}`)) { - const cooldown = ticketCooldowns.get(`${userId}-${int.message.id}`); - - if (Date.now() < cooldown) { - const remainingTime = Math.ceil((cooldown - Date.now()) / 1000); - const cooldown_embed = new MessageEmbed() - .setTitle("チケット") - .setDescription(`❌ クールダウン中です (残り ${remainingTime} 秒)`) - .setColor('RED'); - int.editReply({ embeds: [cooldown_embed], ephemeral: true }); - return; - } - } - - const guildId = int.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - - if (int.member.roles.cache.has(settings?.role?.muted)) { - err_embed.setDescription(`❌ あなたはミュートされています`).setColor('RED'); - int.editReply({ embeds: [err_embed] }); - return; - } - - ticketCooldowns.set(`${userId}-${int.message.id}`, Date.now() + 30000); - - try { - const number = settings?.setting?.ticket_number[int.message.id] || 0; - const formatnum = formatNumber(number + 1); - - function formatNumber(n) { - let numStr = n.toString(); - while (numStr.length < 6) { - numStr = '0' + numStr; - } - return numStr; - } - const p = ['VIEW_CHANNEL', 'SEND_MESSAGES', 'ATTACH_FILES', 'EMBED_LINKS', 'READ_MESSAGE_HISTORY']; - const overrides = [ - { - id: int.guild.roles.everyone, - deny: p - }, - { - id: userId, - allow: p - }, - ]; - const mods = settings?.mods; - if (mods.length > 0) { - for (const mod of mods) { - if (int.guild.roles.cache.get(mod)) { - const opt = { - id: mod, - allow: p - } - overrides.push(opt); - } - } - } - function getCategory(int) { - let category = int.guild.channels.cache.get(settings.setting.ticket_number?.category); - if (!category) { - category = int.channel.parent; - } - return category; - } - const channel = await int.guild.channels.create(`pc-ticket-${formatnum}-${int.message.id}`, { - type: 'GUILD_TEXT', - permissionOverwrites: overrides, - parent: getCategory(int) - }) - channel.setTopic(`in-${int.message.id}-${userId}`) - const embed = new MessageEmbed() - .setTitle('チケット') - .setDescription(`✅ チケットを作成しました`) - .setFooter({ text: `あと ${max - ticketChannels.size - 1} チケットが作成可能です` }) - .setColor(config.color); - await int.editReply({ content: `${channel}`, embeds: [embed], ephemeral: true }); - const ticket_embed = new MessageEmbed() - .setTitle('チケット') - .setDescription(`✅ チケットを作成しました\nチケットを閉じたい場合、下のボタンを押してください`) - .addFields([ - { - name: '作成者', - value: `${int.member}\nName: **${int.member.user.tag.split('#')[1] === '0' ? int.member.user.username : int.member.user.tag}**\nID: ${int.member.id}` - } - ]) - .setColor(config.color); - const row = new MessageActionRow() - .addComponents( - new MessageButton() - .setCustomId(`tclose-${userId}`) - .setEmoji('🔒') - .setLabel('Close') - .setStyle('SECONDARY') - ) - const msg = await channel.send({ content: `${int.member}`, embeds: [ticket_embed], components: [row] }); - await msg.pin() - settings.setting.ticket_number[int.message.id] = number + 1; - fs.writeFileSync(settingsFilePath, JSON.stringify(settings, null, 2)); - } catch (e) { - console.error(e); - err_embed.setDescription(`❌ エラーが発生しました`).setColor('RED'); - await int.editReply({ embeds: [err_embed], ephemeral: true }); - } - } - if (int.customId.startsWith('tclose')) { - try { - const userId = int.customId.split('-')[1]; - const user = int.guild.members.cache.get(userId); - await int.channel.permissionOverwrites.edit(user, { - VIEW_CHANNEL: false, - SEND_MESSAGES: false, - ATTACH_FILES: false, - EMBED_LINKS: false, - READ_MESSAGE_HISTORY: false - }); - await int.message.edit({ components: [] }); - const row = new MessageActionRow() - .addComponents( - new MessageButton() - .setCustomId(`tdelete`) - .setEmoji('🗑') - .setLabel('Delete') - .setStyle('DANGER') - ) - await int.reply({content: `チケットが ${int.member} (**${int.member.user.tag.split('#')[1] === '0' ? int.member.user.username : int.member.user.tag}**, ID: ${int.member.id}) によって閉じられました\nチケットを削除する場合は下のボタンを押してください`, components: [row] }) - const tId = int.channel.topic.split('-')[1]; - await int.channel.setTopic(`out-${tId}-${userId}`); - } catch (e) { - console.error(e); - const err_embed = new MessageEmbed() - .setTitle('チケット') - .setDescription(`❌ エラーが発生しました`) - .setColor('RED'); - await int.reply({ embeds: [err_embed], ephemeral: true }); - } - } - if (int.customId === 'tdelete') { - try { - await int.message.edit({ components: [] }); - const time = 15; - await int.reply(`${time} 秒後にチケットが削除されます`); - setTimeout(async () => await int.channel.delete(), time * 1000); - } catch (e) { - console.error(e); - const err_embed = new MessageEmbed() - .setTitle('チケット') - .setDescription(`❌ エラーが発生しました`) - .setColor('RED'); - await int.reply({ embeds: [err_embed], ephemeral: true }); - } - } -}); - -// verify -client.on("interactionCreate", async int => { - try { - if (int.customId.startsWith('verify')) { - - await int.deferReply({ ephemeral: true }); - - const err_embed = new MessageEmbed() - .setTitle("認証") - - const userId = int.user.id; - - const roleId = int.customId.split('-')[1]; - if (int.member.roles.cache.has(roleId)) { - err_embed.setDescription(`❌ 認証済みです`).setColor('RED'); - await int.editReply({ embeds: [err_embed], ephemeral: true }); - return; - } - - if (verifyCooldowns.has(userId)) { - const cooldown = verifyCooldowns.get(userId); - - if (Date.now() < cooldown) { - const remainingTime = Math.ceil((cooldown - Date.now()) / 1000); - const cooldown_embed = new MessageEmbed() - .setTitle("認証") - .setDescription(`❌ クールダウン中です (残り ${remainingTime} 秒)`) - .setColor('RED'); - int.editReply({ embeds: [cooldown_embed], ephemeral: true }); - return; - } - } - verifyCooldowns.set(userId, Date.now() + 30000); - - const role = await int.guild.roles.cache.get(roleId); - if (!role) { - err_embed.setDescription(`❌ ロールが存在しません`).setColor('RED'); - await int.editReply({ embeds: [err_embed], ephemeral: true }); - return; - } - - const guildId = int.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - - if (int.member.roles.cache.has(settings?.role?.muted)) { - err_embed.setDescription(`❌ あなたはミュートされています`).setColor('RED'); - int.editReply({ embeds: [err_embed] }); - return; - } - - const width = 350; // 幅 - const height = 130; // 高さ - - const image = new Jimp(width, height); - - function generateRandomString(length) { - const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; - let randomString = ''; - for (let i = 0; i < length; i++) { - const randomIndex = Math.floor(Math.random() * characters.length); - randomString += characters.charAt(randomIndex); - } - return randomString; - } - - const correctAnswer = generateRandomString(7); - console.log(correctAnswer); - - const font = await Jimp.loadFont(Jimp.FONT_SANS_64_WHITE); - image.print(font, 10, 10, `${correctAnswer}`); - - // 背景を黒にする - for (let x = 0; x < width; x++) { - for (let y = 0; y < height; y++) { - if (Math.random() < 0.75) { // 75%でノイズを追加 - image.setPixelColor(Jimp.cssColorToHex('#FFFFFF'), x, y); - } else { - const pixelColor = image.getPixelColor(x, y); - if (pixelColor !== Jimp.cssColorToHex('#FFFFFF')) { // 白色以外を背景色に変更 - image.setPixelColor(Jimp.cssColorToHex('#000000'), x, y); - } - } - } - } - - const buffer = await image.getBufferAsync(Jimp.MIME_PNG); - const attachment = new MessageAttachment(buffer, 'generated.png'); - try { - const timeLimit = 30 - const embed = new MessageEmbed() - .setAuthor(int.guild.name, int.guild.iconURL()) - .setTitle("認証") - .setDescription("画像内の文字列を送信してください\n※大文字か小文字かは問いません") - .setFooter({text: `${timeLimit} 秒以内に答えを送信してください`}) - .setColor(config.color); - const dmMsg = await int.member.send({ files: [attachment], content: `${int.member} 画像認証です`, embeds: [embed]}) - const success_embed = new MessageEmbed() - .setTitle("認証") - .setDescription(`✅ DMを送信しました`) - .setColor(config.color); - await int.editReply({ content: `<#${dmMsg.channel.id}>`, embeds: [success_embed] , ephemeral: true }); - - const filter = (response) => { - return response.author.id === int.user.id; - }; - const collector = dmMsg.channel.createMessageCollector({ filter, time: timeLimit * 1000 }); - collector.on('collect', (msg) => { - const userAnswer = msg.content; - if (userAnswer.toLowerCase() === correctAnswer.toLowerCase()) { - int.member.roles.add(roleId) - .then(() => { - const success_embed = new MessageEmbed() - .setTitle("認証") - .setDescription(`✅ 正解! **${role.name}** が付与されました`) - .setColor(config.color); - int.user.send({ embeds: [success_embed] }); - collector.stop(); - }) - .catch((error) => { - console.error(error); - err_embed.setDescription(`❌ ロールを付与できませんでした`); - int.user.send({ embeds: [err_embed] }); - collector.stop(); - }); - } else { - const incorrect_embed = new MessageEmbed() - .setTitle("認証") - .setDescription(`❌ 不正解です、もう一度やり直してください`) - .setColor('RED'); - int.user.send({ embeds: [incorrect_embed] }); - collector.stop(); - } - }); - - collector.on('end', (collected, reason) => { - if (reason === 'time') { - const timeout_embed = new MessageEmbed() - .setTitle("認証") - .setDescription(`❌ 30秒以内に回答しなかったため、認証に失敗しました`) - .setColor('RED'); - int.user.send({ embeds: [timeout_embed] }); - } - }); - } catch (e) { - console.error(e); - err_embed.setDescription(`❌ エラーが発生しました`).setColor('RED'); - await int.editReply({ embeds: [err_embed], ephemeral: true }); - } - } - } catch (error) { - console.error(error); - } -}); - -client.login(process.env.DISCORD_BOT_TOKEN); \ No newline at end of file diff --git a/bot/main.js b/bot/main.js deleted file mode 100644 index 3b28dab..0000000 --- a/bot/main.js +++ /dev/null @@ -1,84 +0,0 @@ -const { Client, Collection, MessageEmbed } = require("discord.js"); -const options = { intents: [3276799] }; -const client = new Client(options); -client.commands = new Collection(); -const fs = require("fs"); -const config = JSON.parse(fs.readFileSync("./config.json", 'utf8')); - -const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); - - -for (const file of commandFiles) { - const command = require(`./commands/${file}`); - client.commands.set(command.name, command); - console.log(`${file} ready!`) -} - -client.on("ready", () => { - console.log(`${client.user.tag} OK!`); -}); - -client.on('messageCreate', async message => { - let prefix = config.prefix; - const guildId = message.guild.id; - const settingsFilePath = `./settings/${guildId}.json`; - if (fs.existsSync(settingsFilePath)) { - const settings = JSON.parse(fs.readFileSync(settingsFilePath, 'utf8')); - if (settings?.prefix) { - prefix = settings.prefix; - } - if (!settings?.setting.disable) { - let isMuted; - try { - isMuted = settings.muted_users.includes(message.author.id); - } catch { - isMuted = false; - } - if (isMuted) { - await message.delete(); - return; - } - } - } - - if (!message.content.startsWith(prefix) || message.author.bot) return; - - const args = message.content.slice(prefix.length).trim().split(/ +/); - const commandName = args.shift().toLowerCase(); - - const command = client.commands.get(commandName) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName)); - - if (!command) return; - if (!message.guild.me.permissions.has("ADMINISTRATOR") && !(commandName === 'help' || commandName === 'h')) { - try { - message.channel.send('❌ Botには管理者権限が必要です'); - return; - } catch (e) { - console.error(e); - } - } - try { - command.execute(client, message, args, config); - } catch (error) { - message.channel.send({ embeds: [new MessageEmbed().setDescription('❌ 想定外のエラーが発生しました').setColor('RED')]}); - const errorChannel = message.guild.channels.cache.get(config.log_channel); - if (errorChannel) { - sendErrorToChannel(errorChannel, error); - } - } -}); - -async function sendErrorToChannel(channel, error) { - try { - const timestamp = new Date().toISOString(); - const fileName = `error_${timestamp}.txt`; - - fs.writeFileSync(fileName, error.stack, 'utf-8'); - await channel.send({ files: [{ attachment: fileName, name: fileName }] }); - fs.unlinkSync(fileName); - } catch (err) { - console.error(err); - } -} - -client.login(process.env.DISCORD_BOT_TOKEN); \ No newline at end of file diff --git a/bot/package.json b/bot/package.json deleted file mode 100644 index 33d4e26..0000000 --- a/bot/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "Discord-js-v13-modbot", - "version": "0.1.3", - "description": "It is modbot of Discord.js v13.", - "main": "server.js", - "scripts": { - "start": "node server.js" - }, - "dependencies": { - "discord.js": "^13.16.0", - "fs": "^0.0.2", - "discord-inviter": "^0.9.3", - "jimp": "^0.22.10" - }, - "engines": { - "node": "16.x" - }, - "keywords": [ - "node", - "glitch", - "template" - ] -} \ No newline at end of file diff --git a/bot/server.js b/bot/server.js deleted file mode 100644 index 7b6bd18..0000000 --- a/bot/server.js +++ /dev/null @@ -1,43 +0,0 @@ -const http = require("http"); -const querystring = require("node:querystring"); - -//GASでwakeさせること。 - -http - .createServer(function(req, res) { - if (req.method == "POST") { - var data = ""; - req.on("data", function(chunk) { - data += chunk; - }); - req.on("end", function() { - if (!data) { - res.end("No post data"); - return; - } - var dataObject = querystring.parse(data); - console.log("post: " + dataObject.type); - if (dataObject.type == "wake") { - console.log("Woke up in post"); - res.end(); - return; - } - res.end(); - }); - } else if (req.method == "GET") { - res.writeHead(200, { "Content-Type": "text/plain" }); - res.end("Discord Bot is Oprateing!"); - } - }) - .listen(3000); - -if (process.env.DISCORD_BOT_TOKEN == undefined || process.env.DISCORD_BOT_TOKEN == "") { - console.log("DISCORD_BOT_TOKENを設定してください。"); - process.exit(0); -} - -require("./main.js") -require("./botlog.js") - -require("./functions/automod.js") -require("./functions/interaction.js") diff --git a/bot/settings/GUILD_ID.json b/bot/settings/GUILD_ID.json deleted file mode 100644 index 5f64937..0000000 --- a/bot/settings/GUILD_ID.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "guild_name": "GUILD_ID's GUILD_NAME", - "prefix": null, - "mods": [], - "channel": { - "category": "GUILD_ID's LOG_CATEGORY_ID", - "log": "GUILD_ID's AUDIT_LOG_CHANNEL_ID", - "msglog": "GUILD_ID's MESSAGE_LOG_CHANNEL_ID", - "invite": "GUILD_ID's INVITE_LOG_CHANNEL_ID", - "nuke": [] - }, - "role": { - "muted": "GUILD_ID's MUTED_USERS_ROLE_ID", - "autos": [] - }, - "setting": { - "disable": false, - "antispam": true, - "antiinvite": true, - "antilink": false, - "antingwords": true, - "ticket_number": { - "category": null - }, - "timeout": { - "days": 0, - "hours": 0, - "minutes": 2, - "seconds": 0, - "antispam": true, - "antiinvite": true, - "antilink": false, - "antingwords": false - } - }, - "ignore_channels": [], - "ignore_roles": [], - "ignore_users": [], - "ngwords": [], - "muted_users": [] -}