From 9569972cd625bafd1b3a5688295bc1386526ed51 Mon Sep 17 00:00:00 2001 From: syntaxbullet Date: Thu, 2 Apr 2026 11:36:22 +0200 Subject: [PATCH] docs: document interaction routing flow in CLAUDE.md Add routing table mapping custom ID prefixes to handler files and describe the ComponentInteractionHandler dispatch mechanism. Co-Authored-By: Claude Opus 4.6 (1M context) --- CLAUDE.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/CLAUDE.md b/CLAUDE.md index 076f14f..7f68b10 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -87,6 +87,30 @@ import { localHelper } from "./helper"; // relative - `*.types.ts` — Module-specific TypeScript types - `*.test.ts` — Tests (co-located with source) +### Interaction Routing + +Component interactions (buttons, select menus, modals) flow through a centralized routing system: + +``` +Discord event → interactionCreate → ComponentInteractionHandler → interaction.routes.ts → *.interaction.ts +``` + +`ComponentInteractionHandler` (`bot/lib/handlers/ComponentInteractionHandler.ts`) iterates over the route table in `bot/lib/interaction.routes.ts`. Each route has a `predicate` that matches on `customId`, a lazy `handler` import, and a `method` name to call. The handler also provides centralized `UserError` / system error handling. + +**Route table (custom ID prefix → handler):** + +| Custom ID prefix | Handler file | Method | +| ------------------ | ----------------------------------------------- | ------------------------------ | +| `trade_`, `amount` | `bot/modules/trade/trade.interaction.ts` | `handleTradeInteraction` | +| `shop_buy_` | `bot/modules/economy/shop.interaction.ts` | `handleShopInteraction` | +| `lootdrop_` | `bot/modules/economy/lootdrop.interaction.ts` | `handleLootdropInteraction` | +| `trivia_` | `bot/modules/trivia/trivia.interaction.ts` | `handleTriviaInteraction` | +| `createitem_` | `bot/modules/admin/item_wizard.ts` | `handleItemWizardInteraction` | +| `enrollment` | `bot/modules/user/enrollment.interaction.ts` | `handleEnrollmentInteraction` | +| `feedback_` | `bot/modules/feedback/feedback.interaction.ts` | `handleFeedbackInteraction` | + +Routes are evaluated in order — the first matching predicate wins. Some modules (e.g., inventory with `inv_` prefix) handle interactions locally via message component collectors instead of the global route table. + ### Command Definition ```typescript