mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 22:15:29 +00:00
fix: refactor remove command
This commit is contained in:
1 parent
ff41013164
commit
230ba5fd93
1 file changed
+24
-4
@@ -1,9 +1,10 @@
|
|||||||
import { GuildQueue, Track, useQueue } from 'discord-player';
|
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 { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
||||||
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
||||||
import { checkQueueExists } from '../../../utils/validation/queueValidator';
|
import { checkQueueExists } from '../../../utils/validation/queueValidator';
|
||||||
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||||
|
import { Logger } from 'pino';
|
||||||
|
|
||||||
class RemoveCommand extends BaseSlashCommandInteraction {
|
class RemoveCommand extends BaseSlashCommandInteraction {
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -35,10 +36,22 @@ class RemoveCommand extends BaseSlashCommandInteraction {
|
|||||||
const removeTrackNumber: number = interaction.options.getNumber('tracknumber')!;
|
const removeTrackNumber: number = interaction.options.getNumber('tracknumber')!;
|
||||||
|
|
||||||
if (removeTrackNumber > queue.tracks.data.length) {
|
if (removeTrackNumber > queue.tracks.data.length) {
|
||||||
|
return await this.handleInvalidTrackNumber(logger, interaction, removeTrackNumber, 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('Specified track number is higher than total tracks.');
|
||||||
|
|
||||||
logger.debug('Responding with warning embed.');
|
logger.debug('Responding with warning embed.');
|
||||||
return await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setDescription(
|
.setDescription(
|
||||||
@@ -47,14 +60,20 @@ class RemoveCommand extends BaseSlashCommandInteraction {
|
|||||||
.setColor(this.embedOptions.colors.warning)
|
.setColor(this.embedOptions.colors.warning)
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove specified track number from queue
|
private async removeTrackFromQueue(
|
||||||
|
logger: Logger,
|
||||||
|
interaction: ChatInputCommandInteraction,
|
||||||
|
queue: GuildQueue,
|
||||||
|
removeTrackNumber: number
|
||||||
|
) {
|
||||||
const removedTrack: Track = queue.node.remove(removeTrackNumber - 1)!;
|
const removedTrack: Track = queue.node.remove(removeTrackNumber - 1)!;
|
||||||
logger.debug(`Removed track '${removedTrack.url}' from queue.`);
|
logger.debug(`Removed track '${removedTrack.url}' from queue.`);
|
||||||
|
|
||||||
logger.debug('Responding with success embed.');
|
logger.debug('Responding with success embed.');
|
||||||
return await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setAuthor(await this.getEmbedUserAuthor(interaction))
|
.setAuthor(await this.getEmbedUserAuthor(interaction))
|
||||||
@@ -67,6 +86,7 @@ class RemoveCommand extends BaseSlashCommandInteraction {
|
|||||||
.setColor(this.embedOptions.colors.success)
|
.setColor(this.embedOptions.colors.success)
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user