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

@@ -1,5 +1,6 @@
import { MessageFlags } from "discord.js";
import type { TriviaSession, TriviaResult } from "@shared/modules/trivia/trivia.service";
import { TRIVIA_CUSTOM_IDS } from "./trivia.types";
/**
* Get color based on difficulty level
@@ -97,14 +98,14 @@ export function getTriviaQuestionView(session: TriviaSession, username: string):
components: [
{
type: 2, // Button
custom_id: `trivia_answer_${sessionId}_${trueIndex}`,
custom_id: TRIVIA_CUSTOM_IDS.ANSWER(sessionId, trueIndex),
label: 'True',
style: 3, // Success
emoji: { name: '✅' }
},
{
type: 2, // Button
custom_id: `trivia_answer_${sessionId}_${falseIndex}`,
custom_id: TRIVIA_CUSTOM_IDS.ANSWER(sessionId, falseIndex),
label: 'False',
style: 4, // Danger
emoji: { name: '❌' }
@@ -129,7 +130,7 @@ export function getTriviaQuestionView(session: TriviaSession, username: string):
buttonRow.components.push({
type: 2, // Button
custom_id: `trivia_answer_${sessionId}_${i}`,
custom_id: TRIVIA_CUSTOM_IDS.ANSWER(sessionId, i),
label: `${label}: ${answer.substring(0, 30)}${answer.length > 30 ? '...' : ''}`,
style: 2, // Secondary
emoji: { name: emoji }
@@ -145,7 +146,7 @@ export function getTriviaQuestionView(session: TriviaSession, username: string):
components: [
{
type: 2, // Button
custom_id: `trivia_giveup_${sessionId}`,
custom_id: TRIVIA_CUSTOM_IDS.GIVE_UP(sessionId),
label: 'Give Up',
style: 4, // Danger
emoji: { name: '🏳️' }
@@ -245,7 +246,7 @@ export function getTriviaResultView(
buttonRow.components.push({
type: 2, // Button
custom_id: `trivia_result_${i}`,
custom_id: TRIVIA_CUSTOM_IDS.RESULT(i),
label: `${label}: ${answer.substring(0, 30)}${answer.length > 30 ? '...' : ''}`,
style: isCorrect ? 3 : wasUserAnswer ? 4 : 2, // Success : Danger : Secondary
emoji: { name: isCorrect ? '✅' : wasUserAnswer ? '❌' : emoji },
@@ -318,7 +319,7 @@ export function getTriviaTimeoutView(
buttonRow.components.push({
type: 2, // Button
custom_id: `trivia_timeout_${i}`,
custom_id: TRIVIA_CUSTOM_IDS.TIMEOUT(i),
label: `${label}: ${answer.substring(0, 30)}${answer.length > 30 ? '...' : ''}`,
style: isCorrect ? 3 : 2, // Success : Secondary
emoji: { name: isCorrect ? '✅' : emoji },