diff --git a/src/buttons/event-creation/step1a-openCustomModal.ts b/src/buttons/event-creation/step1a-openCustomModal.ts index b04eb75..16f6f7c 100644 --- a/src/buttons/event-creation/step1a-openCustomModal.ts +++ b/src/buttons/event-creation/step1a-openCustomModal.ts @@ -1,16 +1,12 @@ -import { Bot, Interaction, InteractionResponseTypes, MessageComponentTypes, TextStyles } from '../../../deps.ts'; +import { Bot, Interaction, InteractionResponseTypes } from '../../../deps.ts'; import { deleteTokenEarly } from '../tokenCleanup.ts'; -import { idSeparator, pathIdxSeparator } from '../eventUtils.ts'; +import { generateCustomActivityFields, idSeparator, pathIdxSeparator } from '../eventUtils.ts'; import { customId as verifyCustomActivityId } from './step1b-verifyCustomActivity.ts'; import utils from '../../utils.ts'; import { dbClient, queries } from '../../db.ts'; export const customId = 'customAct'; -export const activityTitleId = 'activityTitle'; -export const activitySubtitleId = 'activitySubtitle'; -export const activityMaxPlayersId = 'activityMaxPlayers'; - const execute = async (bot: Bot, interaction: Interaction) => { if (interaction.data?.customId && interaction.member && interaction.guildId && interaction.channelId) { // Light Telemetry @@ -24,43 +20,7 @@ const execute = async (bot: Bot, interaction: Interaction) => { data: { title: 'Create Custom Activity', customId: verifyCustomActivityId, - components: [{ - type: MessageComponentTypes.ActionRow, - components: [{ - type: MessageComponentTypes.InputText, - customId: activityTitleId, - label: 'Activity Title:', - placeholder: 'The name of the game or event.', - style: TextStyles.Short, - minLength: 1, - maxLength: 35, - value: actTitle || undefined, - }], - }, { - type: MessageComponentTypes.ActionRow, - components: [{ - type: MessageComponentTypes.InputText, - customId: activitySubtitleId, - label: 'Activity Subtitle:', - placeholder: 'The specific activity within the game or event.', - style: TextStyles.Short, - minLength: 1, - maxLength: 50, - value: actSubtitle || undefined, - }], - }, { - type: MessageComponentTypes.ActionRow, - components: [{ - type: MessageComponentTypes.InputText, - customId: activityMaxPlayersId, - label: 'Maximum Players:', - placeholder: 'Please enter a number between 1 and 99.', - style: TextStyles.Short, - minLength: 1, - maxLength: 2, - value: activityMaxPlayers || undefined, - }], - }], + components: generateCustomActivityFields(actTitle, actSubtitle, activityMaxPlayers), }, }).catch((e: Error) => utils.commonLoggers.interactionSendError('step1a-openCustomModal.ts:modal', interaction, e)); } diff --git a/src/buttons/event-creation/step1b-verifyCustomActivity.ts b/src/buttons/event-creation/step1b-verifyCustomActivity.ts index 36e64a0..8101a9c 100644 --- a/src/buttons/event-creation/step1b-verifyCustomActivity.ts +++ b/src/buttons/event-creation/step1b-verifyCustomActivity.ts @@ -1,9 +1,8 @@ import config from '../../../config.ts'; import { ApplicationCommandFlags, Bot, ButtonStyles, Interaction, InteractionResponseTypes, MessageComponentTypes } from '../../../deps.ts'; import { failColor, infoColor1, safelyDismissMsg, somethingWentWrong } from '../../commandUtils.ts'; -import { idSeparator, pathIdxEnder, pathIdxSeparator } from '../eventUtils.ts'; +import { activityMaxPlayersId, activitySubtitleId, activityTitleId, idSeparator, pathIdxEnder, pathIdxSeparator } from '../eventUtils.ts'; import { addTokenToMap, selfDestructMessage } from '../tokenCleanup.ts'; -import { activityMaxPlayersId, activitySubtitleId, activityTitleId } from './step1a-openCustomModal.ts'; import { customId as gameSelectionId } from './step1-gameSelection.ts'; import { customId as openCustomModalId } from './step1a-openCustomModal.ts'; import utils from '../../utils.ts'; diff --git a/src/buttons/eventUtils.ts b/src/buttons/eventUtils.ts index 41baef6..c86c517 100644 --- a/src/buttons/eventUtils.ts +++ b/src/buttons/eventUtils.ts @@ -91,3 +91,44 @@ export const dateTimeFields = (prefillTime = '', prefillTimeZone = '', prefillDa value: prefillDate || undefined, }], }]; + +export const activityTitleId = 'activityTitle'; +export const activitySubtitleId = 'activitySubtitle'; +export const activityMaxPlayersId = 'activityMaxPlayers'; +export const generateCustomActivityFields = (actTitle = '', actSubtitle = '', activityMaxPlayers = ''): ActionRow[] => [{ + type: MessageComponentTypes.ActionRow, + components: [{ + type: MessageComponentTypes.InputText, + customId: activityTitleId, + label: 'Activity Title:', + placeholder: 'The name of the game or event.', + style: TextStyles.Short, + minLength: 1, + maxLength: 35, + value: actTitle || undefined, + }], +}, { + type: MessageComponentTypes.ActionRow, + components: [{ + type: MessageComponentTypes.InputText, + customId: activitySubtitleId, + label: 'Activity Subtitle:', + placeholder: 'The specific activity within the game or event.', + style: TextStyles.Short, + minLength: 1, + maxLength: 50, + value: actSubtitle || undefined, + }], +}, { + type: MessageComponentTypes.ActionRow, + components: [{ + type: MessageComponentTypes.InputText, + customId: activityMaxPlayersId, + label: 'Maximum Players:', + placeholder: 'Please enter a number between 1 and 99.', + style: TextStyles.Short, + minLength: 1, + maxLength: 2, + value: activityMaxPlayers || undefined, + }], +}]; diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts index f097e69..1624abc 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, fillerChar } from '../buttons/eventUtils.ts'; +import { fillerChar, idSeparator } from '../buttons/eventUtils.ts'; const commandNames: Array = commands.map((command) => command.details.name); const buttonNames: Array = buttons.map((button) => button.customId);