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

Commit

Permalink
registerPermissionメソッドの作成
Browse files Browse the repository at this point in the history
  • Loading branch information
takejohn committed May 8, 2024
1 parent 344bf20 commit 97e150d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
2 changes: 2 additions & 0 deletions packages/misc/commands/reply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { LANG, Config, Command, Pager } from 'core';
import { ClientMessageHandler, ReplyPattern } from '../util/messages';
import { feature as perms } from 'perms';

perms.registerPermission('replyCustomize', '自動応答の設定');

module.exports = {
data: new SlashCommandBuilder()
.setName(LANG.commands.reply.name)
Expand Down
25 changes: 12 additions & 13 deletions packages/perms/commands/perm.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
import { CompoundCommandBuilder } from 'core';
import { feature as db } from 'db';
import { PermissionFlagsBits } from 'discord.js';
import {
ApplicationCommandOptionChoiceData,
PermissionFlagsBits,
} from 'discord.js';
import { PermissionManager } from '../PermissionManager';

const builder = new CompoundCommandBuilder('perm', '権限の設定');

const choices: ApplicationCommandOptionChoiceData<string>[] = [];

export function addChoice(choice: ApplicationCommandOptionChoiceData<string>) {
choices.push(choice);
}

builder
.subcommand('set', '値の更新')
.addStringOption({
name: 'permission',
description: '権限名',
required: true,
async autocomplete(interaction) {
await interaction.respond([
{
name: '自動応答の設定',
value: 'replyCustomize',
},
]);
await interaction.respond(choices);
},
})
.addMentionableOption({
Expand Down Expand Up @@ -57,12 +61,7 @@ builder
description: '権限名',
required: true,
async autocomplete(interaction) {
await interaction.respond([
{
name: '自動応答の設定',
value: 'replyCustomize',
},
]);
await interaction.respond(choices);
},
})
.build(async (interaction, permissionName) => {
Expand Down
9 changes: 8 additions & 1 deletion packages/perms/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommandManager, Feature } from 'core';
import { Client } from 'discord.js';
import perm from './commands/perm';
import perm, { addChoice } from './commands/perm';
import { feature as db } from 'db';
import { PermissionManager } from './PermissionManager';

Expand All @@ -20,6 +20,13 @@ class PermsFeature extends Feature {
onClientReady(client: Client<true>): void | PromiseLike<void> {
this.permissions = PermissionManager.forClient(client);
}

registerPermission(name: string, description: string) {
addChoice({
name: description,
value: name,
});
}
}

export const feature = new PermsFeature();

0 comments on commit 97e150d

Please sign in to comment.