diff --git a/src/interactions/commands/player/back.ts b/src/interactions/commands/player/back.ts index 11ef37f..d5b04c6 100644 --- a/src/interactions/commands/player/back.ts +++ b/src/interactions/commands/player/back.ts @@ -12,7 +12,7 @@ class BackCommand extends BaseSlashCommandInteraction { .setName('back') .setDescription('Go back to previous track or specified position in history.') .addNumberOption((option) => - option.setName('tracknumber').setDescription('The position in history to go back to.').setMinValue(1) + option.setName('position').setDescription('The position in history to go back to.').setMinValue(1) ); super(data); } @@ -30,7 +30,7 @@ class BackCommand extends BaseSlashCommandInteraction { checkQueueCurrentTrack ]); - const backToTrackInput: number = interaction.options.getNumber('tracknumber')!; + const backToTrackInput: number = interaction.options.getNumber('position')!; if (backToTrackInput) { return await this.handleBackToTrackPosition(logger, interaction, history, backToTrackInput); @@ -46,22 +46,27 @@ class BackCommand extends BaseSlashCommandInteraction { backtoTrackPosition: number ) { if (backtoTrackPosition > history.tracks.data.length) { - return await this.handleTrackNumberHigherThanTotalTracks(backtoTrackPosition, history, logger, interaction); + return await this.handleTrackPositionHigherThanQueueLength( + backtoTrackPosition, + history, + logger, + interaction + ); } else { await history.back(); const recoveredTrack: Track = history.currentTrack! ?? history.tracks.data[backtoTrackPosition - 1]; - logger.debug('Went back to specified track number in history.'); + logger.debug('Went back to specified track position in history.'); return await this.respondWithSuccessEmbed(recoveredTrack, interaction); } } - private async handleTrackNumberHigherThanTotalTracks( + private async handleTrackPositionHigherThanQueueLength( backToTrackPosition: number, history: GuildQueueHistory, logger: Logger, interaction: ChatInputCommandInteraction ) { - logger.debug('Specified track number was higher than total tracks.'); + logger.debug('Specified track position was higher than total tracks.'); return await interaction.editReply({ embeds: [ new EmbedBuilder() diff --git a/src/interactions/commands/player/remove.ts b/src/interactions/commands/player/remove.ts index d44d6d9..00a2d0e 100644 --- a/src/interactions/commands/player/remove.ts +++ b/src/interactions/commands/player/remove.ts @@ -10,13 +10,41 @@ class RemoveCommand extends BaseSlashCommandInteraction { constructor() { const data = new SlashCommandBuilder() .setName('remove') - .setDescription('Remove specified track from the queue') - .addNumberOption((option) => - option - .setName('tracknumber') - .setDescription('The position in queue for track to remove.') - .setMinValue(1) - .setRequired(true) + .setDescription('Remove tracks from the queue') + .addSubcommand((subcommand) => + subcommand + .setName('track') + .setDescription('Remove a track from the queue') + .addIntegerOption((option) => + option + .setName('position') + .setDescription('The position in queue for track to remove.') + .setMinValue(1) + .setRequired(true) + ) + ) + .addSubcommand((subcommand) => + subcommand + .setName('range') + .setDescription('Remove a range of tracks from the queue') + .addIntegerOption((option) => + option + .setName('start') + .setDescription('The starting position of the range to remove') + .setRequired(true) + ) + .addIntegerOption((option) => + option + .setName('end') + .setDescription('The ending position of the range to remove') + .setRequired(true) + ) + ) + .addSubcommand((subcommand) => + subcommand.setName('queue').setDescription('Remove all tracks from the queue') + ) + .addSubcommand((subcommand) => + subcommand.setName('duplicates').setDescription('Remove all duplicate tracks from the queue') ); super(data); } @@ -33,22 +61,29 @@ class RemoveCommand extends BaseSlashCommandInteraction { checkQueueExists ]); - const removeTrackNumber: number = interaction.options.getNumber('tracknumber')!; + const subcommand = interaction.options.getSubcommand(); - if (removeTrackNumber > queue.tracks.data.length) { - return await this.handleInvalidTrackNumber(logger, interaction, removeTrackNumber, queue); + switch (subcommand) { + default: + return Promise.resolve(); } - return await this.removeTrackFromQueue(logger, interaction, queue, removeTrackNumber); + const trackPositionInput: number = interaction.options.getNumber('position')!; + + if (trackPositionInput > queue.tracks.data.length) { + return await this.handleTrackPositionHigherThanQueueLength(logger, interaction, trackPositionInput, queue); + } + + return await this.removeTrackFromQueue(logger, interaction, queue, trackPositionInput); } - private async handleInvalidTrackNumber( + private async handleTrackPositionHigherThanQueueLength( logger: Logger, interaction: ChatInputCommandInteraction, - removeTrackNumber: number, + trackPositionInput: number, queue: GuildQueue ) { - logger.debug('Specified track number is higher than total tracks.'); + logger.debug('Specified track position is higher than total tracks.'); logger.debug('Responding with warning embed.'); await interaction.editReply({ @@ -56,7 +91,7 @@ class RemoveCommand extends BaseSlashCommandInteraction { new EmbedBuilder() .setDescription( `**${this.embedOptions.icons.warning} Oops!**\n` + - `Track **\`${removeTrackNumber}\`** is not a valid track number. There are a total of **\`${queue.tracks.data.length}\`** tracks in the queue.` + + `Track **\`${trackPositionInput}\`** is not a valid track position. There are a total of **\`${queue.tracks.data.length}\`** tracks in the queue.` + '\n\nView tracks added to the queue with **`/queue`**.' ) .setColor(this.embedOptions.colors.warning) @@ -69,9 +104,9 @@ class RemoveCommand extends BaseSlashCommandInteraction { logger: Logger, interaction: ChatInputCommandInteraction, queue: GuildQueue, - removeTrackNumber: number + trackPositionInput: number ) { - const removedTrack: Track = queue.node.remove(removeTrackNumber - 1)!; + const removedTrack: Track = queue.node.remove(trackPositionInput - 1)!; logger.debug(`Removed track '${removedTrack.url}' from queue.`); logger.debug('Responding with success embed.'); diff --git a/src/interactions/commands/player/skip.ts b/src/interactions/commands/player/skip.ts index e95580c..f3c738a 100644 --- a/src/interactions/commands/player/skip.ts +++ b/src/interactions/commands/player/skip.ts @@ -12,7 +12,7 @@ class SkipCommand extends BaseSlashCommandInteraction { .setName('skip') .setDescription('Skip track to next or specified position in queue.') .addNumberOption((option) => - option.setName('tracknumber').setDescription('The position in queue to skip to.').setMinValue(1) + option.setName('position').setDescription('The position in queue to skip to.').setMinValue(1) ); super(data); } @@ -30,10 +30,10 @@ class SkipCommand extends BaseSlashCommandInteraction { checkQueueCurrentTrack ]); - const skipToTrackInput: number = interaction.options.getNumber('tracknumber')!; + const trackPositionInput: number = interaction.options.getNumber('position')!; - if (skipToTrackInput) { - return await this.handleSkipToTrackPosition(logger, interaction, queue, skipToTrackInput); + if (trackPositionInput) { + return await this.handleSkipToTrackPosition(logger, interaction, queue, trackPositionInput); } else { return await this.handleSkipToNextTrack(logger, interaction, queue); } @@ -43,31 +43,31 @@ class SkipCommand extends BaseSlashCommandInteraction { logger: Logger, interaction: ChatInputCommandInteraction, queue: GuildQueue, - skipToTrackPosition: number + trackPosition: number ) { - if (skipToTrackPosition > queue.tracks.data.length) { - return await this.handleTrackNumberHigherThanTotalTracks(skipToTrackPosition, queue, logger, interaction); + if (trackPosition > queue.tracks.data.length) { + return await this.handleTrackPositionHigherThanQueueLength(trackPosition, queue, logger, interaction); } else { const skippedTrack: Track = queue.currentTrack!; - queue.node.skipTo(skipToTrackPosition - 1); - logger.debug('Skipped to specified track number.'); + queue.node.skipTo(trackPosition - 1); + logger.debug('Skipped to specified track position.'); return await this.respondWithSuccessEmbed(skippedTrack, interaction); } } - private async handleTrackNumberHigherThanTotalTracks( - skipToTrack: number, + private async handleTrackPositionHigherThanQueueLength( + trackPosition: number, queue: GuildQueue, logger: Logger, interaction: ChatInputCommandInteraction ) { - logger.debug('Specified track number was higher than total tracks.'); + logger.debug('Specified track position was higher than total tracks.'); return await interaction.editReply({ embeds: [ new EmbedBuilder() .setDescription( `**${this.embedOptions.icons.warning} Oops!**\n` + - `There are only **\`${queue.tracks.data.length}\`** tracks in the queue. You cannot skip to track **\`${skipToTrack}\`**.\n\n` + + `There are only **\`${queue.tracks.data.length}\`** tracks in the queue. You cannot skip to track **\`${trackPosition}\`**.\n\n` + 'View tracks added to the queue with **`/queue`**.' ) .setColor(this.embedOptions.colors.warning)