fix: refactor remove command

This commit is contained in:
Marius Begby committed 2023-09-13 18:50:29 +02:00
1 parent ff41013164
commit 230ba5fd93
1 file changed
+35 -15
+35 -15
View File
@@ -1,9 +1,10 @@
import { GuildQueue, Track, useQueue } from 'discord-player';
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import { ChatInputCommandInteraction, EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { Logger } from 'pino';
class RemoveCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -35,26 +36,44 @@ class RemoveCommand extends BaseSlashCommandInteraction {
const removeTrackNumber: number = interaction.options.getNumber('tracknumber')!;
if (removeTrackNumber > queue.tracks.data.length) {
logger.debug('Specified track number is higher than total tracks.');
logger.debug('Responding with warning embed.');
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${this.embedOptions.icons.warning} Oops!**\nTrack **\`${removeTrackNumber}\`** is not a valid track number. 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)
]
});
return await this.handleInvalidTrackNumber(logger, interaction, removeTrackNumber, queue);
}
// Remove specified track number from queue
return await this.removeTrackFromQueue(logger, interaction, queue, removeTrackNumber);
}
private async handleInvalidTrackNumber(
logger: Logger,
interaction: ChatInputCommandInteraction,
removeTrackNumber: number,
queue: GuildQueue
) {
logger.debug('Specified track number is higher than total tracks.');
logger.debug('Responding with warning embed.');
await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${this.embedOptions.icons.warning} Oops!**\nTrack **\`${removeTrackNumber}\`** is not a valid track number. 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)
]
});
return Promise.resolve();
}
private async removeTrackFromQueue(
logger: Logger,
interaction: ChatInputCommandInteraction,
queue: GuildQueue,
removeTrackNumber: number
) {
const removedTrack: Track = queue.node.remove(removeTrackNumber - 1)!;
logger.debug(`Removed track '${removedTrack.url}' from queue.`);
logger.debug('Responding with success embed.');
return await interaction.editReply({
await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor(await this.getEmbedUserAuthor(interaction))
@@ -67,6 +86,7 @@ class RemoveCommand extends BaseSlashCommandInteraction {
.setColor(this.embedOptions.colors.success)
]
});
return Promise.resolve();
}
}