mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 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
@@ -3,7 +3,7 @@ import { Logger } from 'pino';
|
||||
import loggerModule from '../services/logger';
|
||||
import { ExtendedClient } from '../types/clientTypes';
|
||||
import { BaseSlashCommandInteraction } from '../classes/interactions';
|
||||
import { cannotSendMessageInChannel } from '../utils/validation/permissionValidator';
|
||||
import { checkChannelPermissionViewable } from '../utils/validation/permissionValidator';
|
||||
|
||||
export const handleCommand = async (
|
||||
interaction: ChatInputCommandInteraction,
|
||||
@@ -20,9 +20,7 @@ export const handleCommand = async (
|
||||
await interaction.deferReply();
|
||||
logger.debug('Interaction deferred.');
|
||||
|
||||
if (await cannotSendMessageInChannel({ interaction, executionId })) {
|
||||
return;
|
||||
}
|
||||
await checkChannelPermissionViewable({ interaction, executionId });
|
||||
|
||||
const slashCommand: BaseSlashCommandInteraction = client.slashCommandInteractions!.get(
|
||||
interactionIdentifier
|
||||
|
||||
@@ -3,7 +3,7 @@ import { Logger } from 'pino';
|
||||
import loggerModule from '../services/logger';
|
||||
import { ExtendedClient } from '../types/clientTypes';
|
||||
import { BaseComponentInteraction } from '../classes/interactions';
|
||||
import { cannotSendMessageInChannel } from '../utils/validation/permissionValidator';
|
||||
import { checkChannelPermissionViewable } from '../utils/validation/permissionValidator';
|
||||
|
||||
export const handleComponent = async (
|
||||
interaction: MessageComponentInteraction,
|
||||
@@ -25,9 +25,7 @@ export const handleComponent = async (
|
||||
|
||||
logger.debug(`Parsed componentId '${componentId}' from identifier '${interactionIdentifier}'.`);
|
||||
|
||||
if (await cannotSendMessageInChannel({ interaction, executionId })) {
|
||||
return;
|
||||
}
|
||||
await checkChannelPermissionViewable({ interaction, executionId });
|
||||
|
||||
const component: BaseComponentInteraction = client.componentInteractions!.get(
|
||||
componentId
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
import { Logger } from 'pino';
|
||||
import loggerModule from '../services/logger';
|
||||
import { BotOptions, EmbedOptions } from '../types/configTypes';
|
||||
import { CustomError } from '../classes/interactions';
|
||||
import { CustomError, InteractionValidationError } from '../classes/interactions';
|
||||
|
||||
const embedOptions: EmbedOptions = config.get('embedOptions');
|
||||
const botOptions: BotOptions = config.get('botOptions');
|
||||
@@ -28,6 +28,13 @@ export const handleError = async (
|
||||
executionId: executionId
|
||||
});
|
||||
|
||||
if (error instanceof InteractionValidationError) {
|
||||
logger.debug(
|
||||
`Interaction validation error '${error.message}' while handling interaction '${interactionIdentifier}'.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Extract replies for embeds
|
||||
const errorReply: InteractionReplyOptions = {
|
||||
embeds: [
|
||||
|
||||
Reference in new issue
Block a user