Ultima attività 4 weeks ago

.ts Raw
1export async function handleInteraction(interaction: Interaction): Promise<void> {
2 try {
3 if (interaction.isAutocomplete()) {
4 await handleAutocomplete(interaction);
5 return;
6 }
7
8 if (interaction.isButton()) {
9 const btn = interaction as ButtonInteraction;
10
11 console.log("[interactions] interaction btnId:", btn.customId);
12 if (btn.customId.startsWith("conflict_")) {
13 console.log("[interactions] routing to conflict handler:", btn.customId);
14 return await handleConflictButton(btn);
15 }
16
17 if (btn.customId.startsWith("impersonate_")) {
18 return await handleImpersonateButton(btn);
19 }
20
21 if (btn.customId.startsWith("switch_after_reclaim:")) {
22 return await handleSwitchAfterReclaim(btn);
23 }
24
25 if (btn.customId.startsWith("borrow_accept:")) {
26 const [, ownerKey, requesterKey] = btn.customId.split(":");
27 return await handleBorrowAcceptButton(btn, ownerKey, requesterKey);
28 }
29
30 if (btn.customId.startsWith("borrow_decline:")) {
31 const [, ownerKey, requesterKey] = btn.customId.split(":");
32 return await handleBorrowDeclineButton(btn, ownerKey, requesterKey);
33 }
34
35 if (btn.customId === "tg_score_submit") {
36 return await handleScoreSubmitButton(btn);
37 }
38
39 if (btn.customId.startsWith("companion_switch:")) {
40 return await handleSwitchAfterReclaim(btn);
41 }
42
43 return await handleButton(btn);
44 }
45
46 if (interaction.isModalSubmit()) {
47 return await modals.handleModal(interaction);
48 }
49
50 if (interaction.isStringSelectMenu()) {
51 const sel = interaction as StringSelectMenuInteraction;
52 if (sel.customId.startsWith("score_slot_select:")) {
53 const userKey = sel.customId.split(":")[1];
54 const slot = parseInt(sel.values[0], 10);
55 await sel.showModal(modals.buildScoreModal(userKey, slot));
56 return;
57 }
58 }
59
60 if (interaction.isChatInputCommand()) {
61 const cmd = interaction as ChatInputCommandInteraction;
62 if (cmd.commandName === "tg") await handleTgCommand(cmd);
63 if (cmd.commandName === "tg-config") await handleTgConfigCommand(cmd);
64 if (cmd.commandName === "tg-admin") await handleTgAdminCommand(cmd);
65 }
66 } catch (err) {
67 console.error("Interaction error:", err);
68 try {
69 const msg = { content: "❌ An error occurred.", ephemeral: true };
70 if ((interaction as any).replied || (interaction as any).deferred) {
71 await (interaction as any).followUp(msg);
72 } else {
73 await (interaction as any).reply(msg);
74 }
75 } catch {}
76 }
77}