mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-03 14:38:49 +00:00
Add class for interactions
This commit is contained in:
1 parent
d0f1e940a5
commit
b96a73df6f
37 files changed
+1038
-1012
No files matched your search
@@ -1,9 +1,16 @@
|
||||
import { MessageComponentInteraction } from 'discord.js';
|
||||
import { Logger } from 'pino';
|
||||
import loggerModule from '../services/logger';
|
||||
import { ExtendedClient } from '../types/clientTypes';
|
||||
import { BaseComponentInteraction } from '../types/interactionTypes';
|
||||
import { cannotSendMessageInChannel } from '../utils/validation/permissionValidator';
|
||||
|
||||
export const handleComponent = async (interaction: MessageComponentInteraction, executionId: string) => {
|
||||
export const handleComponent = async (
|
||||
interaction: MessageComponentInteraction,
|
||||
client: ExtendedClient,
|
||||
executionId: string,
|
||||
interactionIdentifier: string
|
||||
) => {
|
||||
const logger: Logger = loggerModule.child({
|
||||
source: 'interactionComponentHandler.js',
|
||||
module: 'handler',
|
||||
@@ -14,19 +21,23 @@ export const handleComponent = async (interaction: MessageComponentInteraction,
|
||||
await interaction.deferReply();
|
||||
logger.debug('Interaction deferred.');
|
||||
|
||||
const componentId: string = interaction.customId.split('_')[0];
|
||||
const referenceId: string = interaction.customId.split('_')[1];
|
||||
const componentId: string = interactionIdentifier.split('_')[0];
|
||||
const referenceId: string = interactionIdentifier.split('_')[1];
|
||||
|
||||
logger.debug(`Parsed componentId: ${componentId}`);
|
||||
logger.debug(`Parsed componentId '${componentId}' from identifier '${interactionIdentifier}'.`);
|
||||
|
||||
if (await cannotSendMessageInChannel({ interaction, executionId })) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Create TS Type for component
|
||||
const componentModule = await import(`../interactions/components/${componentId}.js`);
|
||||
const { default: component } = componentModule;
|
||||
const component: BaseComponentInteraction = client.componentInteractions!.get(
|
||||
componentId
|
||||
) as BaseComponentInteraction;
|
||||
if (!component) {
|
||||
logger.warn(`Interaction created but component '${componentId}' was not found.`);
|
||||
return;
|
||||
}
|
||||
|
||||
logger.debug('Executing component interaction.');
|
||||
logger.debug(`Executing component interaction '${componentId}'.`);
|
||||
await component.execute({ interaction, referenceId, executionId });
|
||||
};
|
||||
Reference in new issue
Block a user