From 2a6fbdbf6c535e85afa129eb5cb9a671e2b77164 Mon Sep 17 00:00:00 2001 From: "Ean Milligan (Bastion)" Date: Wed, 26 Apr 2023 08:09:58 -0400 Subject: [PATCH] Add documentation around fillerChar so that I don't spend 20 minutes wondering why I am adding $$$$$$$$ to things --- src/buttons/event-creation/step1-gameSelection.ts | 10 ++++++---- src/buttons/eventUtils.ts | 1 + src/events/interactionCreate.ts | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/buttons/event-creation/step1-gameSelection.ts b/src/buttons/event-creation/step1-gameSelection.ts index 415d7e0..806c612 100644 --- a/src/buttons/event-creation/step1-gameSelection.ts +++ b/src/buttons/event-creation/step1-gameSelection.ts @@ -3,7 +3,7 @@ import { infoColor1, somethingWentWrong } from '../../commandUtils.ts'; import { CommandDetails } from '../../types/commandTypes.ts'; import { Activities } from './activities.ts'; import { generateActionRow, getNestedActivity } from './utils.ts'; -import { dateTimeFields, descriptionTextField, idSeparator, LfgEmbedIndexes, lfgStartTimeName, pathIdxEnder, pathIdxSeparator } from '../eventUtils.ts'; +import { dateTimeFields, descriptionTextField, fillerChar, idSeparator, LfgEmbedIndexes, lfgStartTimeName, pathIdxEnder, pathIdxSeparator } from '../eventUtils.ts'; import { addTokenToMap, deleteTokenEarly, generateMapId, selfDestructMessage, tokenMap } from '../tokenCleanup.ts'; import utils from '../../utils.ts'; import { customId as createCustomActivityBtnId } from './step1a-openCustomModal.ts'; @@ -76,7 +76,9 @@ const execute = async (bot: Bot, interaction: Interaction) => { const rawIdxPath: Array = interaction.data.values ? interaction.data.values[0].split(pathIdxSeparator) : ['']; const idxPath: Array = rawIdxPath.map((rawIdx) => rawIdx ? parseInt(rawIdx) : -1); const selectMenus: Array = []; - let selectMenuCustomId = `${customId}$`; + // Use fillerChar to create unique customIds for dropdowns + // We also leverage this to determine if its the first time the user has entered gameSel + let selectMenuCustomId = `${customId}${fillerChar}`; let currentBaseValue = ''; for (let i = 0; i < idxPath.length; i++) { @@ -84,13 +86,13 @@ const execute = async (bot: Bot, interaction: Interaction) => { const idxPathCopy = [...idxPath].slice(0, i); selectMenus.push(generateActionRow(currentBaseValue, getNestedActivity(idxPathCopy, Activities), selectMenuCustomId, idx)); - selectMenuCustomId = `${selectMenuCustomId}$`; + selectMenuCustomId = `${selectMenuCustomId}${fillerChar}`; currentBaseValue = `${currentBaseValue}${idx}${pathIdxSeparator}`; } selectMenus.push(customEventRow); - if (interaction.data.customId && interaction.data.customId.includes('$')) { + if (interaction.data.customId && interaction.data.customId.includes(fillerChar)) { // Let discord know we didn't ignore the user await bot.helpers.sendInteractionResponse(interaction.id, interaction.token, { type: InteractionResponseTypes.DeferredUpdateMessage, diff --git a/src/buttons/eventUtils.ts b/src/buttons/eventUtils.ts index c665f62..41baef6 100644 --- a/src/buttons/eventUtils.ts +++ b/src/buttons/eventUtils.ts @@ -16,6 +16,7 @@ export enum LfgEmbedIndexes { export const idSeparator = '@'; export const pathIdxSeparator = '|'; export const pathIdxEnder = '&'; +export const fillerChar = '$'; export const lfgStartTimeName = 'Start Time:'; export const noMembersStr = 'None'; export const joinEventBtnStr = 'Join'; diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts index c11b5ae..f097e69 100644 --- a/src/events/interactionCreate.ts +++ b/src/events/interactionCreate.ts @@ -1,7 +1,7 @@ import { Bot, BotWithCache, Interaction, log, LT } from '../../deps.ts'; import { buttons } from '../buttons/_index.ts'; import { commands } from '../commands/_index.ts'; -import { idSeparator } from '../buttons/eventUtils.ts'; +import { idSeparator, fillerChar } from '../buttons/eventUtils.ts'; const commandNames: Array = commands.map((command) => command.details.name); const buttonNames: Array = buttons.map((button) => button.customId); @@ -15,7 +15,7 @@ export const interactionCreate = (rawBot: Bot, interaction: Interaction) => { return; } - const tempCustomId = interaction.data.customId ? interaction.data.customId.replace(/\$/g, '') : ''; + const tempCustomId = interaction.data.customId ? interaction.data.customId.replaceAll(fillerChar, '') : ''; const customId = tempCustomId.split(idSeparator)[0] || ''; if (customId && buttonNames.includes(customId)) { const btnIdx = buttonNames.indexOf(customId);