From 5ab19bf826be75af2c5e7e01bac42b63dae1f963 Mon Sep 17 00:00:00 2001 From: syntaxbullet Date: Wed, 24 Dec 2025 20:23:52 +0100 Subject: [PATCH] fix: improve feedback type parsing from custom IDs and add validation for feedback types in interaction and view logic. --- src/modules/feedback/feedback.interaction.ts | 14 +++++++++++++- src/modules/feedback/feedback.view.ts | 6 ++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/modules/feedback/feedback.interaction.ts b/src/modules/feedback/feedback.interaction.ts index 9f50009..1b3b09d 100644 --- a/src/modules/feedback/feedback.interaction.ts +++ b/src/modules/feedback/feedback.interaction.ts @@ -27,7 +27,19 @@ export const handleFeedbackInteraction = async (interaction: Interaction) => { // Handle modal submission if (interaction.isModalSubmit() && interaction.customId.startsWith(FEEDBACK_CUSTOM_IDS.MODAL)) { // Extract feedback type from customId (format: feedback_modal_FEATURE_REQUEST) - const feedbackType = interaction.customId.split("_")[2] as FeedbackType; + const parts = interaction.customId.split("_"); + const feedbackType = parts.slice(2).join("_") as FeedbackType; + + console.log(`Processing feedback modal. CustomId: ${interaction.customId}, Extracted type: ${feedbackType}`); + + if (!feedbackType || !["FEATURE_REQUEST", "BUG_REPORT", "GENERAL"].includes(feedbackType)) { + console.error(`Invalid feedback type extracted: ${feedbackType} from customId: ${interaction.customId}`); + await interaction.reply({ + embeds: [createErrorEmbed("An error occurred processing your feedback. Please try again.")], + ephemeral: true + }); + return; + } if (!config.feedbackChannelId) { await interaction.reply({ diff --git a/src/modules/feedback/feedback.view.ts b/src/modules/feedback/feedback.view.ts index a105064..6d40fef 100644 --- a/src/modules/feedback/feedback.view.ts +++ b/src/modules/feedback/feedback.view.ts @@ -94,6 +94,12 @@ export function buildFeedbackMessage(feedback: FeedbackData) { }; const theme = themes[feedback.type]; + + if (!theme) { + console.error(`Unknown feedback type: ${feedback.type}`); + throw new Error(`Invalid feedback type: ${feedback.type}`); + } + const timestamp = Math.floor(feedback.timestamp.getTime() / 1000); // Header Container