fix: update validation in interactions

This commit is contained in:
Marius Begby committed 2023-08-29 15:42:29 +02:00
1 parent 37546405e2
commit 5bc0239cdf
17 files changed
+162 -217

No files matched your search

+10 -20
View File
@@ -6,6 +6,7 @@ import loggerModule from '../../../services/logger';
import { CustomSlashCommandInteraction } from '../../../types/interactionTypes';
import { EmbedOptions } from '../../../types/configTypes';
import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { queueDoesNotExist } from '../../../utils/validation/queueValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
@@ -27,29 +28,18 @@ const command: CustomSlashCommandInteraction = {
guildId: interaction.guild?.id
});
if (await notInVoiceChannel({ interaction, executionId })) {
return;
}
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
if (!queue) {
logger.debug('There is already no queue.');
const validators = [
() => notInVoiceChannel({ interaction, executionId }),
() => notInSameVoiceChannel({ interaction, queue, executionId }),
() => queueDoesNotExist({ interaction, queue, executionId })
];
logger.debug('Responding with warning embed.');
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedOptions.icons.warning} Oops!**\n_Hmm.._ It seems I am not in a voice channel!`
)
.setColor(embedOptions.colors.warning)
]
});
}
if (await notInSameVoiceChannel({ interaction, queue, executionId })) {
return;
for (const validator of validators) {
if (await validator()) {
return;
}
}
if (!queue.deleted) {