Add documentation around fillerChar so that I don't spend 20 minutes wondering why I am adding $$$$$$$$ to things
This commit is contained in:
parent
71c0900093
commit
2a6fbdbf6c
|
@ -3,7 +3,7 @@ import { infoColor1, somethingWentWrong } from '../../commandUtils.ts';
|
||||||
import { CommandDetails } from '../../types/commandTypes.ts';
|
import { CommandDetails } from '../../types/commandTypes.ts';
|
||||||
import { Activities } from './activities.ts';
|
import { Activities } from './activities.ts';
|
||||||
import { generateActionRow, getNestedActivity } from './utils.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 { addTokenToMap, deleteTokenEarly, generateMapId, selfDestructMessage, tokenMap } from '../tokenCleanup.ts';
|
||||||
import utils from '../../utils.ts';
|
import utils from '../../utils.ts';
|
||||||
import { customId as createCustomActivityBtnId } from './step1a-openCustomModal.ts';
|
import { customId as createCustomActivityBtnId } from './step1a-openCustomModal.ts';
|
||||||
|
@ -76,7 +76,9 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
||||||
const rawIdxPath: Array<string> = interaction.data.values ? interaction.data.values[0].split(pathIdxSeparator) : [''];
|
const rawIdxPath: Array<string> = interaction.data.values ? interaction.data.values[0].split(pathIdxSeparator) : [''];
|
||||||
const idxPath: Array<number> = rawIdxPath.map((rawIdx) => rawIdx ? parseInt(rawIdx) : -1);
|
const idxPath: Array<number> = rawIdxPath.map((rawIdx) => rawIdx ? parseInt(rawIdx) : -1);
|
||||||
const selectMenus: Array<ActionRow> = [];
|
const selectMenus: Array<ActionRow> = [];
|
||||||
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 = '';
|
let currentBaseValue = '';
|
||||||
|
|
||||||
for (let i = 0; i < idxPath.length; i++) {
|
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);
|
const idxPathCopy = [...idxPath].slice(0, i);
|
||||||
selectMenus.push(generateActionRow(currentBaseValue, getNestedActivity(idxPathCopy, Activities), selectMenuCustomId, idx));
|
selectMenus.push(generateActionRow(currentBaseValue, getNestedActivity(idxPathCopy, Activities), selectMenuCustomId, idx));
|
||||||
|
|
||||||
selectMenuCustomId = `${selectMenuCustomId}$`;
|
selectMenuCustomId = `${selectMenuCustomId}${fillerChar}`;
|
||||||
currentBaseValue = `${currentBaseValue}${idx}${pathIdxSeparator}`;
|
currentBaseValue = `${currentBaseValue}${idx}${pathIdxSeparator}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
selectMenus.push(customEventRow);
|
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
|
// Let discord know we didn't ignore the user
|
||||||
await bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
|
await bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
|
||||||
type: InteractionResponseTypes.DeferredUpdateMessage,
|
type: InteractionResponseTypes.DeferredUpdateMessage,
|
||||||
|
|
|
@ -16,6 +16,7 @@ export enum LfgEmbedIndexes {
|
||||||
export const idSeparator = '@';
|
export const idSeparator = '@';
|
||||||
export const pathIdxSeparator = '|';
|
export const pathIdxSeparator = '|';
|
||||||
export const pathIdxEnder = '&';
|
export const pathIdxEnder = '&';
|
||||||
|
export const fillerChar = '$';
|
||||||
export const lfgStartTimeName = 'Start Time:';
|
export const lfgStartTimeName = 'Start Time:';
|
||||||
export const noMembersStr = 'None';
|
export const noMembersStr = 'None';
|
||||||
export const joinEventBtnStr = 'Join';
|
export const joinEventBtnStr = 'Join';
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Bot, BotWithCache, Interaction, log, LT } from '../../deps.ts';
|
import { Bot, BotWithCache, Interaction, log, LT } from '../../deps.ts';
|
||||||
import { buttons } from '../buttons/_index.ts';
|
import { buttons } from '../buttons/_index.ts';
|
||||||
import { commands } from '../commands/_index.ts';
|
import { commands } from '../commands/_index.ts';
|
||||||
import { idSeparator } from '../buttons/eventUtils.ts';
|
import { idSeparator, fillerChar } from '../buttons/eventUtils.ts';
|
||||||
|
|
||||||
const commandNames: Array<string> = commands.map((command) => command.details.name);
|
const commandNames: Array<string> = commands.map((command) => command.details.name);
|
||||||
const buttonNames: Array<string> = buttons.map((button) => button.customId);
|
const buttonNames: Array<string> = buttons.map((button) => button.customId);
|
||||||
|
@ -15,7 +15,7 @@ export const interactionCreate = (rawBot: Bot, interaction: Interaction) => {
|
||||||
return;
|
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] || '';
|
const customId = tempCustomId.split(idSeparator)[0] || '';
|
||||||
if (customId && buttonNames.includes(customId)) {
|
if (customId && buttonNames.includes(customId)) {
|
||||||
const btnIdx = buttonNames.indexOf(customId);
|
const btnIdx = buttonNames.indexOf(customId);
|
||||||
|
|
Loading…
Reference in New Issue