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

@@ -0,0 +1,8 @@
export const QUEST_CUSTOM_IDS = {
ACCEPT_PREFIX: "quest_accept:",
ACCEPT: (questId: number) => `quest_accept:${questId}`,
PAGE_PREV: "quest_page_prev",
PAGE_NEXT: "quest_page_next",
VIEW_ACTIVE: "quest_view_active",
VIEW_AVAILABLE: "quest_view_available",
} as const;

View File

@@ -8,6 +8,7 @@ import {
SeparatorSpacingSize,
MessageFlags
} from "discord.js";
import { QUEST_CUSTOM_IDS } from "./quest.types";
/**
* Quest entry with quest details and progress
@@ -169,7 +170,7 @@ export function getAvailableQuestsComponents(availableQuests: AvailableQuest[],
container.addActionRowComponents(
new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder()
.setCustomId(`quest_accept:${quest.id}`)
.setCustomId(QUEST_CUSTOM_IDS.ACCEPT(quest.id))
.setLabel("Accept Quest")
.setStyle(ButtonStyle.Success)
.setEmoji("✅")
@@ -191,12 +192,12 @@ export function getQuestActionRows(viewType: 'active' | 'available', totalItems:
if (totalPages > 1) {
rows.push(new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder()
.setCustomId("quest_page_prev")
.setCustomId(QUEST_CUSTOM_IDS.PAGE_PREV)
.setLabel("◀ Prev")
.setStyle(ButtonStyle.Secondary)
.setDisabled(page <= 0),
new ButtonBuilder()
.setCustomId("quest_page_next")
.setCustomId(QUEST_CUSTOM_IDS.PAGE_NEXT)
.setLabel("Next ▶")
.setStyle(ButtonStyle.Secondary)
.setDisabled(page >= totalPages - 1)
@@ -206,12 +207,12 @@ export function getQuestActionRows(viewType: 'active' | 'available', totalItems:
// Tab navigation row
rows.push(new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder()
.setCustomId("quest_view_active")
.setCustomId(QUEST_CUSTOM_IDS.VIEW_ACTIVE)
.setLabel("📜 Active")
.setStyle(viewType === 'active' ? ButtonStyle.Primary : ButtonStyle.Secondary)
.setDisabled(viewType === 'active'),
new ButtonBuilder()
.setCustomId("quest_view_available")
.setCustomId(QUEST_CUSTOM_IDS.VIEW_AVAILABLE)
.setLabel("🗺️ Available")
.setStyle(viewType === 'available' ? ButtonStyle.Primary : ButtonStyle.Secondary)
.setDisabled(viewType === 'available')