diff --git a/src/buttons/event-creation/step2-finalize.ts b/src/buttons/event-creation/step2-finalize.ts index 5bef924..d8f187b 100644 --- a/src/buttons/event-creation/step2-finalize.ts +++ b/src/buttons/event-creation/step2-finalize.ts @@ -1,6 +1,8 @@ import { Bot, Interaction, InteractionResponseTypes, MessageComponentTypes, TextStyles } from '../../../deps.ts'; import { somethingWentWrong } from '../../commandUtils.ts'; import { eventTimeId, eventTimeZoneId, eventDateId, eventDescriptionId } from './step1-gameSelection.ts'; +import { getFinalActivity, getNestedActivity, idSeparator, pathIdxSeparator } from './utils.ts'; +import { Activities, Activity } from './activities.ts'; export const customId = 'finalize'; @@ -14,7 +16,29 @@ const execute = async (bot: Bot, interaction: Interaction) => { } } - console.log(interaction.data.customId) + const customIdIdxPath = ((interaction.data.customId || '').substring((interaction.data.customId || '').indexOf(idSeparator) + 1) || ''); + const rawIdxPath: Array = customIdIdxPath.split(pathIdxSeparator); + const idxPath: Array = rawIdxPath.map((rawIdx) => rawIdx ? parseInt(rawIdx) : -1); + let category: string; + let activity: Activity; + if (idxPath.some(idx => isNaN(idx) || idx < 0)) { + // Handle custom activity + category = rawIdxPath[0]; + activity = { + name: rawIdxPath[1], + maxMembers: parseInt(rawIdxPath[2]) || NaN, + }; + } else { + // Handle preset activity + category = Activities[idxPath[0]].name; + activity = getFinalActivity(idxPath, Activities) + } + + if (!category || !activity.name || !activity.maxMembers || isNaN(activity.maxMembers)) { + // Error out if our activity or category is missing + somethingWentWrong(bot, interaction, `missingActivityFromFinalize@${category}_${activity.name}_${activity.maxMembers}`); + } + const rawEventTime = tempDataMap.get(eventTimeId) || ''; const rawEventTimeZone = tempDataMap.get(eventTimeZoneId) || ''; const rawEventDate = tempDataMap.get(eventDateId) || ''; @@ -24,7 +48,35 @@ const execute = async (bot: Bot, interaction: Interaction) => { somethingWentWrong(bot, interaction, `missingFieldFromEventDescription@${rawEventTime}_${rawEventTimeZone}_${rawEventDate}`); return; } - somethingWentWrong(bot, interaction, `missingFieldFromEventDescription@${rawEventTime}_${rawEventTimeZone}_${rawEventDate}`); + + // Verify/Set Time + let parsedEventTime = rawEventTime.replaceAll(':', '').toUpperCase(); + let parsedEventTimePeriod = ''; + // Get AM or PM out of the rawTime + if (parsedEventTime.endsWith('AM') || parsedEventTime.endsWith('PM')) { + parsedEventTimePeriod = parsedEventTime.slice(-2); + parsedEventTime = parsedEventTime.slice(0, -2).trim(); + } + let parsedEventTimeHours: string; + let parsedEventTimeMinutes: string; + // Get Hours and Minutes out of rawTime + if (parsedEventTime.length > 2) { + parsedEventTimeMinutes = parsedEventTime.slice(-2); + parsedEventTimeHours = parsedEventTime.slice(0, -2).trim(); + } else { + parsedEventTimeHours = parsedEventTime.trim(); + parsedEventTimeMinutes = '00' + } + // Determine if we need to remove the time period + if (parseInt(parsedEventTimeHours) > 12) { + parsedEventTimePeriod = ''; + } + + // Verify/Set Time Zone + + // Verify/Set Date + + somethingWentWrong(bot, interaction, `TESTING@${rawEventTime}_${rawEventTimeZone}_${rawEventDate}`); } else { somethingWentWrong(bot, interaction, 'noDataFromEventDescriptionModal'); } diff --git a/src/buttons/event-creation/utils.ts b/src/buttons/event-creation/utils.ts index 9544872..e2b90f8 100644 --- a/src/buttons/event-creation/utils.ts +++ b/src/buttons/event-creation/utils.ts @@ -9,6 +9,8 @@ export const idSeparator = '@'; export const pathIdxSeparator = '|'; export const pathIdxEnder = '&'; export const selfDestructMessage = (currentTime: number) => `**Please note:** This message will self destruct due to limits imposed by the Discord API.`; +export const monthsLong: Array = ["JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"]; +export const monthsShort: Array = monthsLong.map(month => month.slice(0, 3)); export const tzMap: Map = new Map([ ['CDT', '-05:00'], ['CST', '-06:00'], @@ -77,6 +79,8 @@ export const getNestedActivity = (idxPath: Array, activities: Array, activities: Array): Activity => getNestedActivity(idxPath, activities)[idxPath[idxPath.length - 1]]; + const getSelectOptions = (baseValue: string, activities: Array, defaultIdx?: number): Array => activities.map((act, idx) => ({ label: act.name,