mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-03 06:28:53 +00:00
feat: refactored handling of validators
This commit is contained in:
1 parent
e67d0004b0
commit
8c05499f08
31 files changed
+316
-338
No files matched your search
@@ -12,9 +12,10 @@ import { Logger } from 'pino';
|
||||
import loggerModule from '../../services/logger';
|
||||
import { EmbedOptions } from '../../types/configTypes';
|
||||
import { ValidatorParams } from '../../types/utilTypes';
|
||||
import { InteractionValidationError } from '../../classes/interactions';
|
||||
|
||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||
export const cannotJoinVoiceOrTalk = async ({ interaction, executionId }: ValidatorParams) => {
|
||||
export const checkVoicePermissionJoinAndTalk = async ({ interaction, executionId }: ValidatorParams) => {
|
||||
const logger: Logger = loggerModule.child({
|
||||
module: 'utilValidation',
|
||||
name: 'cannotJoinVoiceOrTalk',
|
||||
@@ -33,7 +34,7 @@ export const cannotJoinVoiceOrTalk = async ({ interaction, executionId }: Valida
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setDescription(
|
||||
`**${embedOptions.icons.warning} Oops!**\nI do not have permission to play audio in the voice channel you are in.\n\nPlease make sure I have the **\`Connect\`** and **\`Speak\`** permissions in this voice channel.`
|
||||
`**${embedOptions.icons.warning} Oops!**\nI do not have permission to play audio in the voice channel <#${channel.id}>.\n\nPlease make sure I have the **\`Connect\`** and **\`Speak\`** permissions in this voice channel.`
|
||||
)
|
||||
.setColor(embedOptions.colors.warning)
|
||||
]
|
||||
@@ -42,13 +43,13 @@ export const cannotJoinVoiceOrTalk = async ({ interaction, executionId }: Valida
|
||||
logger.debug(
|
||||
`User tried to use command '${interactionIdentifier}' but the bot had no permission to join/speak in the voice channel.`
|
||||
);
|
||||
return true;
|
||||
throw new InteractionValidationError('Bot cannot join or speak in voice channel.');
|
||||
}
|
||||
|
||||
return false;
|
||||
return;
|
||||
};
|
||||
|
||||
export const cannotSendMessageInChannel = async ({ interaction, executionId }: ValidatorParams) => {
|
||||
export const checkChannelPermissionViewable = async ({ interaction, executionId }: ValidatorParams) => {
|
||||
const logger: Logger = loggerModule.child({
|
||||
module: 'utilValidation',
|
||||
name: 'cannotSendMessageInChannel',
|
||||
@@ -81,7 +82,7 @@ export const cannotSendMessageInChannel = async ({ interaction, executionId }: V
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setDescription(
|
||||
`**${embedOptions.icons.warning} Oops!**\nI do not have permission to send message replies in the channel you are in.\n\nPlease make sure I have the **\`View Channel\`** permission in this text channel.`
|
||||
`**${embedOptions.icons.warning} Oops!**\nI do not have permission to send message replies in the channel <#${channel.id}>.\n\nPlease make sure I have the **\`View Channel\`** permission in this text channel.`
|
||||
)
|
||||
.setColor(embedOptions.colors.warning)
|
||||
]
|
||||
@@ -106,8 +107,8 @@ export const cannotSendMessageInChannel = async ({ interaction, executionId }: V
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
throw new InteractionValidationError('Bot cannot send message in channel.');
|
||||
}
|
||||
|
||||
return false;
|
||||
return;
|
||||
};
|
||||
@@ -4,9 +4,10 @@ import { Logger } from 'pino';
|
||||
import loggerModule from '../../services/logger';
|
||||
import { EmbedOptions } from '../../types/configTypes';
|
||||
import { ValidatorParams } from '../../types/utilTypes';
|
||||
import { InteractionValidationError } from '../../classes/interactions';
|
||||
|
||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||
export const queueDoesNotExist = async ({ interaction, queue, executionId }: ValidatorParams) => {
|
||||
export const checkQueueExists = async ({ interaction, queue, executionId }: ValidatorParams) => {
|
||||
const logger: Logger = loggerModule.child({
|
||||
module: 'utilValidation',
|
||||
name: 'queueDoesNotExist',
|
||||
@@ -30,13 +31,13 @@ export const queueDoesNotExist = async ({ interaction, queue, executionId }: Val
|
||||
});
|
||||
|
||||
logger.debug(`User tried to use command '${interactionIdentifier}' but there was no queue.`);
|
||||
return true;
|
||||
throw new InteractionValidationError('Queue does not exist.');
|
||||
}
|
||||
|
||||
return false;
|
||||
return;
|
||||
};
|
||||
|
||||
export const queueNoCurrentTrack = async ({ interaction, queue, executionId }: ValidatorParams) => {
|
||||
export const checkQueueCurrentTrack = async ({ interaction, queue, executionId }: ValidatorParams) => {
|
||||
const logger: Logger = loggerModule.child({
|
||||
module: 'utilValidation',
|
||||
name: 'queueNoCurrentTrack',
|
||||
@@ -60,13 +61,13 @@ export const queueNoCurrentTrack = async ({ interaction, queue, executionId }: V
|
||||
});
|
||||
|
||||
logger.debug(`User tried to use command '${interactionIdentifier}' but there was no current track.`);
|
||||
return true;
|
||||
throw new InteractionValidationError('Queue has no current track.');
|
||||
}
|
||||
|
||||
return false;
|
||||
return;
|
||||
};
|
||||
|
||||
export const queueIsEmpty = async ({ interaction, queue, executionId }: ValidatorParams) => {
|
||||
export const checkQueueEmpty = async ({ interaction, queue, executionId }: ValidatorParams) => {
|
||||
const logger: Logger = loggerModule.child({
|
||||
module: 'utilValidation',
|
||||
name: 'queueIsEmpty',
|
||||
@@ -90,8 +91,8 @@ export const queueIsEmpty = async ({ interaction, queue, executionId }: Validato
|
||||
});
|
||||
|
||||
logger.debug(`User tried to use command '${interactionIdentifier}' but there was no tracks in the queue.`);
|
||||
return true;
|
||||
throw new InteractionValidationError('Queue is empty.');
|
||||
}
|
||||
|
||||
return false;
|
||||
return;
|
||||
};
|
||||
@@ -4,10 +4,11 @@ import { Logger } from 'pino';
|
||||
import loggerModule from '../../services/logger';
|
||||
import { EmbedOptions, SystemOptions } from '../../types/configTypes';
|
||||
import { ValidatorParams } from '../../types/utilTypes';
|
||||
import { InteractionValidationError } from '../../classes/interactions';
|
||||
|
||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||
const systemOptions: SystemOptions = config.get('systemOptions');
|
||||
export const notValidGuildId = async ({ interaction, executionId }: ValidatorParams) => {
|
||||
export const checkValidGuildId = async ({ interaction, executionId }: ValidatorParams) => {
|
||||
const logger: Logger = loggerModule.child({
|
||||
module: 'utilValidation',
|
||||
name: 'notValidGuildId',
|
||||
@@ -33,8 +34,8 @@ export const notValidGuildId = async ({ interaction, executionId }: ValidatorPar
|
||||
logger.debug(
|
||||
`User tried to use command '${interactionIdentifier}' but system command cannot be executed in the specified guild.`
|
||||
);
|
||||
return true;
|
||||
throw new InteractionValidationError('System command cannot be executed in the specified guild.');
|
||||
}
|
||||
|
||||
return false;
|
||||
return;
|
||||
};
|
||||
@@ -4,9 +4,10 @@ import { Logger } from 'pino';
|
||||
import loggerModule from '../../services/logger';
|
||||
import { EmbedOptions } from '../../types/configTypes';
|
||||
import { ValidatorParams } from '../../types/utilTypes';
|
||||
import { InteractionValidationError } from '../../classes/interactions';
|
||||
|
||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||
export const notInVoiceChannel = async ({ interaction, executionId }: ValidatorParams) => {
|
||||
export const checkInVoiceChannel = async ({ interaction, executionId }: ValidatorParams) => {
|
||||
const logger: Logger = loggerModule.child({
|
||||
module: 'validator',
|
||||
name: 'notInVoiceChannel',
|
||||
@@ -30,13 +31,13 @@ export const notInVoiceChannel = async ({ interaction, executionId }: ValidatorP
|
||||
});
|
||||
|
||||
logger.debug(`User tried to use command '${interactionIdentifier}' but was not in a voice channel.`);
|
||||
return true;
|
||||
throw new InteractionValidationError('User not in voice channel.');
|
||||
}
|
||||
|
||||
return false;
|
||||
return;
|
||||
};
|
||||
|
||||
export const notInSameVoiceChannel = async ({ interaction, queue, executionId }: ValidatorParams) => {
|
||||
export const checkSameVoiceChannel = async ({ interaction, queue, executionId }: ValidatorParams) => {
|
||||
const logger: Logger = loggerModule.child({
|
||||
module: 'utilValidation',
|
||||
name: 'notInSameVoiceChannel',
|
||||
@@ -50,7 +51,7 @@ export const notInSameVoiceChannel = async ({ interaction, queue, executionId }:
|
||||
|
||||
if (!queue || !queue.dispatcher) {
|
||||
// If there is no queue or bot is not in voice channel, then there is no need to check if user is in same voice channel.
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -68,8 +69,8 @@ export const notInSameVoiceChannel = async ({ interaction, queue, executionId }:
|
||||
});
|
||||
|
||||
logger.debug(`User tried to use command '${interactionIdentifier}' but was not in the same voice channel.`);
|
||||
return true;
|
||||
throw new InteractionValidationError('User not in same voice channel.');
|
||||
}
|
||||
|
||||
return false;
|
||||
return;
|
||||
};
|
||||
Reference in new issue
Block a user