Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #47 from takejohn/feature/custom-reply-permission
Browse files Browse the repository at this point in the history
自動応答のカスタマイズに権限確認の追加
  • Loading branch information
ringo360 authored Feb 29, 2024
2 parents aa910b1 + d826b0e commit 3616104
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
24 changes: 23 additions & 1 deletion commands/reply.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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),
Expand All @@ -77,6 +81,9 @@ const commandReply = {
}

case LANG.commands.reply.subcommands.remove.name: {
if (!await checkPermission(interaction)) {
return;
}
const replyPattern = await guildMessageHandler.removeReplyPattern(
interaction.options.getString(LANG.commands.reply.subcommands.remove.options.message.name, true)
);
Expand Down Expand Up @@ -108,4 +115,19 @@ const commandReply = {
}
};

/**
* 使う権限があるかをチェックする。
* @param {ChatInputCommandInteraction} interaction
*/
async function checkPermission(interaction) {
if (!config.replyCustomizeAllowedUsers?.includes(interaction.user.id)) {
await interaction.reply({
content: LANG.commands.reply.permissionError,
ephemeral: true,
});
return false;
}
return true;
}

module.exports = commandReply;
1 change: 1 addition & 0 deletions config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"cfPurgeUrl": "https://cdn.yourdomain.com/",
"AdminRoleID": "00000000000",
"AdminUserIDs": ["1063527758292070591", "1126422758696427552"],
"replyCustomizeAllowedUsers": ["00000000000","16326412825651210244096"],
"mongoDBhost": "127.0.0.1",
"mongoDBport": "27017",
"mongoDBuser": "admin",
Expand Down
3 changes: 2 additions & 1 deletion language/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,8 @@
"description": "自動応答の一覧を表示します。"
}
},
"notInGuildError": "このコマンドはサーバー内でのみ使用できます!"
"notInGuildError": "このコマンドはサーバー内でのみ使用できます!",
"permissionError": "このコマンドを使用する権限がありません!"
},
"resume": {
"name": "resume",
Expand Down

0 comments on commit 3616104

Please sign in to comment.