From 4a4583e61724f68e9335eb76bc744343c2c2008e Mon Sep 17 00:00:00 2001 From: MotiCAT Date: Fri, 26 Jan 2024 16:38:59 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Added=20usage=20restri?= =?UTF-8?q?ctions=20to=20translation=20commands?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 27 ++++++++++++++++++++++++ package.json | 2 ++ src/embeds/index.ts | 4 ++++ src/interactions/context_en_translate.ts | 17 ++++++++++++++- src/interactions/context_ja_translate.ts | 17 +++++++++++++++ 5 files changed, 66 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 855e38b..68c88c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,11 +14,13 @@ "discord.js": "^14.12.1", "dotenv": "^16.3.2", "fs": "^0.0.1-security", + "node-cron": "^3.0.3", "node-os-utils": "^1.3.7", "os": "^0.1.2" }, "devDependencies": { "@trivago/prettier-plugin-sort-imports": "^4.3.0", + "@types/node-cron": "^3.0.11", "@types/node-os-utils": "^1.3.4", "@typescript-eslint/eslint-plugin": "^6.19.0", "@typescript-eslint/parser": "^6.19.0", @@ -738,6 +740,12 @@ "undici-types": "~5.26.4" } }, + "node_modules/@types/node-cron": { + "version": "3.0.11", + "resolved": "https://registry.npmjs.org/@types/node-cron/-/node-cron-3.0.11.tgz", + "integrity": "sha512-0ikrnug3/IyneSHqCBeslAhlK2aBfYek1fGo4bP4QnZPmiqSGRK+Oy7ZMisLWkesffJvQ1cqAcBnJC+8+nxIAg==", + "dev": true + }, "node_modules/@types/node-os-utils": { "version": "1.3.4", "resolved": "https://registry.npmjs.org/@types/node-os-utils/-/node-os-utils-1.3.4.tgz", @@ -2119,6 +2127,17 @@ "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", "dev": true }, + "node_modules/node-cron": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/node-cron/-/node-cron-3.0.3.tgz", + "integrity": "sha512-dOal67//nohNgYWb+nWmg5dkFdIwDm8EpeGYMekPMrngV3637lqnX0lbUcCtgibHTz6SEz7DAIjKvKDFYCnO1A==", + "dependencies": { + "uuid": "8.3.2" + }, + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/node-os-utils": { "version": "1.3.7", "resolved": "https://registry.npmjs.org/node-os-utils/-/node-os-utils-1.3.7.tgz", @@ -2613,6 +2632,14 @@ "punycode": "^2.1.0" } }, + "node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/v8-compile-cache-lib": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", diff --git a/package.json b/package.json index f44315b..6c0e8d4 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "license": "MIT", "devDependencies": { "@trivago/prettier-plugin-sort-imports": "^4.3.0", + "@types/node-cron": "^3.0.11", "@types/node-os-utils": "^1.3.4", "@typescript-eslint/eslint-plugin": "^6.19.0", "@typescript-eslint/parser": "^6.19.0", @@ -28,6 +29,7 @@ "discord.js": "^14.12.1", "dotenv": "^16.3.2", "fs": "^0.0.1-security", + "node-cron": "^3.0.3", "node-os-utils": "^1.3.7", "os": "^0.1.2" } diff --git a/src/embeds/index.ts b/src/embeds/index.ts index c1bf9ad..05573b1 100644 --- a/src/embeds/index.ts +++ b/src/embeds/index.ts @@ -283,6 +283,10 @@ export const embeds = { .setColor('#ff0000') .build(), translateError: new Builder().addFields({ name: 'Error', value: '翻訳に失敗しました。' }).setColor('#ff0000').build(), + translateLimit: new Builder() + .addFields({ name: 'Error', value: '一日に翻訳可能な文字数をオーバーしました。\n日付が変わってからお試しください。' }) + .setColor('#ff0000') + .build(), untimeoutHelp: new Builder() .setTitle('untimeoutコマンド') .setDescription('指定したユーザーのミュートを解除するコマンド') diff --git a/src/interactions/context_en_translate.ts b/src/interactions/context_en_translate.ts index 0a6b519..b51800a 100644 --- a/src/interactions/context_en_translate.ts +++ b/src/interactions/context_en_translate.ts @@ -1,9 +1,24 @@ import { embeds } from '../embeds'; import translate from 'deepl'; import { EmbedBuilder, MessageContextMenuCommandInteraction } from 'discord.js'; +import cron from 'node-cron'; +const userEnCounts = new Map(); +const maxCharsPerDay = 3000; + +cron.schedule('0 0 0 * * *', () => { + userEnCounts.clear(); +}); export async function en_translateCommand(interaction: MessageContextMenuCommandInteraction) { - if (!interaction.targetMessage.content) return interaction.reply(embeds.translateError); + if (!interaction.targetMessage.content) return interaction.reply(embeds.translateError); + const currentChars = userEnCounts.get(interaction.user.id) || 0; + const newChars = currentChars + interaction.targetMessage.content.length; + + if (newChars > maxCharsPerDay) { + return interaction.reply(embeds.translateLimit); + } + + userEnCounts.set(interaction.user.id, newChars); translate({ text: interaction.targetMessage.content, target_lang: 'EN', diff --git a/src/interactions/context_ja_translate.ts b/src/interactions/context_ja_translate.ts index 6691bb1..570795e 100644 --- a/src/interactions/context_ja_translate.ts +++ b/src/interactions/context_ja_translate.ts @@ -1,9 +1,26 @@ import { embeds } from '../embeds'; import translate from 'deepl'; import { EmbedBuilder, MessageContextMenuCommandInteraction } from 'discord.js'; +import cron from 'node-cron'; +const userJaCounts = new Map(); +const maxCharsPerDay = 3000; + +cron.schedule('0 0 0 * * *', () => { + userJaCounts.clear(); +}); export async function ja_translateCommand(interaction: MessageContextMenuCommandInteraction) { if (!interaction.targetMessage.content) return interaction.reply(embeds.translateError); + + const currentChars = userJaCounts.get(interaction.user.id) || 0; + const newChars = currentChars + interaction.targetMessage.content.length; + + if (newChars > maxCharsPerDay) { + return interaction.reply(embeds.translateLimit); + } + + userJaCounts.set(interaction.user.id, newChars); + translate({ text: interaction.targetMessage.content, target_lang: 'JA', From cdfc3db99b15cf5ed9fc5f42806605f57d0405b9 Mon Sep 17 00:00:00 2001 From: MotiCAT Date: Fri, 26 Jan 2024 23:57:54 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=94=A7=20Update=20printWidth=20in=20.?= =?UTF-8?q?prettierrc=20to=20150?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .prettierrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.prettierrc b/.prettierrc index 591c2ae..073b7b8 100644 --- a/.prettierrc +++ b/.prettierrc @@ -2,6 +2,6 @@ "useTabs": true, "singleQuote": true, "trailingComma": "none", - "printWidth": 120, + "printWidth": 150, "plugins": ["@trivago/prettier-plugin-sort-imports"] } From d870f97ecad5d34139983a4fe8fda71d8076367d Mon Sep 17 00:00:00 2001 From: MotiCAT Date: Sat, 27 Jan 2024 00:00:19 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=A7=B9format=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Events/onGuildRoleCreate.ts | 5 +- src/Events/onGuildRoleDelete.ts | 5 +- src/Events/onGuildRoleUpdate.ts | 5 +- src/Events/onMessageCreate.ts | 4 +- src/Events/onMessageDelete.ts | 4 +- src/Events/onMessageUpdate.ts | 12 +--- src/Events/onReady.ts | 6 +- src/commands/ban.ts | 6 +- src/commands/banlist.ts | 3 +- src/commands/clear.ts | 10 +-- src/commands/invite.ts | 6 +- src/commands/join.ts | 3 +- src/commands/kick.ts | 6 +- src/commands/leave.ts | 3 +- src/commands/log.ts | 3 +- src/commands/ping.ts | 5 +- src/commands/poll.ts | 4 +- src/commands/response.ts | 6 +- src/commands/role.ts | 9 +-- src/commands/server.ts | 4 +- src/commands/timeout.ts | 6 +- src/commands/untimeout.ts | 6 +- src/deploy-commands.ts | 39 +++------- src/embeds/index.ts | 92 ++++++------------------ src/index.ts | 20 +----- src/interactions/ban.ts | 3 +- src/interactions/banlist.ts | 3 +- src/interactions/clear.ts | 8 +-- src/interactions/context_en_translate.ts | 15 ++-- src/interactions/context_ja_translate.ts | 13 ++-- src/interactions/createticket.ts | 20 +----- src/interactions/inlist.ts | 3 +- src/interactions/invite.ts | 8 +-- src/interactions/kick.ts | 3 +- src/interactions/ping.ts | 5 +- src/interactions/response.ts | 3 +- src/interactions/server.ts | 4 +- 37 files changed, 92 insertions(+), 268 deletions(-) diff --git a/src/Events/onGuildRoleCreate.ts b/src/Events/onGuildRoleCreate.ts index d172bd1..2bc1450 100644 --- a/src/Events/onGuildRoleCreate.ts +++ b/src/Events/onGuildRoleCreate.ts @@ -14,10 +14,7 @@ export async function onGuildRoleCreate(role: Role) { const channel = role.guild.channels.cache.get(serverData.channelId); if (channel && channel.isTextBased()) { if (!role.guild?.members.me?.permissionsIn(channel).has(PermissionsBitField.Flags.SendMessages)) return; - const embed = new EmbedBuilder() - .setDescription(`新しいロール ${role} が作成されました`) - .setTimestamp() - .setColor('#0099ff'); + const embed = new EmbedBuilder().setDescription(`新しいロール ${role} が作成されました`).setTimestamp().setColor('#0099ff'); channel.send({ embeds: [embed] }); } } catch (error) { diff --git a/src/Events/onGuildRoleDelete.ts b/src/Events/onGuildRoleDelete.ts index c8b7ec0..099e9fe 100644 --- a/src/Events/onGuildRoleDelete.ts +++ b/src/Events/onGuildRoleDelete.ts @@ -14,10 +14,7 @@ export async function onGuildRoleDelete(role: Role) { const channel = role.guild.channels.cache.get(serverData.channelId); if (channel && channel.isTextBased()) { if (!role.guild.members.me?.permissionsIn(channel).has(PermissionsBitField.Flags.SendMessages)) return; - const embed = new EmbedBuilder() - .setDescription(`${role.name} ロールが削除されました`) - .setTimestamp() - .setColor('#0099ff'); + const embed = new EmbedBuilder().setDescription(`${role.name} ロールが削除されました`).setTimestamp().setColor('#0099ff'); channel.send({ embeds: [embed] }); } } catch (error) { diff --git a/src/Events/onGuildRoleUpdate.ts b/src/Events/onGuildRoleUpdate.ts index 3c3df77..5c2f637 100644 --- a/src/Events/onGuildRoleUpdate.ts +++ b/src/Events/onGuildRoleUpdate.ts @@ -11,10 +11,7 @@ export async function onGuildRoleUpdate(oldRole: Role, newRole: Role) { const serverData = data[serverId]; if (!serverData) return; try { - const embed = new EmbedBuilder() - .setTitle('ロールが更新されました') - .setDescription(`${newRole}`) - .setColor('#0099ff'); + const embed = new EmbedBuilder().setTitle('ロールが更新されました').setDescription(`${newRole}`).setColor('#0099ff'); const changes = []; if (oldRole.name !== newRole.name) { changes.push(`ロール名: ${oldRole.name} → ${newRole.name}`); diff --git a/src/Events/onMessageCreate.ts b/src/Events/onMessageCreate.ts index 86d7456..2d66a75 100644 --- a/src/Events/onMessageCreate.ts +++ b/src/Events/onMessageCreate.ts @@ -38,9 +38,7 @@ export async function onMessageCreate(message: Message): Promise if ( message.author.bot || message.guild?.members.me?.communicationDisabledUntil !== null || - !message.guild.members.me - .permissionsIn(message.channel as GuildTextBasedChannel) - .has(PermissionsBitField.Flags.SendMessages) || + !message.guild.members.me.permissionsIn(message.channel as GuildTextBasedChannel).has(PermissionsBitField.Flags.SendMessages) || bannedServers.includes(message.guild.id) ) return; diff --git a/src/Events/onMessageDelete.ts b/src/Events/onMessageDelete.ts index 881e191..26304aa 100644 --- a/src/Events/onMessageDelete.ts +++ b/src/Events/onMessageDelete.ts @@ -7,9 +7,7 @@ export async function onMessageDelete(message: Message | PartialMessage) { if (bannedUsers.includes((message.author as User).id) || bannedServers.includes((message.guild as Guild).id)) return; if ( !message.content || - !message.guild?.members.me - ?.permissionsIn(message.channel as GuildBasedChannel) - .has(PermissionsBitField.Flags.SendMessages) || + !message.guild?.members.me?.permissionsIn(message.channel as GuildBasedChannel).has(PermissionsBitField.Flags.SendMessages) || !message.guild ) return; diff --git a/src/Events/onMessageUpdate.ts b/src/Events/onMessageUpdate.ts index d149866..ea8938a 100644 --- a/src/Events/onMessageUpdate.ts +++ b/src/Events/onMessageUpdate.ts @@ -4,8 +4,7 @@ import { EmbedBuilder, Guild, Message, PartialMessage, PermissionsBitField, User import { readFileSync } from 'fs'; export const onMessageUpdate = async (oldMessage: Message | PartialMessage, newMessage: Message | PartialMessage) => { - if (bannedUsers.includes((newMessage.author as User).id) || bannedServers.includes((newMessage.guild as Guild).id)) - return; + if (bannedUsers.includes((newMessage.author as User).id) || bannedServers.includes((newMessage.guild as Guild).id)) return; if ((oldMessage.author as User).bot || oldMessage.content === newMessage.content || !oldMessage.guild) return; const serverId = oldMessage.guild.id; const rawData = readFileSync('./database/msglogs.json', 'utf-8'); @@ -17,13 +16,8 @@ export const onMessageUpdate = async (oldMessage: Message | PartialMessage, newM if (channel && channel.isTextBased()) { if (!oldMessage.guild?.members.me?.permissionsIn(channel).has(PermissionsBitField.Flags.SendMessages)) return; const embed = new EmbedBuilder() - .setDescription( - `${oldMessage.channel}で${oldMessage.author}がメッセージを編集しました。\n [メッセージへジャンプ](${newMessage.url})` - ) - .addFields( - { name: '変更前', value: oldMessage.content ?? 'なし' }, - { name: '変更後', value: newMessage.content ?? 'なし' } - ) + .setDescription(`${oldMessage.channel}で${oldMessage.author}がメッセージを編集しました。\n [メッセージへジャンプ](${newMessage.url})`) + .addFields({ name: '変更前', value: oldMessage.content ?? 'なし' }, { name: '変更後', value: newMessage.content ?? 'なし' }) .setColor('#0099ff') .setThumbnail((oldMessage.author as User).displayAvatarURL()) .setTimestamp(); diff --git a/src/Events/onReady.ts b/src/Events/onReady.ts index d1009db..5d23276 100644 --- a/src/Events/onReady.ts +++ b/src/Events/onReady.ts @@ -12,11 +12,7 @@ export function onReady(client: Client) { 'Discord.js': version, 'Node.js': process.version, Plattform: process.platform + ' | ' + process.arch, - Memory: - (process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2) + - 'MB | ' + - (process.memoryUsage().rss / 1024 / 1024).toFixed(2) + - 'MB' + Memory: (process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2) + 'MB | ' + (process.memoryUsage().rss / 1024 / 1024).toFixed(2) + 'MB' // Quote from: https://github.com/Nich87/Faith }); } diff --git a/src/commands/ban.ts b/src/commands/ban.ts index 3905e92..1189945 100644 --- a/src/commands/ban.ts +++ b/src/commands/ban.ts @@ -2,10 +2,8 @@ import { embeds } from '../embeds'; import { Message, PermissionsBitField } from 'discord.js'; export async function banCommand(message: Message) { - if (!message.member?.permissions.has(PermissionsBitField.Flags.BanMembers)) - return message.reply(embeds.PermissionError); - if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.BanMembers)) - return message.reply(embeds.banPermissionError); + if (!message.member?.permissions.has(PermissionsBitField.Flags.BanMembers)) return message.reply(embeds.PermissionError); + if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.BanMembers)) return message.reply(embeds.banPermissionError); const member = message.mentions.members?.first(); if (!member) return message.reply(embeds.banHelp); member diff --git a/src/commands/banlist.ts b/src/commands/banlist.ts index 380e7b5..7f3b313 100644 --- a/src/commands/banlist.ts +++ b/src/commands/banlist.ts @@ -2,8 +2,7 @@ import { embeds } from '../embeds'; import { Message, PermissionsBitField, EmbedBuilder } from 'discord.js'; export async function banlistCommand(message: Message) { - if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.BanMembers)) - return message.reply(embeds.banlistPermissionError); + if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.BanMembers)) return message.reply(embeds.banlistPermissionError); await message.guild.bans .fetch() .then((bans) => { diff --git a/src/commands/clear.ts b/src/commands/clear.ts index e25d013..a92fdb8 100644 --- a/src/commands/clear.ts +++ b/src/commands/clear.ts @@ -2,10 +2,8 @@ import { embeds } from '../embeds'; import { ChannelType, Message, PermissionsBitField } from 'discord.js'; export async function clearCommand(message: Message) { - if (!message.member?.permissions.has(PermissionsBitField.Flags.ManageMessages)) - return message.reply(embeds.PermissionError); - if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.ManageMessages)) - return message.reply(embeds.clearPermissionError); + if (!message.member?.permissions.has(PermissionsBitField.Flags.ManageMessages)) return message.reply(embeds.PermissionError); + if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.ManageMessages)) return message.reply(embeds.clearPermissionError); const member = message.mentions.users.first(); const amountString = message.content.split(' ')[2]; const amount = Number(amountString); @@ -21,9 +19,7 @@ export async function clearCommand(message: Message) { message.channel .bulkDelete(userMessages) .then(() => { - message.reply( - `メッセージ${userMessages.length}件を削除しました\n(指定した数より削除した数が少ない場合があるのはDiscord側の仕様です)` - ); + message.reply(`メッセージ${userMessages.length}件を削除しました\n(指定した数より削除した数が少ない場合があるのはDiscord側の仕様です)`); }) .catch(() => { message.reply('メッセージを削除できませんでした。'); diff --git a/src/commands/invite.ts b/src/commands/invite.ts index c0be430..5276eca 100644 --- a/src/commands/invite.ts +++ b/src/commands/invite.ts @@ -2,10 +2,8 @@ import { embeds } from '../embeds'; import { ChannelType, Message, PermissionsBitField } from 'discord.js'; export async function inviteCommand(message: Message) { - if (!message.member?.permissions.has(PermissionsBitField.Flags.CreateInstantInvite)) - return message.reply(embeds.PermissionError); - if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.CreateInstantInvite)) - return message.reply(embeds.invitePermissionError); + if (!message.member?.permissions.has(PermissionsBitField.Flags.CreateInstantInvite)) return message.reply(embeds.PermissionError); + if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.CreateInstantInvite)) return message.reply(embeds.invitePermissionError); if (message.channel.type !== ChannelType.GuildText) return; message.channel .createInvite() diff --git a/src/commands/join.ts b/src/commands/join.ts index 68f24a6..5d29dea 100644 --- a/src/commands/join.ts +++ b/src/commands/join.ts @@ -4,8 +4,7 @@ import { Message, Guild, TextBasedChannel, PermissionsBitField } from 'discord.j import { writeFile, readFileSync } from 'fs'; export async function joinCommand(message: Message) { - if (!message.member?.permissions.has(PermissionsBitField.Flags.Administrator)) - return message.reply(embeds.PermissionError); + if (!message.member?.permissions.has(PermissionsBitField.Flags.Administrator)) return message.reply(embeds.PermissionError); const args = message.content.split(' '); const subcommand = args[1] as string | undefined; switch (subcommand) { diff --git a/src/commands/kick.ts b/src/commands/kick.ts index 07ca4f2..9799203 100644 --- a/src/commands/kick.ts +++ b/src/commands/kick.ts @@ -2,10 +2,8 @@ import { embeds } from '../embeds'; import { PermissionsBitField, Message } from 'discord.js'; export async function kickCommand(message: Message) { - if (!message.member?.permissions.has(PermissionsBitField.Flags.KickMembers)) - return message.reply('コマンドを使用する権限がありません。'); - if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.KickMembers)) - return message.reply(embeds.kickPermissionError); + if (!message.member?.permissions.has(PermissionsBitField.Flags.KickMembers)) return message.reply('コマンドを使用する権限がありません。'); + if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.KickMembers)) return message.reply(embeds.kickPermissionError); const member = message.mentions.members?.first(); if (!member) return message.reply(embeds.kickHelp); member diff --git a/src/commands/leave.ts b/src/commands/leave.ts index efa7d54..d17068e 100644 --- a/src/commands/leave.ts +++ b/src/commands/leave.ts @@ -4,8 +4,7 @@ import { Message, Guild, TextBasedChannel, PermissionsBitField } from 'discord.j import { writeFile, readFileSync } from 'fs'; export async function leaveCommand(message: Message) { - if (!message.member?.permissions.has(PermissionsBitField.Flags.Administrator)) - return message.reply(embeds.PermissionError); + if (!message.member?.permissions.has(PermissionsBitField.Flags.Administrator)) return message.reply(embeds.PermissionError); const args = message.content.split(' '); const subcommand = args[1] as string | undefined; switch (subcommand) { diff --git a/src/commands/log.ts b/src/commands/log.ts index 4f9f8ba..1180bfd 100644 --- a/src/commands/log.ts +++ b/src/commands/log.ts @@ -4,8 +4,7 @@ import { Message, Guild, TextBasedChannel, PermissionsBitField } from 'discord.j import { writeFile, readFileSync } from 'fs'; export async function logCommand(message: Message) { - if (!message.member?.permissions.has(PermissionsBitField.Flags.ManageChannels)) - return message.reply(embeds.PermissionError); + if (!message.member?.permissions.has(PermissionsBitField.Flags.ManageChannels)) return message.reply(embeds.PermissionError); const args = message.content.split(' '); const subcommand = args[1]; switch (subcommand) { diff --git a/src/commands/ping.ts b/src/commands/ping.ts index 8f35a39..7ff1dfb 100644 --- a/src/commands/ping.ts +++ b/src/commands/ping.ts @@ -1,9 +1,6 @@ import { Message, EmbedBuilder } from 'discord.js'; export async function pingCommand(message: Message) { - const embed = new EmbedBuilder() - .setColor('#0099ff') - .setTitle('Pong!:ping_pong:') - .setDescription(`${message.client.ws.ping}ms`); + const embed = new EmbedBuilder().setColor('#0099ff').setTitle('Pong!:ping_pong:').setDescription(`${message.client.ws.ping}ms`); message.reply({ embeds: [embed] }); } diff --git a/src/commands/poll.ts b/src/commands/poll.ts index 6d86d69..e83ec8d 100644 --- a/src/commands/poll.ts +++ b/src/commands/poll.ts @@ -8,9 +8,7 @@ export async function pollCommand(message: Message) { const [title, ...options] = args.slice(1); if (!title || options.length === 0) return message.reply(embeds.pollHelp); if (options.length > 10) return message.reply('選択肢は10個までです。'); - const embed = new EmbedBuilder() - .setTitle(title) - .setDescription(options.map((option, index) => `${reactions[index]} ${option}`).join('\n')); + const embed = new EmbedBuilder().setTitle(title).setDescription(options.map((option, index) => `${reactions[index]} ${option}`).join('\n')); const pollMessage = await message.reply({ embeds: [embed] }); options.forEach(async (_, index) => { diff --git a/src/commands/response.ts b/src/commands/response.ts index a813fc7..ce4e044 100644 --- a/src/commands/response.ts +++ b/src/commands/response.ts @@ -4,8 +4,7 @@ import { Guild, Message, PermissionsBitField } from 'discord.js'; import { writeFile, readFileSync } from 'fs'; export async function responseCommand(message: Message) { - if (!message.member?.permissions.has(PermissionsBitField.Flags.ManageMessages)) - return message.reply(embeds.PermissionError); + if (!message.member?.permissions.has(PermissionsBitField.Flags.ManageMessages)) return message.reply(embeds.PermissionError); const args = message.content.split(' '); const subcommand = args[1] as string | undefined; switch (subcommand) { @@ -42,8 +41,7 @@ export async function responseCommand(message: Message) { const data: Record = JSON.parse(rawData); const serverData = data[serverId]; if (!keyword) return message.reply(embeds.responseRemoveHelp); - if (!serverData || !serverData[keyword]) - return message.reply(`キーワード 「${keyword}」 のレスポンスは登録されていません。`); + if (!serverData || !serverData[keyword]) return message.reply(`キーワード 「${keyword}」 のレスポンスは登録されていません。`); delete serverData[keyword]; writeFile('./database/responses.json', JSON.stringify(data, null, 2), (err) => { diff --git a/src/commands/role.ts b/src/commands/role.ts index a86235e..75bfa62 100644 --- a/src/commands/role.ts +++ b/src/commands/role.ts @@ -2,14 +2,12 @@ import { embeds } from '../embeds'; import { Message, PermissionsBitField } from 'discord.js'; export async function roleCommand(message: Message) { - if (!message.member?.permissions.has(PermissionsBitField.Flags.ManageRoles)) - return message.reply(embeds.PermissionError); + if (!message.member?.permissions.has(PermissionsBitField.Flags.ManageRoles)) return message.reply(embeds.PermissionError); const subcommand = message.content.split(' ')[1]; switch (subcommand) { case 'add': { - if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.ManageRoles)) - return message.reply(embeds.roleAddPermissionError); + if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.ManageRoles)) return message.reply(embeds.roleAddPermissionError); const role = message.mentions.roles.first(); const member = message.mentions.members?.first(); if (!role || !member) return message.reply(embeds.roleAddHelp); @@ -25,8 +23,7 @@ export async function roleCommand(message: Message) { break; case 'remove': { - if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.ManageRoles)) - return message.reply(embeds.remrolePermissionError); + if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.ManageRoles)) return message.reply(embeds.remrolePermissionError); const role = message.mentions.roles.first(); const member = message.mentions.members?.first(); if (!role || !member) return message.reply(embeds.remroleHelp); diff --git a/src/commands/server.ts b/src/commands/server.ts index e0d5d33..37925e9 100644 --- a/src/commands/server.ts +++ b/src/commands/server.ts @@ -15,9 +15,7 @@ export async function serverCommand(message: Message) { guild.channels.cache.filter((c) => c.type === ChannelType.GuildText).size }\nボイスチャンネル数: ${ guild.channels.cache.filter((c) => c.type === ChannelType.GuildVoice).size - }\nカテゴリー数: ${guild.channels.cache.filter((c) => c.type === ChannelType.GuildCategory).size}\n絵文字数: ${ - guild.emojis.cache.size - }` + }\nカテゴリー数: ${guild.channels.cache.filter((c) => c.type === ChannelType.GuildCategory).size}\n絵文字数: ${guild.emojis.cache.size}` } ) .setThumbnail(guild.iconURL()); diff --git a/src/commands/timeout.ts b/src/commands/timeout.ts index 9009d5b..8ed9258 100644 --- a/src/commands/timeout.ts +++ b/src/commands/timeout.ts @@ -2,10 +2,8 @@ import { embeds } from '../embeds'; import { Message, PermissionsBitField } from 'discord.js'; export async function timeoutCommand(message: Message) { - if (!message.member?.permissions.has(PermissionsBitField.Flags.ModerateMembers)) - return message.reply(embeds.PermissionError); - if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.ModerateMembers)) - return message.reply(embeds.timeoutPermissionError); + if (!message.member?.permissions.has(PermissionsBitField.Flags.ModerateMembers)) return message.reply(embeds.PermissionError); + if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.ModerateMembers)) return message.reply(embeds.timeoutPermissionError); const args = message.content.split(' '); const member = message.mentions.members?.first(); const time = parseInt(args[2]); diff --git a/src/commands/untimeout.ts b/src/commands/untimeout.ts index bb5c2ab..312c763 100644 --- a/src/commands/untimeout.ts +++ b/src/commands/untimeout.ts @@ -2,10 +2,8 @@ import { embeds } from '../embeds'; import { PermissionsBitField, Message } from 'discord.js'; export async function untimeoutCommand(message: Message) { - if (!message.member?.permissions.has(PermissionsBitField.Flags.ModerateMembers)) - return message.reply('このコマンドを使用する権限がありません'); - if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.ModerateMembers)) - return message.reply(embeds.timeoutPermissionError); + if (!message.member?.permissions.has(PermissionsBitField.Flags.ModerateMembers)) return message.reply('このコマンドを使用する権限がありません'); + if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.ModerateMembers)) return message.reply(embeds.timeoutPermissionError); const member = message.mentions.members?.first(); if (!member) return message.reply(embeds.untimeoutHelp); if (member.communicationDisabledUntil !== null) { diff --git a/src/deploy-commands.ts b/src/deploy-commands.ts index 50dbd36..dcb9876 100644 --- a/src/deploy-commands.ts +++ b/src/deploy-commands.ts @@ -1,11 +1,4 @@ -import { - ContextMenuCommandBuilder, - PermissionsBitField, - REST, - Routes, - SlashCommandBuilder, - ApplicationCommandType -} from 'discord.js'; +import { ContextMenuCommandBuilder, PermissionsBitField, REST, Routes, SlashCommandBuilder, ApplicationCommandType } from 'discord.js'; import { config } from 'dotenv'; config(); @@ -29,9 +22,7 @@ const commands = [ new SlashCommandBuilder() .setName('clear') .setDescription('指定したメンバーのメッセージを削除します') - .addUserOption((option) => - option.setName('member').setDescription('メッセージを削除するメンバー').setRequired(true) - ) + .addUserOption((option) => option.setName('member').setDescription('メッセージを削除するメンバー').setRequired(true)) .addIntegerOption((option) => option.setName('amount').setDescription('削除するメッセージの数').setRequired(true)) .setDefaultMemberPermissions(PermissionsBitField.Flags.ManageMessages), new SlashCommandBuilder() @@ -70,11 +61,7 @@ const commands = [ option .setName('type') .setDescription('削除するログの種類') - .addChoices( - { name: 'member', value: 'member' }, - { name: 'message', value: 'message' }, - { name: 'role', value: 'role' } - ) + .addChoices({ name: 'member', value: 'member' }, { name: 'message', value: 'message' }, { name: 'role', value: 'role' }) .setRequired(true) ) ) @@ -108,18 +95,14 @@ const commands = [ subcommand .setName('add') .setDescription('レスポンスを追加します') - .addStringOption((option) => - option.setName('keyword').setDescription('レスポンスのキーワード').setRequired(true) - ) + .addStringOption((option) => option.setName('keyword').setDescription('レスポンスのキーワード').setRequired(true)) .addStringOption((option) => option.setName('response').setDescription('レスポンス').setRequired(true)) ) .addSubcommand((subcommand) => subcommand .setName('remove') .setDescription('レスポンスを削除します') - .addStringOption((option) => - option.setName('keyword').setDescription('レスポンスのキーワード').setRequired(true) - ) + .addStringOption((option) => option.setName('keyword').setDescription('レスポンスのキーワード').setRequired(true)) ) .addSubcommand((subcommand) => subcommand.setName('list').setDescription('レスポンスの一覧を表示します')) .setDefaultMemberPermissions(PermissionsBitField.Flags.ManageMessages), @@ -131,18 +114,14 @@ const commands = [ .setName('add') .setDescription('ロールを追加します') .addRoleOption((option) => option.setName('role').setDescription('追加するロール').setRequired(true)) - .addUserOption((option) => - option.setName('member').setDescription('ロールを追加するメンバー').setRequired(true) - ) + .addUserOption((option) => option.setName('member').setDescription('ロールを追加するメンバー').setRequired(true)) ) .addSubcommand((subcommand) => subcommand .setName('remove') .setDescription('ロールを削除します') .addRoleOption((option) => option.setName('role').setDescription('削除するロール').setRequired(true)) - .addUserOption((option) => - option.setName('member').setDescription('ロールを削除するメンバー').setRequired(true) - ) + .addUserOption((option) => option.setName('member').setDescription('ロールを削除するメンバー').setRequired(true)) ) .setDefaultMemberPermissions(PermissionsBitField.Flags.ManageRoles), new SlashCommandBuilder() @@ -160,9 +139,7 @@ const commands = [ new SlashCommandBuilder() .setName('untimeout') .setDescription('タイムアウトを解除します') - .addUserOption((option) => - option.setName('member').setDescription('タイムアウトを解除するメンバー').setRequired(true) - ) + .addUserOption((option) => option.setName('member').setDescription('タイムアウトを解除するメンバー').setRequired(true)) .setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers), new SlashCommandBuilder() .setName('user') diff --git a/src/embeds/index.ts b/src/embeds/index.ts index 05573b1..dff3da7 100644 --- a/src/embeds/index.ts +++ b/src/embeds/index.ts @@ -40,8 +40,7 @@ export const embeds = { }, { name: ':arrow_up:botの歴史', - value: - '```diff\n+ 2023/05/21 認証\n+ 2023/02/21 v1.0 Release\n- 2023/02/10 暴走\n+ 2022/05/15 Botアカウントの作成\n```' + value: '```diff\n+ 2023/05/21 認証\n+ 2023/02/21 v1.0 Release\n- 2023/02/10 暴走\n+ 2022/05/15 Botアカウントの作成\n```' }, { name: ':link:関連リンク', @@ -73,10 +72,7 @@ export const embeds = { .addFields({ name: '使い方', value: 'mc!role add @ユーザー @ロール' }) .setFooter({ text: 'Motcher v2.0' }) .build(), - roleAddSuccess: new Builder() - .addFields({ name: 'Success', value: 'ロールを付与しました。' }) - .setColor('#0099ff') - .build(), + roleAddSuccess: new Builder().addFields({ name: 'Success', value: 'ロールを付与しました。' }).setColor('#0099ff').build(), banHelp: new Builder() .setTitle('banコマンド') .setDescription('指定したメンバーをbanするコマンド') @@ -91,22 +87,15 @@ export const embeds = { }) .setColor('#ff0000') .build(), - banSuccess: new Builder() - .addFields({ name: 'Success', value: '指定したメンバーをbanしました。' }) - .setColor('#0099ff') - .build(), + banSuccess: new Builder().addFields({ name: 'Success', value: '指定したメンバーをbanしました。' }).setColor('#0099ff').build(), banError: new Builder() .addFields({ name: 'Error', - value: - '指定したメンバーをbanできませんでした。\n(自分より順位の高いユーザー、同順位のユーザーの操作ができないDiscordの仕様です。)' + value: '指定したメンバーをbanできませんでした。\n(自分より順位の高いユーザー、同順位のユーザーの操作ができないDiscordの仕様です。)' }) .setColor('#ff0000') .build(), - banlistError: new Builder() - .addFields({ name: 'Error', value: 'Banされたユーザーを取得できませんでした。' }) - .setColor('#ff0000') - .build(), + banlistError: new Builder().addFields({ name: 'Error', value: 'Banされたユーザーを取得できませんでした。' }).setColor('#ff0000').build(), banlistPermissionError: new Builder() .addFields({ name: '権限不足', @@ -114,10 +103,7 @@ export const embeds = { }) .setColor('#ff0000') .build(), - bannerInfo: new Builder() - .addFields({ name: 'Info', value: '指定したユーザーのバナーが設定されていませんでした。' }) - .setColor('#0099ff') - .build(), + bannerInfo: new Builder().addFields({ name: 'Info', value: '指定したユーザーのバナーが設定されていませんでした。' }).setColor('#0099ff').build(), clearHelp: new Builder() .setTitle('clearコマンド') .setDescription('指定したユーザーのメッセージをまとめて削除するコマンド') @@ -132,14 +118,8 @@ export const embeds = { }) .setColor('#ff0000') .build(), - clearSuccess: new Builder() - .addFields({ name: 'Success', value: '指定したユーザーのメッセージを削除しました。' }) - .setColor('#0099ff') - .build(), - clearError: new Builder() - .addFields({ name: 'Error', value: '指定したユーザーのメッセージを削除できませんでした。' }) - .setColor('#ff0000') - .build(), + clearSuccess: new Builder().addFields({ name: 'Success', value: '指定したユーザーのメッセージを削除しました。' }).setColor('#0099ff').build(), + clearError: new Builder().addFields({ name: 'Error', value: '指定したユーザーのメッセージを削除できませんでした。' }).setColor('#ff0000').build(), invitePermissionError: new Builder() .addFields({ name: '権限不足', @@ -147,10 +127,7 @@ export const embeds = { }) .setColor('#ff0000') .build(), - inviteError: new Builder() - .addFields({ name: 'Error', value: '招待リンクの作成に失敗しました。' }) - .setColor('#ff0000') - .build(), + inviteError: new Builder().addFields({ name: 'Error', value: '招待リンクの作成に失敗しました。' }).setColor('#ff0000').build(), kickHelp: new Builder() .setTitle('kickコマンド') .setDescription('特定のユーザーをキックするコマンド') @@ -168,15 +145,11 @@ export const embeds = { kickError: new Builder() .addFields({ name: 'Error', - value: - '指定したユーザーをkickできませんでした。\n(自分より順位の高いユーザー、同順位のユーザーの操作ができないDiscordの仕様です。)' + value: '指定したユーザーをkickできませんでした。\n(自分より順位の高いユーザー、同順位のユーザーの操作ができないDiscordの仕様です。)' }) .setColor('#ff0000') .build(), - kickSuccess: new Builder() - .addFields({ name: 'Success', value: '指定したユーザーをkickしました。' }) - .setColor('#0099ff') - .build(), + kickSuccess: new Builder().addFields({ name: 'Success', value: '指定したユーザーをkickしました。' }).setColor('#0099ff').build(), mcskinHelp: new Builder() .setTitle('mcskinコマンド') .setDescription('指定したユーザーのマイクラスキンを取得するコマンド') @@ -240,15 +213,11 @@ export const embeds = { }) .setColor('#ff0000') .build(), - remroleSuccess: new Builder() - .addFields({ name: 'Success', value: 'ロールを剥奪しました。' }) - .setColor('#0099ff') - .build(), + remroleSuccess: new Builder().addFields({ name: 'Success', value: 'ロールを剥奪しました。' }).setColor('#0099ff').build(), remroleError: new Builder() .addFields({ name: 'エラー', - value: - '指定されたロールを剥奪できませんでした。\n(自分についているものより順位の高いロール、同順位のロールを操作できないDiscordの仕様です。)' + value: '指定されたロールを剥奪できませんでした。\n(自分についているものより順位の高いロール、同順位のロールを操作できないDiscordの仕様です。)' }) .setColor('#ff0000') .build(), @@ -274,14 +243,8 @@ export const embeds = { .addFields({ name: '使い方', value: 'mc!timeout @ユーザー 分数' }) .setFooter({ text: 'Motcher v2.0' }) .build(), - timeoutSuccess: new Builder() - .addFields({ name: 'Success', value: '指定したユーザーをミュートしました。' }) - .setColor('#0099ff') - .build(), - timeoutError: new Builder() - .addFields({ name: 'Error', value: '指定したユーザーをミュートできませんでした。' }) - .setColor('#ff0000') - .build(), + timeoutSuccess: new Builder().addFields({ name: 'Success', value: '指定したユーザーをミュートしました。' }).setColor('#0099ff').build(), + timeoutError: new Builder().addFields({ name: 'Error', value: '指定したユーザーをミュートできませんでした。' }).setColor('#ff0000').build(), translateError: new Builder().addFields({ name: 'Error', value: '翻訳に失敗しました。' }).setColor('#ff0000').build(), translateLimit: new Builder() .addFields({ name: 'Error', value: '一日に翻訳可能な文字数をオーバーしました。\n日付が変わってからお試しください。' }) @@ -294,24 +257,12 @@ export const embeds = { .addFields({ name: '使い方', value: 'mc!untimeout @ユーザー' }) .setFooter({ text: 'Motcher v2.0' }) .build(), - untimeoutSuccess: new Builder() - .addFields({ name: 'Success', value: '指定したユーザーのミュートを解除しました。' }) - .setColor('#0099ff') - .build(), - untimeoutError: new Builder() - .addFields({ name: 'Error', value: '指定したユーザーのミュートを解除できませんでした。' }) - .setColor('#ff0000') - .build(), - untimeoutNo: new Builder() - .addFields({ name: 'Error', value: '指定したユーザーはミュートされていません。' }) - .setColor('#ff0000') - .build(), + untimeoutSuccess: new Builder().addFields({ name: 'Success', value: '指定したユーザーのミュートを解除しました。' }).setColor('#0099ff').build(), + untimeoutError: new Builder().addFields({ name: 'Error', value: '指定したユーザーのミュートを解除できませんでした。' }).setColor('#ff0000').build(), + untimeoutNo: new Builder().addFields({ name: 'Error', value: '指定したユーザーはミュートされていません。' }).setColor('#ff0000').build(), defaultError: new Builder().addFields({ name: 'Error', value: 'エラーが発生しました。' }).setColor('#ff0000').build(), saveSuccess: new Builder().addFields({ name: 'Success', value: '保存しました。' }).setColor('#0099ff').build(), - deleteSuccess: new Builder() - .addFields({ name: 'Success', value: '設定を削除しました。' }) - .setColor('#0099ff') - .build(), + deleteSuccess: new Builder().addFields({ name: 'Success', value: '設定を削除しました。' }).setColor('#0099ff').build(), joinHelp: new Builder() .setTitle('joinコマンド') .setDescription('参加時のメッセージを設定するコマンド') @@ -385,10 +336,7 @@ export const embeds = { }) .setFooter({ text: 'Motcher v2.0' }) .build(), - resnowEmpty: new Builder() - .addFields({ name: 'Error', value: 'まだレスポンスが登録されていません。' }) - .setColor('#ff0000') - .build(), + resnowEmpty: new Builder().addFields({ name: 'Error', value: 'まだレスポンスが登録されていません。' }).setColor('#ff0000').build(), PermissionError: new Builder() .addFields({ name: 'Error', diff --git a/src/index.ts b/src/index.ts index 61748b4..cfbf8e4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,15 +1,5 @@ import { events } from './Events'; -import { - BaseInteraction, - Client, - GatewayIntentBits, - GuildMember, - Message, - PartialGuildMember, - PartialMessage, - Partials, - Role -} from 'discord.js'; +import { BaseInteraction, Client, GatewayIntentBits, GuildMember, Message, PartialGuildMember, PartialMessage, Partials, Role } from 'discord.js'; import { config } from 'dotenv'; config(); @@ -36,15 +26,11 @@ const client = new Client({ client .on('ready', () => events.onReady(client)) .on('messageCreate', async (message: Message) => events.onMessageCreate(message)) - .on('messageUpdate', async (oldMessage: Message | PartialMessage, newMessage: Message | PartialMessage) => - events.onMessageUpdate(oldMessage, newMessage) - ) + .on('messageUpdate', async (oldMessage: Message | PartialMessage, newMessage: Message | PartialMessage) => events.onMessageUpdate(oldMessage, newMessage)) .on('messageDelete', async (message: Message | PartialMessage) => events.onMessageDelete(message)) .on('guildMemberAdd', async (member: GuildMember) => events.onGuildMemberAdd(member)) .on('guildMemberRemove', async (member: GuildMember | PartialGuildMember) => events.onGuildMemberRemove(member)) - .on('guildMemberUpdate', async (oldMember: GuildMember | PartialGuildMember, newMember: GuildMember) => - events.onGuildMemberUpdate(oldMember, newMember) - ) + .on('guildMemberUpdate', async (oldMember: GuildMember | PartialGuildMember, newMember: GuildMember) => events.onGuildMemberUpdate(oldMember, newMember)) .on('guildRoleCreate', async (role: Role) => events.onGuildRoleCreate(role)) .on('guildRoleUpdate', async (oldRole: Role, newRole: Role) => events.onGuildRoleUpdate(oldRole, newRole)) .on('guildRoleDelete', async (role: Role) => events.onGuildRoleDelete(role)) diff --git a/src/interactions/ban.ts b/src/interactions/ban.ts index 0ef24ba..db2b2a0 100644 --- a/src/interactions/ban.ts +++ b/src/interactions/ban.ts @@ -3,8 +3,7 @@ import { ChatInputCommandInteraction, GuildMember, PermissionsBitField } from 'd export async function banCommand(interaction: ChatInputCommandInteraction) { if (!(interaction.member instanceof GuildMember)) return; - if (!interaction.guild?.members.me?.permissions.has(PermissionsBitField.Flags.BanMembers)) - return interaction.reply(embeds.banPermissionError); + if (!interaction.guild?.members.me?.permissions.has(PermissionsBitField.Flags.BanMembers)) return interaction.reply(embeds.banPermissionError); const member = interaction.options.getMember('member') as GuildMember; if (!member) return interaction.reply(embeds.banHelp); member diff --git a/src/interactions/banlist.ts b/src/interactions/banlist.ts index 9fa6204..5aea976 100644 --- a/src/interactions/banlist.ts +++ b/src/interactions/banlist.ts @@ -2,8 +2,7 @@ import { embeds } from '../embeds'; import { ChatInputCommandInteraction, PermissionsBitField, EmbedBuilder } from 'discord.js'; export async function banlistCommand(interaction: ChatInputCommandInteraction) { - if (!interaction.guild?.members.me?.permissions.has(PermissionsBitField.Flags.BanMembers)) - return interaction.reply(embeds.banlistPermissionError); + if (!interaction.guild?.members.me?.permissions.has(PermissionsBitField.Flags.BanMembers)) return interaction.reply(embeds.banlistPermissionError); await interaction.guild.bans .fetch() .then((bans) => { diff --git a/src/interactions/clear.ts b/src/interactions/clear.ts index 7a53487..f303e6d 100644 --- a/src/interactions/clear.ts +++ b/src/interactions/clear.ts @@ -1,11 +1,5 @@ import { embeds } from '../embeds'; -import { - ChannelType, - ChatInputCommandInteraction, - GuildMember, - PermissionsBitField, - TextBasedChannel -} from 'discord.js'; +import { ChannelType, ChatInputCommandInteraction, GuildMember, PermissionsBitField, TextBasedChannel } from 'discord.js'; export async function clearCommand(interaction: ChatInputCommandInteraction) { if (!(interaction.member instanceof GuildMember)) return; diff --git a/src/interactions/context_en_translate.ts b/src/interactions/context_en_translate.ts index b51800a..d8c42b8 100644 --- a/src/interactions/context_en_translate.ts +++ b/src/interactions/context_en_translate.ts @@ -2,6 +2,7 @@ import { embeds } from '../embeds'; import translate from 'deepl'; import { EmbedBuilder, MessageContextMenuCommandInteraction } from 'discord.js'; import cron from 'node-cron'; + const userEnCounts = new Map(); const maxCharsPerDay = 3000; @@ -10,15 +11,15 @@ cron.schedule('0 0 0 * * *', () => { }); export async function en_translateCommand(interaction: MessageContextMenuCommandInteraction) { - if (!interaction.targetMessage.content) return interaction.reply(embeds.translateError); - const currentChars = userEnCounts.get(interaction.user.id) || 0; - const newChars = currentChars + interaction.targetMessage.content.length; + if (!interaction.targetMessage.content) return interaction.reply(embeds.translateError); + const currentChars = userEnCounts.get(interaction.user.id) || 0; + const newChars = currentChars + interaction.targetMessage.content.length; - if (newChars > maxCharsPerDay) { - return interaction.reply(embeds.translateLimit); - } + if (newChars > maxCharsPerDay) { + return interaction.reply(embeds.translateLimit); + } - userEnCounts.set(interaction.user.id, newChars); + userEnCounts.set(interaction.user.id, newChars); translate({ text: interaction.targetMessage.content, target_lang: 'EN', diff --git a/src/interactions/context_ja_translate.ts b/src/interactions/context_ja_translate.ts index 570795e..b98813e 100644 --- a/src/interactions/context_ja_translate.ts +++ b/src/interactions/context_ja_translate.ts @@ -2,6 +2,7 @@ import { embeds } from '../embeds'; import translate from 'deepl'; import { EmbedBuilder, MessageContextMenuCommandInteraction } from 'discord.js'; import cron from 'node-cron'; + const userJaCounts = new Map(); const maxCharsPerDay = 3000; @@ -12,14 +13,14 @@ cron.schedule('0 0 0 * * *', () => { export async function ja_translateCommand(interaction: MessageContextMenuCommandInteraction) { if (!interaction.targetMessage.content) return interaction.reply(embeds.translateError); - const currentChars = userJaCounts.get(interaction.user.id) || 0; - const newChars = currentChars + interaction.targetMessage.content.length; + const currentChars = userJaCounts.get(interaction.user.id) || 0; + const newChars = currentChars + interaction.targetMessage.content.length; - if (newChars > maxCharsPerDay) { - return interaction.reply(embeds.translateLimit); - } + if (newChars > maxCharsPerDay) { + return interaction.reply(embeds.translateLimit); + } - userJaCounts.set(interaction.user.id, newChars); + userJaCounts.set(interaction.user.id, newChars); translate({ text: interaction.targetMessage.content, diff --git a/src/interactions/createticket.ts b/src/interactions/createticket.ts index 3b1dae8..5704ff6 100644 --- a/src/interactions/createticket.ts +++ b/src/interactions/createticket.ts @@ -1,13 +1,4 @@ -import { - ButtonInteraction, - PermissionsBitField, - Guild, - ChannelType, - ActionRowBuilder, - ButtonBuilder, - ButtonStyle, - TextChannel -} from 'discord.js'; +import { ButtonInteraction, PermissionsBitField, Guild, ChannelType, ActionRowBuilder, ButtonBuilder, ButtonStyle, TextChannel } from 'discord.js'; export async function createticketCommand(interaction: ButtonInteraction) { if (!interaction.guild?.members.me?.permissions.has(PermissionsBitField.Flags.ManageChannels)) @@ -17,9 +8,7 @@ export async function createticketCommand(interaction: ButtonInteraction) { }); const guild = interaction.guild as Guild; const existingChannels = guild.channels.cache.filter( - (c) => - c.type === ChannelType.GuildText && - c.name === `ticket-${interaction.user.username.replace('#', '').toLowerCase()}` + (c) => c.type === ChannelType.GuildText && c.name === `ticket-${interaction.user.username.replace('#', '').toLowerCase()}` ); if (existingChannels.size > 0) { return interaction.reply({ @@ -48,10 +37,7 @@ export async function createticketCommand(interaction: ButtonInteraction) { } ] }); - const Closeticket = new ButtonBuilder() - .setCustomId('closeticket') - .setLabel('Close Ticket') - .setStyle(ButtonStyle.Danger); + const Closeticket = new ButtonBuilder().setCustomId('closeticket').setLabel('Close Ticket').setStyle(ButtonStyle.Danger); const row = new ActionRowBuilder().addComponents(Closeticket); await createdChannel.send({ content: `${interaction.user}さん、チケットへようこそ!\nこのチケットを閉じるときは下のボタンを押してください。`, diff --git a/src/interactions/inlist.ts b/src/interactions/inlist.ts index 8acbebd..5b5ecee 100644 --- a/src/interactions/inlist.ts +++ b/src/interactions/inlist.ts @@ -2,8 +2,7 @@ import { ChatInputCommandInteraction } from 'discord.js'; import { writeFileSync } from 'fs'; export async function inlistCommand(interaction: ChatInputCommandInteraction) { - if (interaction.user.id !== process.env.OWNER_ID) - return interaction.reply({ content: 'このコマンドは開発者のみ使用できます。', ephemeral: true }); + if (interaction.user.id !== process.env.OWNER_ID) return interaction.reply({ content: 'このコマンドは開発者のみ使用できます。', ephemeral: true }); const guildList = [] as string[]; interaction.client.guilds.cache.forEach((guild) => { guildList.push(`${guild.name} : ${guild.id}`); diff --git a/src/interactions/invite.ts b/src/interactions/invite.ts index 17909be..ec93f99 100644 --- a/src/interactions/invite.ts +++ b/src/interactions/invite.ts @@ -1,11 +1,5 @@ import { embeds } from '../embeds'; -import { - ChannelType, - ChatInputCommandInteraction, - GuildMember, - PermissionsBitField, - TextBasedChannel -} from 'discord.js'; +import { ChannelType, ChatInputCommandInteraction, GuildMember, PermissionsBitField, TextBasedChannel } from 'discord.js'; export async function inviteCommand(interaction: ChatInputCommandInteraction) { if (!(interaction.member instanceof GuildMember)) return; diff --git a/src/interactions/kick.ts b/src/interactions/kick.ts index ab82a0c..02c66b0 100644 --- a/src/interactions/kick.ts +++ b/src/interactions/kick.ts @@ -3,8 +3,7 @@ import { PermissionsBitField, ChatInputCommandInteraction, GuildMember } from 'd export async function kickCommand(interaction: ChatInputCommandInteraction) { if (!(interaction.member instanceof GuildMember)) return; - if (!interaction.guild?.members.me?.permissions.has(PermissionsBitField.Flags.KickMembers)) - return interaction.reply(embeds.kickPermissionError); + if (!interaction.guild?.members.me?.permissions.has(PermissionsBitField.Flags.KickMembers)) return interaction.reply(embeds.kickPermissionError); const member = interaction.options.getMember('member') as GuildMember; if (!member) return interaction.reply(embeds.kickHelp); member diff --git a/src/interactions/ping.ts b/src/interactions/ping.ts index b264cad..206ea1d 100644 --- a/src/interactions/ping.ts +++ b/src/interactions/ping.ts @@ -1,9 +1,6 @@ import { ChatInputCommandInteraction, EmbedBuilder } from 'discord.js'; export async function pingCommand(interaction: ChatInputCommandInteraction) { - const embed = new EmbedBuilder() - .setColor('#0099ff') - .setTitle('Pong!:ping_pong:') - .setDescription(`${interaction.client.ws.ping}ms`); + const embed = new EmbedBuilder().setColor('#0099ff').setTitle('Pong!:ping_pong:').setDescription(`${interaction.client.ws.ping}ms`); interaction.reply({ embeds: [embed] }); } diff --git a/src/interactions/response.ts b/src/interactions/response.ts index 639e30b..6862e75 100644 --- a/src/interactions/response.ts +++ b/src/interactions/response.ts @@ -38,8 +38,7 @@ export async function responseCommand(interaction: ChatInputCommandInteraction) const rawData = readFileSync('./database/responses.json', 'utf-8'); const data: Record = JSON.parse(rawData); const serverData = data[serverId]; - if (!serverData || !serverData[keyword]) - return interaction.reply(`キーワード 「${keyword}」 のレスポンスは登録されていません。`); + if (!serverData || !serverData[keyword]) return interaction.reply(`キーワード 「${keyword}」 のレスポンスは登録されていません。`); delete serverData[keyword]; writeFile('./database/responses.json', JSON.stringify(data, null, 2), (err) => { diff --git a/src/interactions/server.ts b/src/interactions/server.ts index 2e1c3a8..c60eb10 100644 --- a/src/interactions/server.ts +++ b/src/interactions/server.ts @@ -15,9 +15,7 @@ export async function serverCommand(interaction: ChatInputCommandInteraction) { guild.channels.cache.filter((c) => c.type === ChannelType.GuildText).size }\nボイスチャンネル数: ${ guild.channels.cache.filter((c) => c.type === ChannelType.GuildVoice).size - }\nカテゴリー数: ${guild.channels.cache.filter((c) => c.type === ChannelType.GuildCategory).size}\n絵文字数: ${ - guild.emojis.cache.size - }` + }\nカテゴリー数: ${guild.channels.cache.filter((c) => c.type === ChannelType.GuildCategory).size}\n絵文字数: ${guild.emojis.cache.size}` } ) .setThumbnail(guild.iconURL());