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) <noreply@anthropic.com>
This commit is contained in:
syntaxbullet
2026-04-02 11:36:22 +02:00
parent 5bd390b4ee
commit 9569972cd6

View File

@@ -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