feat: refactored handling of validators

This commit is contained in:
Marius Begby committed 2023-09-05 21:35:18 +02:00
1 parent e67d0004b0
commit 8c05499f08
31 files changed
+316 -338

No files matched your search

+10 -15
View File
@@ -13,8 +13,8 @@ import {
import { PlayerOptions } from '../../../types/configTypes';
import { BaseSlashCommandParams, BaseSlashCommandReturnType, TrackMetadata } from '../../../types/interactionTypes';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { checkQueueExists, checkQueueCurrentTrack } from '../../../utils/validation/queueValidator';
import { checkSameVoiceChannel, checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
const playerOptions: PlayerOptions = config.get('playerOptions');
@@ -24,6 +24,13 @@ 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 {
@@ -32,19 +39,7 @@ class NowPlayingCommand extends BaseSlashCommandInteraction {
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
// TODO: define TS type for validators
const validators = [
() => notInVoiceChannel({ interaction, executionId }),
() => notInSameVoiceChannel({ interaction, queue, executionId }),
() => queueDoesNotExist({ interaction, queue, executionId }),
() => queueNoCurrentTrack({ interaction, queue, executionId })
];
for (const validator of validators) {
if (await validator()) {
return;
}
}
await this.runValidators({ interaction, queue, executionId });
const sourceStringsFormatted: Map<string, string> = new Map([
['youtube', 'YouTube'],