From 56056cd73d03d51d5a49e0cace710ccdcc930281 Mon Sep 17 00:00:00 2001 From: Marius Begby Date: Wed, 6 Sep 2023 20:40:25 +0200 Subject: [PATCH] fix: Updated sending in checks for validation runner --- src/interactions/commands/player/filters.ts | 14 ++++++-------- src/interactions/commands/player/leave.ts | 12 +++++------- src/interactions/commands/player/loop.ts | 12 +++++------- src/interactions/commands/player/lyrics.ts | 14 ++++++-------- src/interactions/commands/player/nowplaying.ts | 14 ++++++-------- src/interactions/commands/player/pause.ts | 14 ++++++-------- src/interactions/commands/player/play.ts | 4 +--- src/interactions/commands/player/queue.ts | 12 +++++------- src/interactions/commands/player/remove.ts | 12 +++++------- src/interactions/commands/player/seek.ts | 14 ++++++-------- src/interactions/commands/player/shuffle.ts | 14 ++++++-------- src/interactions/commands/player/skip.ts | 14 ++++++-------- src/interactions/commands/player/stop.ts | 12 +++++------- src/interactions/commands/player/volume.ts | 12 +++++------- src/interactions/commands/system/guilds.ts | 4 +--- src/interactions/commands/system/reload.ts | 4 +--- src/interactions/commands/system/shards.ts | 4 +--- 17 files changed, 76 insertions(+), 110 deletions(-) diff --git a/src/interactions/commands/player/filters.ts b/src/interactions/commands/player/filters.ts index e3515e5..4909373 100644 --- a/src/interactions/commands/player/filters.ts +++ b/src/interactions/commands/player/filters.ts @@ -41,13 +41,6 @@ class FiltersCommand extends BaseSlashCommandInteraction { ) ); super(data); - - this.validators = [ - (args) => checkInVoiceChannel(args), - (args) => checkSameVoiceChannel(args), - (args) => checkQueueExists(args), - (args) => checkQueueCurrentTrack(args) - ]; } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { @@ -56,7 +49,12 @@ class FiltersCommand extends BaseSlashCommandInteraction { const queue: GuildQueue = useQueue(interaction.guild!.id)!; - await this.runValidators({ interaction, queue, executionId }); + await this.runValidators({ interaction, queue, executionId }, [ + checkInVoiceChannel, + checkSameVoiceChannel, + checkQueueExists, + checkQueueCurrentTrack + ]); const filterProvider: string = interaction.options.getString('type') || 'FFmpeg'; diff --git a/src/interactions/commands/player/leave.ts b/src/interactions/commands/player/leave.ts index 6e5c9f4..f85ebca 100644 --- a/src/interactions/commands/player/leave.ts +++ b/src/interactions/commands/player/leave.ts @@ -11,12 +11,6 @@ class LeaveCommand extends BaseSlashCommandInteraction { .setName('leave') .setDescription('Clear the queue and remove bot from voice channel.'); super(data); - - this.validators = [ - (args) => checkInVoiceChannel(args), - (args) => checkSameVoiceChannel(args), - (args) => checkQueueExists(args) - ]; } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { @@ -25,7 +19,11 @@ class LeaveCommand extends BaseSlashCommandInteraction { const queue: GuildQueue = useQueue(interaction.guild!.id)!; - await this.runValidators({ interaction, queue, executionId }); + await this.runValidators({ interaction, queue, executionId }, [ + checkInVoiceChannel, + checkSameVoiceChannel, + checkQueueExists + ]); logger.info('Validators passed, clearing queue.'); diff --git a/src/interactions/commands/player/loop.ts b/src/interactions/commands/player/loop.ts index dc33a8b..75fa8bf 100644 --- a/src/interactions/commands/player/loop.ts +++ b/src/interactions/commands/player/loop.ts @@ -23,12 +23,6 @@ class LoopCommand extends BaseSlashCommandInteraction { ) ); super(data); - - this.validators = [ - (args) => checkInVoiceChannel(args), - (args) => checkSameVoiceChannel(args), - (args) => checkQueueExists(args) - ]; } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { @@ -37,7 +31,11 @@ class LoopCommand extends BaseSlashCommandInteraction { const queue: GuildQueue = useQueue(interaction.guild!.id)!; - await this.runValidators({ interaction, queue, executionId }); + await this.runValidators({ interaction, queue, executionId }, [ + checkInVoiceChannel, + checkSameVoiceChannel, + checkQueueExists + ]); // TODO: create type for loop modes formatted const loopModesFormatted: Map = new Map([ diff --git a/src/interactions/commands/player/lyrics.ts b/src/interactions/commands/player/lyrics.ts index 11578c5..4eb3c13 100644 --- a/src/interactions/commands/player/lyrics.ts +++ b/src/interactions/commands/player/lyrics.ts @@ -21,13 +21,6 @@ class LyricsCommand extends BaseSlashCommandInteraction { .setAutocomplete(true) ); super(data); - - this.validators = [ - (args) => checkInVoiceChannel(args), - (args) => checkSameVoiceChannel(args), - (args) => checkQueueExists(args), - (args) => checkQueueCurrentTrack(args) - ]; } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { @@ -40,7 +33,12 @@ class LyricsCommand extends BaseSlashCommandInteraction { let geniusSearchQuery: string = ''; if (!query) { - await this.runValidators({ interaction, queue, executionId }); + await this.runValidators({ interaction, queue, executionId }, [ + checkInVoiceChannel, + checkSameVoiceChannel, + checkQueueExists, + checkQueueCurrentTrack + ]); geniusSearchQuery = queue.currentTrack!.title.slice(0, 50); diff --git a/src/interactions/commands/player/nowplaying.ts b/src/interactions/commands/player/nowplaying.ts index 08ea584..025037a 100644 --- a/src/interactions/commands/player/nowplaying.ts +++ b/src/interactions/commands/player/nowplaying.ts @@ -24,13 +24,6 @@ class NowPlayingCommand extends BaseSlashCommandInteraction { .setName('nowplaying') .setDescription('Show information about the current track.'); super(data); - - this.validators = [ - (args) => checkInVoiceChannel(args), - (args) => checkSameVoiceChannel(args), - (args) => checkQueueExists(args), - (args) => checkQueueCurrentTrack(args) - ]; } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { @@ -39,7 +32,12 @@ class NowPlayingCommand extends BaseSlashCommandInteraction { const queue: GuildQueue = useQueue(interaction.guild!.id)!; - await this.runValidators({ interaction, queue, executionId }); + await this.runValidators({ interaction, queue, executionId }, [ + checkInVoiceChannel, + checkSameVoiceChannel, + checkQueueExists, + checkQueueCurrentTrack + ]); const sourceStringsFormatted: Map = new Map([ ['youtube', 'YouTube'], diff --git a/src/interactions/commands/player/pause.ts b/src/interactions/commands/player/pause.ts index 37c6e8c..ff60b9c 100644 --- a/src/interactions/commands/player/pause.ts +++ b/src/interactions/commands/player/pause.ts @@ -9,13 +9,6 @@ class PauseCommand extends BaseSlashCommandInteraction { constructor() { const data = new SlashCommandBuilder().setName('pause').setDescription('Toggle pause for the current track.'); super(data); - - this.validators = [ - (args) => checkInVoiceChannel(args), - (args) => checkSameVoiceChannel(args), - (args) => checkQueueExists(args), - (args) => checkQueueCurrentTrack(args) - ]; } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { @@ -24,7 +17,12 @@ class PauseCommand extends BaseSlashCommandInteraction { const queue: GuildQueue = useQueue(interaction.guild!.id)!; - await this.runValidators({ interaction, queue, executionId }); + await this.runValidators({ interaction, queue, executionId }, [ + checkInVoiceChannel, + checkSameVoiceChannel, + checkQueueExists, + checkQueueCurrentTrack + ]); const currentTrack: Track = queue.currentTrack!; diff --git a/src/interactions/commands/player/play.ts b/src/interactions/commands/player/play.ts index dc0e6df..62eb9ce 100644 --- a/src/interactions/commands/player/play.ts +++ b/src/interactions/commands/player/play.ts @@ -25,15 +25,13 @@ class PlayCommand extends BaseSlashCommandInteraction { .setAutocomplete(true) ); super(data); - - this.validators = [(args) => checkInVoiceChannel(args)]; } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { const { executionId, interaction } = params; const logger = this.getLogger(this.name, executionId, interaction); - await this.runValidators({ interaction, executionId }); + await this.runValidators({ interaction, executionId }, [checkInVoiceChannel]); let queue: GuildQueue = useQueue(interaction.guild!.id)!; if (queue) { diff --git a/src/interactions/commands/player/queue.ts b/src/interactions/commands/player/queue.ts index d3b54b2..82b3568 100644 --- a/src/interactions/commands/player/queue.ts +++ b/src/interactions/commands/player/queue.ts @@ -18,12 +18,6 @@ class QueueCommand extends BaseSlashCommandInteraction { option.setName('page').setDescription('Page number to display for the queue').setMinValue(1) ); super(data); - - this.validators = [ - (args) => checkInVoiceChannel(args), - (args) => checkSameVoiceChannel(args), - (args) => checkQueueExists(args) - ]; } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { @@ -32,7 +26,11 @@ class QueueCommand extends BaseSlashCommandInteraction { const queue: GuildQueue = useQueue(interaction.guild!.id)!; - await this.runValidators({ interaction, queue, executionId }); + await this.runValidators({ interaction, queue, executionId }, [ + checkInVoiceChannel, + checkSameVoiceChannel, + checkQueueExists + ]); const pageIndex: number = (interaction.options.getNumber('page') || 1) - 1; let queueString: string = ''; diff --git a/src/interactions/commands/player/remove.ts b/src/interactions/commands/player/remove.ts index 2611e51..92d87d7 100644 --- a/src/interactions/commands/player/remove.ts +++ b/src/interactions/commands/player/remove.ts @@ -18,12 +18,6 @@ class RemoveCommand extends BaseSlashCommandInteraction { .setRequired(true) ); super(data); - - this.validators = [ - (args) => checkInVoiceChannel(args), - (args) => checkSameVoiceChannel(args), - (args) => checkQueueExists(args) - ]; } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { @@ -32,7 +26,11 @@ class RemoveCommand extends BaseSlashCommandInteraction { const queue: GuildQueue = useQueue(interaction.guild!.id)!; - await this.runValidators({ interaction, queue, executionId }); + await this.runValidators({ interaction, queue, executionId }, [ + checkInVoiceChannel, + checkSameVoiceChannel, + checkQueueExists + ]); const removeTrackNumber: number = interaction.options.getNumber('tracknumber')!; diff --git a/src/interactions/commands/player/seek.ts b/src/interactions/commands/player/seek.ts index 47e4000..cdc7641 100644 --- a/src/interactions/commands/player/seek.ts +++ b/src/interactions/commands/player/seek.ts @@ -14,13 +14,6 @@ class SeekCommand extends BaseSlashCommandInteraction { option.setName('duration').setDescription('Duration in format 00:00:00 (HH:mm:ss).').setRequired(true) ); super(data); - - this.validators = [ - (args) => checkInVoiceChannel(args), - (args) => checkSameVoiceChannel(args), - (args) => checkQueueExists(args), - (args) => checkQueueCurrentTrack(args) - ]; } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { @@ -29,7 +22,12 @@ class SeekCommand extends BaseSlashCommandInteraction { const queue: GuildQueue = useQueue(interaction.guild!.id)!; - await this.runValidators({ interaction, queue, executionId }); + await this.runValidators({ interaction, queue, executionId }, [ + checkInVoiceChannel, + checkSameVoiceChannel, + checkQueueExists, + checkQueueCurrentTrack + ]); const durationInput: string = interaction.options.getString('duration')!; diff --git a/src/interactions/commands/player/shuffle.ts b/src/interactions/commands/player/shuffle.ts index 5a630dd..affb0f6 100644 --- a/src/interactions/commands/player/shuffle.ts +++ b/src/interactions/commands/player/shuffle.ts @@ -11,13 +11,6 @@ class ShuffleCommand extends BaseSlashCommandInteraction { .setName('shuffle') .setDescription('Randomly shuffle all tracks in the queue.'); super(data); - - this.validators = [ - (args) => checkInVoiceChannel(args), - (args) => checkSameVoiceChannel(args), - (args) => checkQueueExists(args), - (args) => checkQueueEmpty(args) - ]; } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { @@ -26,7 +19,12 @@ class ShuffleCommand extends BaseSlashCommandInteraction { const queue: GuildQueue = useQueue(interaction.guild!.id)!; - await this.runValidators({ interaction, queue, executionId }); + await this.runValidators({ interaction, queue, executionId }, [ + checkInVoiceChannel, + checkSameVoiceChannel, + checkQueueExists, + checkQueueEmpty + ]); queue.tracks.shuffle(); logger.debug('Shuffled queue tracks.'); diff --git a/src/interactions/commands/player/skip.ts b/src/interactions/commands/player/skip.ts index b12d33d..911324e 100644 --- a/src/interactions/commands/player/skip.ts +++ b/src/interactions/commands/player/skip.ts @@ -14,13 +14,6 @@ class SkipCommand extends BaseSlashCommandInteraction { option.setName('tracknumber').setDescription('The position in queue to skip to.').setMinValue(1) ); super(data); - - this.validators = [ - (args) => checkInVoiceChannel(args), - (args) => checkSameVoiceChannel(args), - (args) => checkQueueExists(args), - (args) => checkQueueCurrentTrack(args) - ]; } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { @@ -29,7 +22,12 @@ class SkipCommand extends BaseSlashCommandInteraction { const queue: GuildQueue = useQueue(interaction.guild!.id)!; - await this.runValidators({ interaction, queue, executionId }); + await this.runValidators({ interaction, queue, executionId }, [ + checkInVoiceChannel, + checkSameVoiceChannel, + checkQueueExists, + checkQueueCurrentTrack + ]); const skipToTrack: number = interaction.options.getNumber('tracknumber')!; diff --git a/src/interactions/commands/player/stop.ts b/src/interactions/commands/player/stop.ts index 50cf5a9..64706ef 100644 --- a/src/interactions/commands/player/stop.ts +++ b/src/interactions/commands/player/stop.ts @@ -11,12 +11,6 @@ class StopCommand extends BaseSlashCommandInteraction { .setName('stop') .setDescription('Clear the queue and stop playing audio.'); super(data); - - this.validators = [ - (args) => checkInVoiceChannel(args), - (args) => checkSameVoiceChannel(args), - (args) => checkQueueExists(args) - ]; } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { @@ -25,7 +19,11 @@ class StopCommand extends BaseSlashCommandInteraction { const queue: GuildQueue = useQueue(interaction.guild!.id)!; - await this.runValidators({ interaction, queue, executionId }); + await this.runValidators({ interaction, queue, executionId }, [ + checkInVoiceChannel, + checkSameVoiceChannel, + checkQueueExists + ]); if (!queue.deleted) { queue.setRepeatMode(0); diff --git a/src/interactions/commands/player/volume.ts b/src/interactions/commands/player/volume.ts index d6955bf..27beb90 100644 --- a/src/interactions/commands/player/volume.ts +++ b/src/interactions/commands/player/volume.ts @@ -18,12 +18,6 @@ class VolumeCommand extends BaseSlashCommandInteraction { .setMaxValue(100) ); super(data); - - this.validators = [ - (args) => checkInVoiceChannel(args), - (args) => checkSameVoiceChannel(args), - (args) => checkQueueExists(args) - ]; } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { @@ -32,7 +26,11 @@ class VolumeCommand extends BaseSlashCommandInteraction { const queue: GuildQueue = useQueue(interaction.guild!.id)!; - await this.runValidators({ interaction, queue, executionId }); + await this.runValidators({ interaction, queue, executionId }, [ + checkInVoiceChannel, + checkSameVoiceChannel, + checkQueueExists + ]); const volume: number = interaction.options.getNumber('percentage')!; diff --git a/src/interactions/commands/system/guilds.ts b/src/interactions/commands/system/guilds.ts index ad76379..2aeb3c9 100644 --- a/src/interactions/commands/system/guilds.ts +++ b/src/interactions/commands/system/guilds.ts @@ -10,15 +10,13 @@ class GuildsCommand extends BaseSlashCommandInteraction { .setDescription('Show the top 25 guilds by member count.'); const isSystemCommand: boolean = true; super(data, isSystemCommand); - - this.validators = [(args) => checkValidGuildId(args)]; } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { const { executionId, interaction, client } = params; const logger = this.getLogger(this.name, executionId, interaction); - await this.runValidators({ interaction, executionId }); + await this.runValidators({ interaction, executionId }, [checkValidGuildId]); let shardGuilds: Guild[] = []; let totalGuildCount: number = 0; diff --git a/src/interactions/commands/system/reload.ts b/src/interactions/commands/system/reload.ts index 43f3cde..8411984 100644 --- a/src/interactions/commands/system/reload.ts +++ b/src/interactions/commands/system/reload.ts @@ -11,15 +11,13 @@ class ReloadCommand extends BaseSlashCommandInteraction { .setDescription('Reload slash command, autocomplete and component interactions across shards.'); const isSystemCommand: boolean = true; super(data, isSystemCommand); - - this.validators = [(args) => checkValidGuildId(args)]; } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { const { executionId, interaction, client } = params; const logger = this.getLogger(this.name, executionId, interaction); - await this.runValidators({ interaction, executionId }); + await this.runValidators({ interaction, executionId }, [checkValidGuildId]); try { logger.debug('Reloading interaction module across all shards.'); diff --git a/src/interactions/commands/system/shards.ts b/src/interactions/commands/system/shards.ts index 3d774e2..84b0d7e 100644 --- a/src/interactions/commands/system/shards.ts +++ b/src/interactions/commands/system/shards.ts @@ -29,15 +29,13 @@ class ShardsCommand extends BaseSlashCommandInteraction { ); const isSystemCommand: boolean = true; super(data, isSystemCommand); - - this.validators = [(args) => checkValidGuildId(args)]; } async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { const { executionId, interaction, client } = params; const logger = this.getLogger(this.name, executionId, interaction); - await this.runValidators({ interaction, executionId }); + await this.runValidators({ interaction, executionId }, [checkValidGuildId]); let shardInfoList: ShardInfo[] = [];