refactor: centralize custom interaction IDs into constants

Replace all hardcoded custom ID strings with module-level constants.
Each module now has *_CUSTOM_IDS in its types file, using functions
for dynamic IDs and PREFIX for startsWith matching.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
syntaxbullet
2026-04-02 11:36:35 +02:00
parent 70d59a091a
commit 3c256ba0b2
27 changed files with 238 additions and 132 deletions

View File

@@ -12,6 +12,7 @@ import { inventoryService } from "@shared/modules/inventory/inventory.service";
import { createErrorEmbed, createWarningEmbed, createSuccessEmbed, createInfoEmbed } from "@lib/embeds";
import { UserError } from "@shared/lib/errors";
import { getTradeDashboard, getTradeMoneyModal, getItemSelectMenu, getTradeCompletedEmbed } from "./trade.view";
import { TRADE_CUSTOM_IDS } from "./trade.types";
@@ -23,25 +24,25 @@ export async function handleTradeInteraction(interaction: Interaction) {
if (!threadId) return;
if (customId === 'trade_cancel') {
if (customId === TRADE_CUSTOM_IDS.CANCEL) {
await handleCancel(interaction, threadId);
} else if (customId === 'trade_lock') {
} else if (customId === TRADE_CUSTOM_IDS.LOCK) {
await handleLock(interaction, threadId);
} else if (customId === 'trade_confirm') {
} else if (customId === TRADE_CUSTOM_IDS.CONFIRM) {
// Confirm logic is handled implicitly by both locking or explicitly if needed.
// For now, locking both triggers execution, so no separate confirm handler is actively used
// unless we re-introduce a specific button. keeping basic handler stub if needed.
} else if (customId === 'trade_add_money') {
} else if (customId === TRADE_CUSTOM_IDS.ADD_MONEY) {
await handleAddMoneyClick(interaction);
} else if (customId === 'trade_money_modal') {
} else if (customId === TRADE_CUSTOM_IDS.MONEY_MODAL) {
await handleMoneySubmit(interaction as ModalSubmitInteraction, threadId);
} else if (customId === 'trade_add_item') {
} else if (customId === TRADE_CUSTOM_IDS.ADD_ITEM) {
await handleAddItemClick(interaction as ButtonInteraction, threadId);
} else if (customId === 'trade_select_item') {
} else if (customId === TRADE_CUSTOM_IDS.SELECT_ITEM) {
await handleItemSelect(interaction as StringSelectMenuInteraction, threadId);
} else if (customId === 'trade_remove_item') {
} else if (customId === TRADE_CUSTOM_IDS.REMOVE_ITEM) {
await handleRemoveItemClick(interaction as ButtonInteraction, threadId);
} else if (customId === 'trade_remove_item_select') {
} else if (customId === TRADE_CUSTOM_IDS.REMOVE_ITEM_SELECT) {
await handleRemoveItemSelect(interaction as StringSelectMenuInteraction, threadId);
}
}
@@ -82,7 +83,7 @@ async function handleAddMoneyClick(interaction: Interaction) {
}
async function handleMoneySubmit(interaction: ModalSubmitInteraction, threadId: string) {
const amountStr = interaction.fields.getTextInputValue('amount');
const amountStr = interaction.fields.getTextInputValue(TRADE_CUSTOM_IDS.MONEY_AMOUNT_FIELD);
const amount = BigInt(amountStr);
if (amount < 0n) throw new UserError("Amount must be positive");
@@ -107,7 +108,7 @@ async function handleAddItemClick(interaction: ButtonInteraction, threadId: stri
description: `Rarity: ${entry.item.rarity} `
}));
const { components } = getItemSelectMenu(options, 'trade_select_item', 'Select an item to add');
const { components } = getItemSelectMenu(options, TRADE_CUSTOM_IDS.SELECT_ITEM, 'Select an item to add');
await interaction.reply({ content: "Select an item to add:", components, ephemeral: true });
}
@@ -142,7 +143,7 @@ async function handleRemoveItemClick(interaction: ButtonInteraction, threadId: s
value: i.id.toString(),
}));
const { components } = getItemSelectMenu(options, 'trade_remove_item_select', 'Select an item to remove');
const { components } = getItemSelectMenu(options, TRADE_CUSTOM_IDS.REMOVE_ITEM_SELECT, 'Select an item to remove');
await interaction.reply({ content: "Select an item to remove:", components, ephemeral: true });
}