From b5ef3c216f28762c553dbee69c685a0edecb0498 Mon Sep 17 00:00:00 2001 From: takejohn <105504345+takejohn@users.noreply.github.com> Date: Thu, 29 Feb 2024 22:23:59 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=E6=A8=A9=E9=99=90=E7=A2=BA=E8=AA=8D?= =?UTF-8?q?=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commands/reply.js | 24 +++++++++++++++++++++++- config.json.example | 1 + language/default.json | 3 ++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/commands/reply.js b/commands/reply.js index 0d77841..f06808d 100644 --- a/commands/reply.js +++ b/commands/reply.js @@ -1,10 +1,11 @@ // @ts-check const assert = require('assert'); -const { SlashCommandBuilder } = require("discord.js"); +const { SlashCommandBuilder, ChatInputCommandInteraction } = require("discord.js"); const { LANG } = require("../util/languages"); const { ClientMessageHandler, ReplyPattern } = require("../internal/messages"); const Pager = require('../util/pager'); +const config = require("../config.json"); /** @type {import("../util/types").Command} */ const commandReply = { @@ -59,6 +60,9 @@ const commandReply = { switch (subcommand) { case LANG.commands.reply.subcommands.add.name: { + if (!await checkPermission(interaction)) { + return; + } const replyPattern = new ReplyPattern( interaction.options.getString(LANG.commands.reply.subcommands.add.options.message.name, true), interaction.options.getString(LANG.commands.reply.subcommands.add.options.reply.name, true), @@ -77,6 +81,9 @@ const commandReply = { } case LANG.commands.reply.subcommands.remove.name: { + if (!checkPermission(interaction)) { + return; + } const replyPattern = await guildMessageHandler.removeReplyPattern( interaction.options.getString(LANG.commands.reply.subcommands.remove.options.message.name, true) ); @@ -108,4 +115,19 @@ const commandReply = { } }; +/** + * 使う権限があるかをチェックする。 + * @param {ChatInputCommandInteraction} interaction + */ +async function checkPermission(interaction) { + if (!config.replyEditionAllowedUsers?.includes(interaction.user.id)) { + await interaction.reply({ + content: LANG.commands.reply.permissionError, + ephemeral: true, + }); + return false; + } + return true; +} + module.exports = commandReply; diff --git a/config.json.example b/config.json.example index 6799dc3..0ca73d7 100755 --- a/config.json.example +++ b/config.json.example @@ -15,6 +15,7 @@ "cfPurgeUrl": "https://cdn.yourdomain.com/", "AdminRoleID": "00000000000", "AdminUserIDs": ["1063527758292070591", "1126422758696427552"], + "replyEditionAllowedUsers": ["00000000000","16326412825651210244096"], "mongoDBhost": "127.0.0.1", "mongoDBport": "27017", "mongoDBuser": "admin", diff --git a/language/default.json b/language/default.json index f7c0ddf..f117b43 100644 --- a/language/default.json +++ b/language/default.json @@ -550,7 +550,8 @@ "description": "自動応答の一覧を表示します。" } }, - "notInGuildError": "このコマンドはサーバー内でのみ使用できます!" + "notInGuildError": "このコマンドはサーバー内でのみ使用できます!", + "permissionError": "このコマンドを使用する権限がありません!" }, "resume": { "name": "resume", From 0a5d3e6a05ea6fb0b121be45e06835e24d5fa9f3 Mon Sep 17 00:00:00 2001 From: takejohn <105504345+takejohn@users.noreply.github.com> Date: Thu, 29 Feb 2024 22:28:45 +0900 Subject: [PATCH 2/3] =?UTF-8?q?await=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commands/reply.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/reply.js b/commands/reply.js index f06808d..4d31bd3 100644 --- a/commands/reply.js +++ b/commands/reply.js @@ -81,7 +81,7 @@ const commandReply = { } case LANG.commands.reply.subcommands.remove.name: { - if (!checkPermission(interaction)) { + if (!await checkPermission(interaction)) { return; } const replyPattern = await guildMessageHandler.removeReplyPattern( From d826b0e078b5a8bffc5e4246c0c8c5d5db809f29 Mon Sep 17 00:00:00 2001 From: takejohn <105504345+takejohn@users.noreply.github.com> Date: Thu, 29 Feb 2024 22:31:10 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=E3=82=AD=E3=83=BC=E3=82=92=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commands/reply.js | 2 +- config.json.example | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/commands/reply.js b/commands/reply.js index 4d31bd3..cd355b6 100644 --- a/commands/reply.js +++ b/commands/reply.js @@ -120,7 +120,7 @@ const commandReply = { * @param {ChatInputCommandInteraction} interaction */ async function checkPermission(interaction) { - if (!config.replyEditionAllowedUsers?.includes(interaction.user.id)) { + if (!config.replyCustomizeAllowedUsers?.includes(interaction.user.id)) { await interaction.reply({ content: LANG.commands.reply.permissionError, ephemeral: true, diff --git a/config.json.example b/config.json.example index 0ca73d7..e8169da 100755 --- a/config.json.example +++ b/config.json.example @@ -15,7 +15,7 @@ "cfPurgeUrl": "https://cdn.yourdomain.com/", "AdminRoleID": "00000000000", "AdminUserIDs": ["1063527758292070591", "1126422758696427552"], - "replyEditionAllowedUsers": ["00000000000","16326412825651210244096"], + "replyCustomizeAllowedUsers": ["00000000000","16326412825651210244096"], "mongoDBhost": "127.0.0.1", "mongoDBport": "27017", "mongoDBuser": "admin",