Move custom activity modal fields to eventUtils for use in the editing step

This commit is contained in:
Ean Milligan (Bastion) 2023-04-27 00:54:23 -04:00
parent 2a6fbdbf6c
commit 12bb1f614e
4 changed files with 46 additions and 46 deletions

View File

@ -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));
}

View File

@ -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';

View File

@ -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,
}],
}];

View File

@ -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<string> = commands.map((command) => command.details.name);
const buttonNames: Array<string> = buttons.map((button) => button.customId);