From e8472719da73c146a5972df068a4f73a55f5ab20 Mon Sep 17 00:00:00 2001 From: Anthony Date: Thu, 4 Aug 2022 05:02:49 +0100 Subject: [PATCH] refactor(arabot): change togglecommand to a subcommand of diversity --- src/commands/mod/diversityToggleOpen.ts | 27 ++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/commands/mod/diversityToggleOpen.ts b/src/commands/mod/diversityToggleOpen.ts index 93762b6..f132aec 100644 --- a/src/commands/mod/diversityToggleOpen.ts +++ b/src/commands/mod/diversityToggleOpen.ts @@ -25,8 +25,8 @@ export class ToggleOpenCommand extends Command { public constructor(context: Command.Context, options: Command.Options) { super(context, { ...options, - name: 'toggleopen', - description: 'Toggles read-only for vegans in diversity section', + name: 'diversity', + description: 'Commands for the Diversity Coordinators', preconditions: ['DiversityCoordinatorOnly'], }); } @@ -36,7 +36,9 @@ export class ToggleOpenCommand extends Command { registry.registerChatInputCommand( (builder) => builder .setName(this.name) - .setDescription(this.description), + .setDescription(this.description) + .addSubcommand((command) => command.setName('toggleopen') + .setDescription('Toggles read-only for vegans in diversity section')), { behaviorWhenNotIdentical: RegisterBehavior.Overwrite, }, @@ -45,6 +47,25 @@ export class ToggleOpenCommand extends Command { // Command run public async chatInputRun(interaction: Command.ChatInputInteraction) { + const subcommand = interaction.options.getSubcommand(true); + + // Checks what subcommand was run + switch (subcommand) { + case 'toggleopen': { + return await this.toggleOpen(interaction); + } + } + + // If subcommand is invalid + await interaction.reply({ + content: 'Invalid sub command!', + ephemeral: true, + fetchReply: true, + }); + } + + // Command run + public async toggleOpen(interaction: Command.ChatInputInteraction) { // Check if guild is not null if (interaction.guild === null) { await interaction.reply({