Add class for interactions

This commit is contained in:
Marius Begby committed 2023-08-31 17:36:16 +02:00
1 parent d0f1e940a5
commit b96a73df6f
37 files changed
+1038 -1012

No files matched your search

+17 -6
View File
@@ -1,20 +1,31 @@
import { AutocompleteInteraction } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../services/logger';
import { ExtendedClient } from '../types/clientTypes';
import { BaseAutocompleteInteraction } from '../types/interactionTypes';
export const handleAutocomplete = async (interaction: AutocompleteInteraction, executionId: string) => {
export const handleAutocomplete = async (
interaction: AutocompleteInteraction,
client: ExtendedClient,
executionId: string,
interactionIdentifier: string
) => {
// TODO: Define TS Type for handlers, and require logger constant?
const logger: Logger = loggerModule.child({
source: 'interactionCutocompleteHandler.ts',
source: 'interactionAutocompleteHandler.ts',
module: 'handler',
name: 'interactionAutocompleteHandler',
executionId: executionId
});
// TODO: Create TS Type for autocompleteModule
const autocompleteModule = await import(`../interactions/autocomplete/${interaction.commandName}.js`);
const { default: autocomplete } = autocompleteModule;
const autocomplete: BaseAutocompleteInteraction = client.autocompleteInteractions!.get(
interactionIdentifier
) as BaseAutocompleteInteraction;
if (!autocomplete) {
logger.warn(`Interaction created but autocomplete '${interactionIdentifier}' was not found.`);
return;
}
logger.debug('Executing autocomplete interaction.');
logger.debug(`Executing autocomplete interaction '${interactionIdentifier}'.`);
await autocomplete.execute({ interaction, executionId });
};