From 7298ae15623c069fa297321ba51b3d66957cc542 Mon Sep 17 00:00:00 2001 From: Federico fuji97 Rapetti Date: Sun, 26 Dec 2021 18:06:24 +0100 Subject: [PATCH] Update remove command to slash command --- src/commands/remove.ts | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/src/commands/remove.ts b/src/commands/remove.ts index 9c40a71..f0c1b15 100644 --- a/src/commands/remove.ts +++ b/src/commands/remove.ts @@ -1,18 +1,26 @@ -import {Message} from 'discord.js'; +import {CommandInteraction, Message} from 'discord.js'; import {inject, injectable} from 'inversify'; import {TYPES} from '../types.js'; import PlayerManager from '../managers/player.js'; import Command from '.'; import errorMsg from '../utils/error-msg.js'; +import {SlashCommandBuilder} from '@discordjs/builders'; @injectable() export default class implements Command { - public name = 'remove'; - public aliases = ['rm']; - public examples = [ - ['remove 1', 'removes the next song in the queue'], - ['rm 5-7', 'remove every song in range 5 - 7 (inclusive) from the queue'], - ]; + public readonly slashCommand = new SlashCommandBuilder() + .setName('remove') + // TODO: make sure verb tense is consistent between all command descriptions + .setDescription('remove songs from the queue') + .addIntegerOption(option => + option.setName('position') + .setDescription('position of the song to remove [default: 1]') + .setRequired(false), + ) + .addIntegerOption(option => + option.setName('range') + .setDescription('number of songs to remove [default: 1]') + .setRequired(false)); private readonly playerManager: PlayerManager; @@ -20,6 +28,25 @@ export default class implements Command { this.playerManager = playerManager; } + public async executeFromInteraction(interaction: CommandInteraction): Promise { + const player = this.playerManager.get(interaction.guild!.id); + + const position = interaction.options.getInteger('position') ?? 1; + const range = interaction.options.getInteger('range') ?? 1; + + if (position < 1) { + await interaction.reply('position must be greater than 0'); + } + + if (range < 1) { + await interaction.reply('range must be greater than 0'); + } + + player.removeFromQueue(position, range); + + await interaction.reply(':wastebasket: removed'); + } + public async execute(msg: Message, args: string []): Promise { const player = this.playerManager.get(msg.guild!.id);