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

+9 -13
View File
@@ -2,8 +2,8 @@ import { GuildQueue, useQueue } from 'discord-player';
import { EmbedBuilder, GuildMember, SlashCommandBuilder } from 'discord.js';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkSameVoiceChannel, checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
class VolumeCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -18,6 +18,12 @@ class VolumeCommand extends BaseSlashCommandInteraction {
.setMaxValue(100)
);
super(data);
this.validators = [
(args) => checkInVoiceChannel(args),
(args) => checkSameVoiceChannel(args),
(args) => checkQueueExists(args)
];
}
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
@@ -26,17 +32,7 @@ class VolumeCommand extends BaseSlashCommandInteraction {
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
const validators = [
() => notInVoiceChannel({ interaction, executionId }),
() => notInSameVoiceChannel({ interaction, queue, executionId }),
() => queueDoesNotExist({ interaction, queue, executionId })
];
for (const validator of validators) {
if (await validator()) {
return;
}
}
await this.runValidators({ interaction, queue, executionId });
const volume: number = interaction.options.getNumber('percentage')!;