Fixes member count parsing and error handling, start adding finalize step
This commit is contained in:
parent
50aa8d204c
commit
37a46d82f0
|
@ -2,5 +2,6 @@ import { Button } from '../types/commandTypes.ts';
|
||||||
import { createEventButton } from './event-creation/step1-gameSelection.ts';
|
import { createEventButton } from './event-creation/step1-gameSelection.ts';
|
||||||
import { createCustomEventButton } from './event-creation/step1a-openCustomModal.ts';
|
import { createCustomEventButton } from './event-creation/step1a-openCustomModal.ts';
|
||||||
import { verifyCustomEventButton } from './event-creation/step1b-verifyCustomActivity.ts';
|
import { verifyCustomEventButton } from './event-creation/step1b-verifyCustomActivity.ts';
|
||||||
|
import { finalizeEventButton } from './event-creation/step2-finalize.ts';
|
||||||
|
|
||||||
export const buttons: Array<Button> = [createEventButton, createCustomEventButton, verifyCustomEventButton];
|
export const buttons: Array<Button> = [createEventButton, createCustomEventButton, verifyCustomEventButton, finalizeEventButton];
|
||||||
|
|
|
@ -2,11 +2,16 @@ import { ActionRow, ApplicationCommandFlags, ApplicationCommandTypes, Bot, Butto
|
||||||
import { infoColor1, somethingWentWrong } from '../../commandUtils.ts';
|
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 { deleteTokenEarly, generateActionRow, generateMapId, getNestedActivity, pathIdxEnder, idSeparator, pathIdxSeparator, tokenMap, addTokenToMap, tokenTimeoutMS, selfDestructMessage } from './utils.ts';
|
import { deleteTokenEarly, generateActionRow, generateMapId, getNestedActivity, pathIdxEnder, idSeparator, pathIdxSeparator, tokenMap, addTokenToMap, selfDestructMessage } from './utils.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';
|
||||||
|
import { customId as finalizeEventBtnId } from './step2-finalize.ts';
|
||||||
|
|
||||||
export const customId = 'gameSel';
|
export const customId = 'gameSel';
|
||||||
|
export const eventTimeId = 'eventTime';
|
||||||
|
export const eventTimeZoneId = 'eventTimeZone';
|
||||||
|
export const eventDateId = 'eventDate';
|
||||||
|
export const eventDescriptionId = 'eventDescription';
|
||||||
const slashCommandName = 'create-event';
|
const slashCommandName = 'create-event';
|
||||||
const details: CommandDetails = {
|
const details: CommandDetails = {
|
||||||
name: slashCommandName,
|
name: slashCommandName,
|
||||||
|
@ -38,13 +43,14 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
||||||
type: InteractionResponseTypes.Modal,
|
type: InteractionResponseTypes.Modal,
|
||||||
data: {
|
data: {
|
||||||
title: 'Enter Event Details',
|
title: 'Enter Event Details',
|
||||||
customId: `temp${idSeparator}${finalizedIdxPath}`, //TODO: finish
|
customId: `${finalizeEventBtnId}${idSeparator}${finalizedIdxPath}`,
|
||||||
components: [{
|
components: [{
|
||||||
type: MessageComponentTypes.ActionRow,
|
type: MessageComponentTypes.ActionRow,
|
||||||
components: [{
|
components: [{
|
||||||
type: MessageComponentTypes.InputText,
|
type: MessageComponentTypes.InputText,
|
||||||
customId: 'eventTime',
|
customId: eventTimeId,
|
||||||
label: 'Start Time:',
|
label: 'Start Time:',
|
||||||
|
placeholder: 'Enter the start time as "HH:MM AM/PM"',
|
||||||
style: TextStyles.Short,
|
style: TextStyles.Short,
|
||||||
minLength: 1,
|
minLength: 1,
|
||||||
maxLength: 8,
|
maxLength: 8,
|
||||||
|
@ -53,8 +59,9 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
||||||
type: MessageComponentTypes.ActionRow,
|
type: MessageComponentTypes.ActionRow,
|
||||||
components: [{
|
components: [{
|
||||||
type: MessageComponentTypes.InputText,
|
type: MessageComponentTypes.InputText,
|
||||||
customId: 'eventTimeZone',
|
customId: eventTimeZoneId,
|
||||||
label: 'Time Zone:',
|
label: 'Time Zone:',
|
||||||
|
placeholder: 'Enter your time zone abbreviation (UTC±## also works)',
|
||||||
style: TextStyles.Short,
|
style: TextStyles.Short,
|
||||||
minLength: 2,
|
minLength: 2,
|
||||||
maxLength: 8,
|
maxLength: 8,
|
||||||
|
@ -63,8 +70,9 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
||||||
type: MessageComponentTypes.ActionRow,
|
type: MessageComponentTypes.ActionRow,
|
||||||
components: [{
|
components: [{
|
||||||
type: MessageComponentTypes.InputText,
|
type: MessageComponentTypes.InputText,
|
||||||
customId: 'eventDate',
|
customId: eventDateId,
|
||||||
label: 'Start Date:',
|
label: 'Start Date:',
|
||||||
|
placeholder: 'Enter date as "MONTH/DAY" or "Month, Day"',
|
||||||
style: TextStyles.Short,
|
style: TextStyles.Short,
|
||||||
minLength: 1,
|
minLength: 1,
|
||||||
maxLength: 20,
|
maxLength: 20,
|
||||||
|
@ -73,11 +81,11 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
||||||
type: MessageComponentTypes.ActionRow,
|
type: MessageComponentTypes.ActionRow,
|
||||||
components: [{
|
components: [{
|
||||||
type: MessageComponentTypes.InputText,
|
type: MessageComponentTypes.InputText,
|
||||||
customId: 'eventDescription',
|
customId: eventDescriptionId,
|
||||||
label: 'Description:',
|
label: 'Description:',
|
||||||
|
placeholder: 'Briefly describe the event',
|
||||||
style: TextStyles.Paragraph,
|
style: TextStyles.Paragraph,
|
||||||
required: false,
|
required: false,
|
||||||
placeholder: finalizedIdxPath,
|
|
||||||
minLength: 0,
|
minLength: 0,
|
||||||
maxLength: 1000,
|
maxLength: 1000,
|
||||||
}],
|
}],
|
||||||
|
|
|
@ -24,12 +24,7 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
||||||
const activityTitle = (tempDataMap.get(activityTitleId) || '').replace(/\|/g, '');
|
const activityTitle = (tempDataMap.get(activityTitleId) || '').replace(/\|/g, '');
|
||||||
const activitySubtitle = (tempDataMap.get(activitySubtitleId) || '').replace(/\|/g, '');
|
const activitySubtitle = (tempDataMap.get(activitySubtitleId) || '').replace(/\|/g, '');
|
||||||
const activityMaxPlayers = parseInt(tempDataMap.get(activityMaxPlayersId) || '0');
|
const activityMaxPlayers = parseInt(tempDataMap.get(activityMaxPlayersId) || '0');
|
||||||
if (!activityMaxPlayers || !activitySubtitle || !activityTitle) {
|
if (isNaN(activityMaxPlayers) || activityMaxPlayers < 1 || activityMaxPlayers > 99) {
|
||||||
// Verify fields exist
|
|
||||||
somethingWentWrong(bot, interaction, `missingFieldFromCustomActivity@${activityTitle}|${activitySubtitle}|${activityMaxPlayers}$`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (activityMaxPlayers < 1 || activityMaxPlayers > 99) {
|
|
||||||
bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
|
bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
|
||||||
type: InteractionResponseTypes.ChannelMessageWithSource,
|
type: InteractionResponseTypes.ChannelMessageWithSource,
|
||||||
data: {
|
data: {
|
||||||
|
@ -37,12 +32,17 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
||||||
embeds: [{
|
embeds: [{
|
||||||
color: failColor,
|
color: failColor,
|
||||||
title: 'Invalid Max Member count!',
|
title: 'Invalid Max Member count!',
|
||||||
description: `${config.name} parsed the max members as ${activityMaxPlayers}, which is outside of the allowed range. Please recreate this activity, but make sure the maximum player count is between 1 and 99.\n\n${safelyDismissMsg}`
|
description: `${config.name} parsed the max members as \`${isNaN(activityMaxPlayers) ? 'Not a Number' : activityMaxPlayers}\`, which is outside of the allowed range. Please recreate this activity, but make sure the maximum player count is between 1 and 99.\n\n${safelyDismissMsg}`
|
||||||
}],
|
}],
|
||||||
}
|
}
|
||||||
}).catch((e: Error) => utils.commonLoggers.interactionSendError('step1b-verifyCustomActivity.ts:invalidPlayer', interaction, e));
|
}).catch((e: Error) => utils.commonLoggers.interactionSendError('step1b-verifyCustomActivity.ts:invalidPlayer', interaction, e));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!activityMaxPlayers || !activitySubtitle || !activityTitle) {
|
||||||
|
// Verify fields exist
|
||||||
|
somethingWentWrong(bot, interaction, `missingFieldFromCustomActivity@${activityTitle}|${activitySubtitle}|${activityMaxPlayers}$`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
addTokenToMap(bot, interaction, interaction.guildId, interaction.channelId, interaction.member.id);
|
addTokenToMap(bot, interaction, interaction.guildId, interaction.channelId, interaction.member.id);
|
||||||
const idxPath = `${idSeparator}${activityTitle}${pathIdxSeparator}${activitySubtitle}${pathIdxSeparator}${activityMaxPlayers}`;
|
const idxPath = `${idSeparator}${activityTitle}${pathIdxSeparator}${activitySubtitle}${pathIdxSeparator}${activityMaxPlayers}`;
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
import { Bot, Interaction, InteractionResponseTypes, MessageComponentTypes, TextStyles } from '../../../deps.ts';
|
||||||
|
import { somethingWentWrong } from '../../commandUtils.ts';
|
||||||
|
import { eventTimeId, eventTimeZoneId, eventDateId, eventDescriptionId } from './step1-gameSelection.ts';
|
||||||
|
|
||||||
|
export const customId = 'finalize';
|
||||||
|
|
||||||
|
const execute = async (bot: Bot, interaction: Interaction) => {
|
||||||
|
if (interaction?.data?.components?.length && interaction.guildId && interaction.channelId && interaction.member) {
|
||||||
|
const tempDataMap: Map<string, string> = new Map();
|
||||||
|
for (const row of interaction.data.components) {
|
||||||
|
if (row.components?.[0]) {
|
||||||
|
const textField = row.components[0];
|
||||||
|
tempDataMap.set(textField.customId || 'missingCustomId', textField.value || 'missingValue');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(interaction.data.customId)
|
||||||
|
const rawEventTime = tempDataMap.get(eventTimeId) || '';
|
||||||
|
const rawEventTimeZone = tempDataMap.get(eventTimeZoneId) || '';
|
||||||
|
const rawEventDate = tempDataMap.get(eventDateId) || '';
|
||||||
|
const eventDescription = tempDataMap.get(eventDescriptionId) || 'No Description Provided.';
|
||||||
|
if (!rawEventTime || !rawEventTimeZone || !rawEventDate) {
|
||||||
|
// Error out if user somehow failed to provide one of the fields (eventDescription is allowed to be null/empty)
|
||||||
|
somethingWentWrong(bot, interaction, `missingFieldFromEventDescription@${rawEventTime}_${rawEventTimeZone}_${rawEventDate}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
somethingWentWrong(bot, interaction, `missingFieldFromEventDescription@${rawEventTime}_${rawEventTimeZone}_${rawEventDate}`);
|
||||||
|
} else {
|
||||||
|
somethingWentWrong(bot, interaction, 'noDataFromEventDescriptionModal');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const finalizeEventButton = {
|
||||||
|
customId,
|
||||||
|
execute,
|
||||||
|
};
|
Loading…
Reference in New Issue