fix: add validation to component interactions

This commit is contained in:
Marius Begby committed 2023-08-29 15:48:53 +02:00
1 parent 5bc0239cdf
commit 7053f01bc5
8 files changed
+89 -36

No files matched your search

@@ -5,6 +5,8 @@ import { EmbedBuilder, GuildMember } from 'discord.js';
import loggerModule from '../../services/logger';
import { EmbedOptions } from '../../types/configTypes';
import { CustomComponentInteraction } from '../../types/interactionTypes';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { queueDoesNotExist, queueNoCurrentTrack } from '../../utils/validation/queueValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
const component: CustomComponentInteraction = {
@@ -22,6 +24,19 @@ const component: CustomComponentInteraction = {
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
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;
}
}
if (!queue || (queue.tracks.data.length === 0 && !queue.currentTrack)) {
logger.debug('Tried skipping track but there was no queue.');