diff --git a/src/commands/tenmans.ts b/src/commands/tenmans.ts index 6532e0c..799f266 100644 --- a/src/commands/tenmans.ts +++ b/src/commands/tenmans.ts @@ -33,7 +33,7 @@ abstract class QueueAction< abstract updateQueue(); - afterUserExecute(): Promise { + async afterUserExecute(): Promise { if (activeTenmansMessage === null) { this.interaction.reply({ content: "I must wait a moment! There is no active 10mans queue.", @@ -42,7 +42,7 @@ abstract class QueueAction< return; } - this.updateQueue(); + await this.updateQueue(); activeTenmansMessage.edit({ embeds: [createEmbed(time)], @@ -72,6 +72,36 @@ class LeaveQueueButtonAction extends QueueAction { } } +class ManualAddUserToQueue extends QueueAction { + async updateQueue() { + const targetUser = this.interaction.options.getUser("member"); + const targetMember = (await this.db.collection("members").findOne({ + discordId: targetUser.id, + })) as Member; + tenmansQueue.push(targetMember); + this.interaction.reply({ + content: `User \`${targetUser.username}\` added to the queue.`, + ephemeral: true, + }); + } +} + +class ManualRemoveUserToQueue extends QueueAction { + async updateQueue() { + const targetUser = this.interaction.options.getUser("member"); + const targetMember = (await this.db.collection("members").findOne({ + discordId: targetUser.id, + })) as Member; + tenmansQueue = tenmansQueue.filter( + (member) => member.discordId !== targetMember.discordId + ); + this.interaction.reply({ + content: `User \`${targetUser.username}\` removed from the queue.`, + ephemeral: true, + }); + } +} + class SubcommandTenmansStart extends MessageExecutable { async execute(): Promise { const interaction_user = this.interaction.user; @@ -133,22 +163,25 @@ class TenmansCloseSubcommand extends MessageExecutable { } // Teardown - clear current queue - tenmansQueue = [] + tenmansQueue = []; await activeTenmansMessage.delete(); } } -export async function cmd_tenmans(interaction, db: Db) { +export async function cmd_tenmans(interaction: CommandInteraction, db: Db) { const commands: { [key: string]: { new ( interaction: Interaction, - db: Db + db: Db, + queueId: string ): MessageExecutable; }; } = { start: SubcommandTenmansStart, - end: TenmansCloseSubcommand + end: TenmansCloseSubcommand, + add_user: ManualAddUserToQueue, + remove_user: ManualRemoveUserToQueue, }; // Wrap function call to pass same args to all methods @@ -157,11 +190,11 @@ export async function cmd_tenmans(interaction, db: Db) { console.error("Bad action:", interaction.options.getSubcommand()); interaction.reply({ ephemeral: true, - content: "Error logged; please tell an admin what you were trying to do." + content: "Error logged; please tell an admin what you were trying to do.", }); return; } - const command = new Action(interaction, db); + const command = new Action(interaction, db, interaction.options.getString("queueId")); command.execute(); } @@ -185,7 +218,7 @@ export async function handleButton(interaction: ButtonInteraction, db: Db) { console.error("Bad action:", interaction.customId); interaction.reply({ ephemeral: true, - content: "Error logged; please tell an admin what you were trying to do." + content: "Error logged; please tell an admin what you were trying to do.", }); return; } diff --git a/src/index.ts b/src/index.ts index c803c1e..f399d8e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,11 +24,12 @@ const commands = [ }, { name: "pronouns", - description: "Your preferred third-person pronouns (used by casters)", + description: + "Your preferred third-person pronouns (used by casters)", type: ApplicationCommandOptionType.String, required: true, }, - ] + ], }, { name: "update", @@ -43,12 +44,13 @@ const commands = [ }, { name: "pronouns", - description: "Your new preferred third-person pronouns (used by casters)", + description: + "Your new preferred third-person pronouns (used by casters)", type: ApplicationCommandOptionType.String, required: false, }, - ] - } + ], + }, ], }, { @@ -64,8 +66,8 @@ const commands = [ name: "time", description: "The time to start queue", type: ApplicationCommandOptionType.String, - } - ] + }, + ], }, { name: "close", @@ -73,7 +75,7 @@ const commands = [ type: ApplicationCommandOptionType.Subcommand, options: [ // TODO: Add an option for queue id after adding multi-queue support - ] + ], }, { name: "vote", @@ -83,11 +85,49 @@ const commands = [ { name: "time", description: "The time to start the queue", - type: ApplicationCommandOptionType.String - } - ] - } - ] + type: ApplicationCommandOptionType.String, + }, + ], + }, + { + name: "add_user", + description: "Adds a specified user to a 10mans queue", + type: ApplicationCommandOptionType.Subcommand, + options: [ + { + name: "member", + description: "The member to add to the queue", + type: ApplicationCommandOptionType.User, + required: true + }, + { + name: "queue_id", + description: "The queue to modify", + type: ApplicationCommandOptionType.String, + required: false + }, + ], + }, + { + name: "remove_user", + description: "Removes a specified user to a 10mans queue", + type: ApplicationCommandOptionType.Subcommand, + options: [ + { + name: "member", + description: "The member to remove from the queue", + type: ApplicationCommandOptionType.User, + required: true + }, + { + name: "queue_id", + description: "The queue to modify", + type: ApplicationCommandOptionType.String, + required: false + }, + ], + }, + ], }, { name: "config", @@ -101,12 +141,12 @@ const commands = [ { name: "channel", description: "Channel to place messages", - type: ApplicationCommandOptionType.Channel - } - ] - } - ] - } + type: ApplicationCommandOptionType.Channel, + }, + ], + }, + ], + }, ]; const rest = new REST({ version: "9" }).setToken(process.env.CYPHERBOT_TOKEN); @@ -116,7 +156,10 @@ const rest = new REST({ version: "9" }).setToken(process.env.CYPHERBOT_TOKEN); console.log("Started refreshing application (/) commands."); await rest.put( - Routes.applicationGuildCommands(process.env.CYPHERBOT_CLIENT_ID, process.env.CYPHERBOT_TARGET_GUILD_ID), + Routes.applicationGuildCommands( + process.env.CYPHERBOT_CLIENT_ID, + process.env.CYPHERBOT_TARGET_GUILD_ID + ), { body: commands, }