feat!: Extracted handling of interactions into separate files

This commit is contained in:
Marius Begby committed 2023-08-28 17:21:52 +02:00
1 parent 8e9cb308e9
commit 780e20d419
7 files changed
+166 -153

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
import { ChatInputCommandInteraction } from 'discord.js';
import { Command, ExtendedClient } from '../types/clientTypes';
import { cannotSendMessageInChannel } from '../utils/validation/permissionValidator';
import loggerModule from '../services/logger';
const logger = loggerModule.child({
source: 'interactionCommandHandler.ts',
module: 'handler',
name: 'interactionCommandHandler'
});
export const handleCommand = async (
interaction: ChatInputCommandInteraction,
client: ExtendedClient,
executionId: string
) => {
await interaction.deferReply();
logger.debug('Interaction deferred.');
const command = client.commands?.get(interaction.commandName) as Command;
if (!command) {
logger.warn(`Interaction created but command '${interaction.commandName}' was not found.`);
return;
}
if (await cannotSendMessageInChannel({ interaction, executionId })) {
return Promise.resolve();
}
logger.debug('Executing command interaction.');
await command.execute({ interaction, client, executionId });
};