refactor: Extract interaction handling logic into dedicated ComponentInteractionHandler, AutocompleteHandler, and CommandHandler classes.

This commit is contained in:
syntaxbullet
2025-12-24 21:38:01 +01:00
parent f13ef781b6
commit 5420653b2b
5 changed files with 96 additions and 54 deletions

View File

@@ -0,0 +1,27 @@
import { ButtonInteraction, StringSelectMenuInteraction, ModalSubmitInteraction } from "discord.js";
type ComponentInteraction = ButtonInteraction | StringSelectMenuInteraction | ModalSubmitInteraction;
/**
* Handles component interactions (buttons, select menus, modals)
* Routes to appropriate handlers based on customId patterns
*/
export class ComponentInteractionHandler {
static async handle(interaction: ComponentInteraction): Promise<void> {
const { interactionRoutes } = await import("@lib/interaction.routes");
for (const route of interactionRoutes) {
if (route.predicate(interaction)) {
const module = await route.handler();
const handlerMethod = module[route.method];
if (typeof handlerMethod === 'function') {
await handlerMethod(interaction);
return;
} else {
console.error(`Handler method ${route.method} not found in module`);
}
}
}
}
}