Parse event category/activity and time from user input
This commit is contained in:
parent
37a46d82f0
commit
6e92407fc9
|
@ -1,6 +1,8 @@
|
||||||
import { Bot, Interaction, InteractionResponseTypes, MessageComponentTypes, TextStyles } from '../../../deps.ts';
|
import { Bot, Interaction, InteractionResponseTypes, MessageComponentTypes, TextStyles } from '../../../deps.ts';
|
||||||
import { somethingWentWrong } from '../../commandUtils.ts';
|
import { somethingWentWrong } from '../../commandUtils.ts';
|
||||||
import { eventTimeId, eventTimeZoneId, eventDateId, eventDescriptionId } from './step1-gameSelection.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';
|
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<string> = customIdIdxPath.split(pathIdxSeparator);
|
||||||
|
const idxPath: Array<number> = 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 rawEventTime = tempDataMap.get(eventTimeId) || '';
|
||||||
const rawEventTimeZone = tempDataMap.get(eventTimeZoneId) || '';
|
const rawEventTimeZone = tempDataMap.get(eventTimeZoneId) || '';
|
||||||
const rawEventDate = tempDataMap.get(eventDateId) || '';
|
const rawEventDate = tempDataMap.get(eventDateId) || '';
|
||||||
|
@ -24,7 +48,35 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
||||||
somethingWentWrong(bot, interaction, `missingFieldFromEventDescription@${rawEventTime}_${rawEventTimeZone}_${rawEventDate}`);
|
somethingWentWrong(bot, interaction, `missingFieldFromEventDescription@${rawEventTime}_${rawEventTimeZone}_${rawEventDate}`);
|
||||||
return;
|
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 {
|
} else {
|
||||||
somethingWentWrong(bot, interaction, 'noDataFromEventDescriptionModal');
|
somethingWentWrong(bot, interaction, 'noDataFromEventDescriptionModal');
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@ export const idSeparator = '@';
|
||||||
export const pathIdxSeparator = '|';
|
export const pathIdxSeparator = '|';
|
||||||
export const pathIdxEnder = '&';
|
export const pathIdxEnder = '&';
|
||||||
export const selfDestructMessage = (currentTime: number) => `**Please note:** This message will self destruct <t:${Math.floor((currentTime + tokenTimeoutMS) / 1000)}:R> due to limits imposed by the Discord API.`;
|
export const selfDestructMessage = (currentTime: number) => `**Please note:** This message will self destruct <t:${Math.floor((currentTime + tokenTimeoutMS) / 1000)}:R> due to limits imposed by the Discord API.`;
|
||||||
|
export const monthsLong: Array<string> = ["JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"];
|
||||||
|
export const monthsShort: Array<string> = monthsLong.map(month => month.slice(0, 3));
|
||||||
export const tzMap: Map<string, string> = new Map([
|
export const tzMap: Map<string, string> = new Map([
|
||||||
['CDT', '-05:00'],
|
['CDT', '-05:00'],
|
||||||
['CST', '-06:00'],
|
['CST', '-06:00'],
|
||||||
|
@ -77,6 +79,8 @@ export const getNestedActivity = (idxPath: Array<number>, activities: Array<Acti
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getFinalActivity = (idxPath: Array<number>, activities: Array<Activity>): Activity => getNestedActivity(idxPath, activities)[idxPath[idxPath.length - 1]];
|
||||||
|
|
||||||
const getSelectOptions = (baseValue: string, activities: Array<Activity>, defaultIdx?: number): Array<SelectOption> =>
|
const getSelectOptions = (baseValue: string, activities: Array<Activity>, defaultIdx?: number): Array<SelectOption> =>
|
||||||
activities.map((act, idx) => ({
|
activities.map((act, idx) => ({
|
||||||
label: act.name,
|
label: act.name,
|
||||||
|
|
Loading…
Reference in New Issue