mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-03 06:28:53 +00:00
fix: add validation to component interactions
This commit is contained in:
1 parent
5bc0239cdf
commit
7053f01bc5
8 files changed
+89
-36
No files matched your search
@@ -3,8 +3,10 @@ import config from 'config';
|
||||
import loggerModule from '../../services/logger';
|
||||
import { EmbedOptions } from '../../types/configTypes';
|
||||
import { CustomComponentInteraction } from '../../types/interactionTypes';
|
||||
import { useQueue } from 'discord-player';
|
||||
import { GuildQueue, useQueue } from 'discord-player';
|
||||
import { EmbedBuilder, GuildMember } from 'discord.js';
|
||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
|
||||
import { queueDoesNotExist } from '../../utils/validation/queueValidator';
|
||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||
|
||||
const component: CustomComponentInteraction = {
|
||||
@@ -20,7 +22,19 @@ const component: CustomComponentInteraction = {
|
||||
|
||||
logger.debug('Received disable confirmation.');
|
||||
|
||||
const queue = useQueue(interaction.guild!.id)!;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// Reset filters before enabling provided filters
|
||||
if (queue.filters.ffmpeg.filters.length > 0) {
|
||||
|
||||
@@ -3,8 +3,10 @@ import config from 'config';
|
||||
import loggerModule from '../../services/logger';
|
||||
import { EmbedOptions, FFmpegFilterOptions } from '../../types/configTypes';
|
||||
import { CustomComponentInteraction } from '../../types/interactionTypes';
|
||||
import { QueueFilters, useQueue } from 'discord-player';
|
||||
import { GuildQueue, QueueFilters, useQueue } from 'discord-player';
|
||||
import { EmbedBuilder, GuildMember, StringSelectMenuInteraction } from 'discord.js';
|
||||
import { notInSameVoiceChannel, notInVoiceChannel } from '../../utils/validation/voiceChannelValidator';
|
||||
import { queueDoesNotExist } from '../../utils/validation/queueValidator';
|
||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||
const ffmpegFilterOptions: FFmpegFilterOptions = config.get('ffmpegFilterOptions');
|
||||
|
||||
@@ -22,7 +24,19 @@ const component: CustomComponentInteraction = {
|
||||
logger.debug('Received select menu confirmation.');
|
||||
|
||||
const selectMenuInteraction = interaction as StringSelectMenuInteraction;
|
||||
const queue = useQueue(selectMenuInteraction.guild!.id)!;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
queue.filters.ffmpeg.setInputArgs([
|
||||
'-threads',
|
||||
@@ -42,10 +56,10 @@ const component: CustomComponentInteraction = {
|
||||
logger.debug('Reset queue filters.');
|
||||
}
|
||||
|
||||
|
||||
// if bassboost is enabled and not normalizer, also enable normalizer to avoid distrorion
|
||||
if (
|
||||
(selectMenuInteraction.values.includes('bassboost_low') || selectMenuInteraction.values.includes('bassboost')) &&
|
||||
(selectMenuInteraction.values.includes('bassboost_low') ||
|
||||
selectMenuInteraction.values.includes('bassboost')) &&
|
||||
!selectMenuInteraction.values.includes('normalizer')
|
||||
) {
|
||||
selectMenuInteraction.values.push('normalizer');
|
||||
|
||||
@@ -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.');
|
||||
|
||||
|
||||
Reference in new issue
Block a user