This commit is contained in:
Ean Milligan (Bastion) 2023-03-26 21:37:47 -04:00
parent 716913b24c
commit 4ddfd70655
9 changed files with 51 additions and 47 deletions

View File

@ -1,5 +1,5 @@
const monthsLong: Array<string> = ["JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"]; const monthsLong: Array<string> = ['JANUARY', 'FEBRUARY', 'MARCH', 'APRIL', 'MAY', 'JUNE', 'JULY', 'AUGUST', 'SEPTEMBER', 'OCTOBER', 'NOVEMBER', 'DECEMBER'];
const monthsShort: Array<string> = monthsLong.map(month => month.slice(0, 3)); const monthsShort: Array<string> = monthsLong.map((month) => month.slice(0, 3));
const tzMap: Map<string, string> = new Map([ const tzMap: Map<string, string> = new Map([
['CDT', '-05:00'], ['CDT', '-05:00'],
['CST', '-06:00'], ['CST', '-06:00'],
@ -70,7 +70,7 @@ const parseEventTime = (preParsedEventTime: string): [string, string, string] =>
parsedEventTimeHours = preParsedEventTime.slice(0, -2).trim(); parsedEventTimeHours = preParsedEventTime.slice(0, -2).trim();
} else { } else {
parsedEventTimeHours = preParsedEventTime.trim(); parsedEventTimeHours = preParsedEventTime.trim();
parsedEventTimeMinutes = '00' parsedEventTimeMinutes = '00';
} }
// Determine if we need to remove the time period // Determine if we need to remove the time period
if (parseInt(parsedEventTimeHours) > 12) { if (parseInt(parsedEventTimeHours) > 12) {
@ -78,7 +78,7 @@ const parseEventTime = (preParsedEventTime: string): [string, string, string] =>
} }
return [parsedEventTimeHours, parsedEventTimeMinutes, parsedEventTimePeriod]; return [parsedEventTimeHours, parsedEventTimeMinutes, parsedEventTimePeriod];
} };
// Takes user input Time Zone and makes it actually usable // Takes user input Time Zone and makes it actually usable
const parseEventTimeZone = (preParsedEventTimeZone: string): string => { const parseEventTimeZone = (preParsedEventTimeZone: string): string => {
@ -141,12 +141,12 @@ const parseEventDate = (preParsedEventDate: string): [string, string, string] =>
} }
return [parsedEventYear, parsedEventMonth, parsedEventDay]; return [parsedEventYear, parsedEventMonth, parsedEventDay];
} };
// Take full raw Date/Time input and convert it to a proper Date // Take full raw Date/Time input and convert it to a proper Date
export const getDateFromRawInput = (rawEventTime: string, rawEventTimeZone: string, rawEventDate: string): Date => { export const getDateFromRawInput = (rawEventTime: string, rawEventTimeZone: string, rawEventDate: string): Date => {
// Verify/Set Time // Verify/Set Time
const [parsedEventTimeHours, parsedEventTimeMinutes, parsedEventTimePeriod] = parseEventTime(rawEventTime.replaceAll(':', '').toUpperCase()) const [parsedEventTimeHours, parsedEventTimeMinutes, parsedEventTimePeriod] = parseEventTime(rawEventTime.replaceAll(':', '').toUpperCase());
// Verify/Set Time Zone // Verify/Set Time Zone
const parsedEventTimeZone = parseEventTimeZone(rawEventTimeZone.replaceAll(' ', '').trim().toUpperCase()); const parsedEventTimeZone = parseEventTimeZone(rawEventTimeZone.replaceAll(' ', '').trim().toUpperCase());

View File

@ -2,7 +2,7 @@ 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, selfDestructMessage } from './utils.ts'; import { addTokenToMap, deleteTokenEarly, generateActionRow, generateMapId, getNestedActivity, idSeparator, pathIdxEnder, pathIdxSeparator, selfDestructMessage, tokenMap } 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'; import { customId as finalizeEventBtnId } from './step2-finalize.ts';
@ -32,8 +32,8 @@ const customEventRow: ActionRow = {
const execute = async (bot: Bot, interaction: Interaction) => { const execute = async (bot: Bot, interaction: Interaction) => {
if (interaction.data && (interaction.data.name === slashCommandName || interaction.data.customId) && interaction.member && interaction.guildId && interaction.channelId) { if (interaction.data && (interaction.data.name === slashCommandName || interaction.data.customId) && interaction.member && interaction.guildId && interaction.channelId) {
// Check if we are done // Check if we are done
const customIdIdxPath = ((interaction.data.customId || '').substring((interaction.data.customId || '').indexOf(idSeparator) + 1) || ''); const customIdIdxPath = (interaction.data.customId || '').substring((interaction.data.customId || '').indexOf(idSeparator) + 1) || '';
const valuesIdxPath = (interaction.data?.values?.[0] || ''); const valuesIdxPath = interaction.data?.values?.[0] || '';
const strippedIdxPath = interaction.data.customId?.includes(idSeparator) ? customIdIdxPath : valuesIdxPath; const strippedIdxPath = interaction.data.customId?.includes(idSeparator) ? customIdIdxPath : valuesIdxPath;
const finalizedIdxPath = strippedIdxPath.substring(0, strippedIdxPath.lastIndexOf(pathIdxEnder)); const finalizedIdxPath = strippedIdxPath.substring(0, strippedIdxPath.lastIndexOf(pathIdxEnder));
if ((interaction.data.customId?.includes(idSeparator) && interaction.data.customId.endsWith(pathIdxEnder)) || interaction.data?.values?.[0].endsWith(pathIdxEnder)) { if ((interaction.data.customId?.includes(idSeparator) && interaction.data.customId.endsWith(pathIdxEnder)) || interaction.data?.values?.[0].endsWith(pathIdxEnder)) {

View File

@ -1,8 +1,8 @@
import config from '../../../config.ts'; import config from '../../../config.ts';
import { Bot, Interaction, InteractionResponseTypes, MessageComponentTypes, ButtonStyles, ApplicationCommandFlags } from '../../../deps.ts'; import { ApplicationCommandFlags, Bot, ButtonStyles, Interaction, InteractionResponseTypes, MessageComponentTypes } from '../../../deps.ts';
import { infoColor1, somethingWentWrong, failColor, safelyDismissMsg } from '../../commandUtils.ts'; import { failColor, infoColor1, safelyDismissMsg, somethingWentWrong } from '../../commandUtils.ts';
import { addTokenToMap, idSeparator, pathIdxSeparator, pathIdxEnder, selfDestructMessage } from './utils.ts'; import { addTokenToMap, idSeparator, pathIdxEnder, pathIdxSeparator, selfDestructMessage } from './utils.ts';
import { activityTitleId, activitySubtitleId, activityMaxPlayersId } from './step1a-openCustomModal.ts'; import { activityMaxPlayersId, activitySubtitleId, activityTitleId } from './step1a-openCustomModal.ts';
import { customId as gameSelectionId } from './step1-gameSelection.ts'; import { customId as gameSelectionId } from './step1-gameSelection.ts';
import { customId as openCustomModalId } from './step1a-openCustomModal.ts'; import { customId as openCustomModalId } from './step1a-openCustomModal.ts';
import utils from '../../utils.ts'; import utils from '../../utils.ts';
@ -32,9 +32,11 @@ 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 \`${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}` 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;
} }
@ -77,9 +79,9 @@ const execute = async (bot: Bot, interaction: Interaction) => {
style: ButtonStyles.Danger, style: ButtonStyles.Danger,
label: 'Nope, let me change something.', label: 'Nope, let me change something.',
customId: `${openCustomModalId}${idxPath}`, customId: `${openCustomModalId}${idxPath}`,
}] }],
}] }],
} },
}).catch((e: Error) => utils.commonLoggers.interactionSendError('step1b-verifyCustomActivity.ts:message', interaction, e)); }).catch((e: Error) => utils.commonLoggers.interactionSendError('step1b-verifyCustomActivity.ts:message', interaction, e));
} else { } else {
somethingWentWrong(bot, interaction, 'noDataFromCustomActivityModal'); somethingWentWrong(bot, interaction, 'noDataFromCustomActivityModal');

View File

@ -1,6 +1,6 @@
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 { eventDateId, eventDescriptionId, eventTimeId, eventTimeZoneId } from './step1-gameSelection.ts';
import { getFinalActivity, idSeparator, pathIdxSeparator } from './utils.ts'; import { getFinalActivity, idSeparator, pathIdxSeparator } from './utils.ts';
import { Activities, Activity } from './activities.ts'; import { Activities, Activity } from './activities.ts';
import { getDateFromRawInput } from './dateTimeUtils.ts'; import { getDateFromRawInput } from './dateTimeUtils.ts';
@ -17,12 +17,12 @@ const execute = async (bot: Bot, interaction: Interaction) => {
} }
} }
const customIdIdxPath = ((interaction.data.customId || '').substring((interaction.data.customId || '').indexOf(idSeparator) + 1) || ''); const customIdIdxPath = (interaction.data.customId || '').substring((interaction.data.customId || '').indexOf(idSeparator) + 1) || '';
const rawIdxPath: Array<string> = customIdIdxPath.split(pathIdxSeparator); const rawIdxPath: Array<string> = customIdIdxPath.split(pathIdxSeparator);
const idxPath: Array<number> = rawIdxPath.map((rawIdx) => rawIdx ? parseInt(rawIdx) : -1); const idxPath: Array<number> = rawIdxPath.map((rawIdx) => rawIdx ? parseInt(rawIdx) : -1);
let category: string; let category: string;
let activity: Activity; let activity: Activity;
if (idxPath.some(idx => isNaN(idx) || idx < 0)) { if (idxPath.some((idx) => isNaN(idx) || idx < 0)) {
// Handle custom activity // Handle custom activity
category = rawIdxPath[0]; category = rawIdxPath[0];
activity = { activity = {
@ -32,7 +32,7 @@ const execute = async (bot: Bot, interaction: Interaction) => {
} else { } else {
// Handle preset activity // Handle preset activity
category = Activities[idxPath[0]].name; category = Activities[idxPath[0]].name;
activity = getFinalActivity(idxPath, Activities) activity = getFinalActivity(idxPath, Activities);
} }
if (!category || !activity.name || !activity.maxMembers || isNaN(activity.maxMembers)) { if (!category || !activity.name || !activity.maxMembers || isNaN(activity.maxMembers)) {

View File

@ -8,7 +8,8 @@ export const tokenTimeoutMS = tokenTimeoutS * 1000;
export const idSeparator = '@'; 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 tokenMap: Map<string, { export const tokenMap: Map<string, {
token: string; token: string;
@ -45,7 +46,8 @@ export const generateActionRow = (baseValue: string, activities: Array<Activity>
export const generateMapId = (guildId: bigint, channelId: bigint, userId: bigint) => `${guildId}-${channelId}-${userId}`; export const generateMapId = (guildId: bigint, channelId: bigint, userId: bigint) => `${guildId}-${channelId}-${userId}`;
export const addTokenToMap = (bot: Bot, interaction: Interaction, guildId: bigint, channelId: bigint, userId: bigint) => tokenMap.set(generateMapId(guildId, channelId, userId), { export const addTokenToMap = (bot: Bot, interaction: Interaction, guildId: bigint, channelId: bigint, userId: bigint) =>
tokenMap.set(generateMapId(guildId, channelId, userId), {
token: interaction.token, token: interaction.token,
timeoutId: setTimeout( timeoutId: setTimeout(
(guildId, channelId, userId) => { (guildId, channelId, userId) => {

View File

@ -9,7 +9,7 @@ export const successColor = 0x0f8108;
export const infoColor1 = 0x313bf9; export const infoColor1 = 0x313bf9;
export const infoColor2 = 0x6805e9; export const infoColor2 = 0x6805e9;
export const safelyDismissMsg = 'You may safely dismiss this message.' export const safelyDismissMsg = 'You may safely dismiss this message.';
export const getRandomStatus = (guildCount: number): string => { export const getRandomStatus = (guildCount: number): string => {
const statuses = [ const statuses = [

View File

@ -1,6 +1,6 @@
import config from '../../config.ts'; import config from '../../config.ts';
import { ApplicationCommandFlags, ApplicationCommandTypes, Bot, Interaction, InteractionResponseTypes } from '../../deps.ts'; import { ApplicationCommandFlags, ApplicationCommandTypes, Bot, Interaction, InteractionResponseTypes } from '../../deps.ts';
import { failColor, somethingWentWrong, successColor, safelyDismissMsg } from '../commandUtils.ts'; import { failColor, safelyDismissMsg, somethingWentWrong, successColor } from '../commandUtils.ts';
import { dbClient, lfgChannelSettings, queries } from '../db.ts'; import { dbClient, lfgChannelSettings, queries } from '../db.ts';
import { CommandDetails } from '../types/commandTypes.ts'; import { CommandDetails } from '../types/commandTypes.ts';
import utils from '../utils.ts'; import utils from '../utils.ts';

View File

@ -14,7 +14,7 @@ import {
OverwriteTypes, OverwriteTypes,
sendMessage, sendMessage,
} from '../../deps.ts'; } from '../../deps.ts';
import { failColor, infoColor2, somethingWentWrong, successColor, safelyDismissMsg } from '../commandUtils.ts'; import { failColor, infoColor2, safelyDismissMsg, somethingWentWrong, successColor } from '../commandUtils.ts';
import { dbClient, lfgChannelSettings, queries } from '../db.ts'; import { dbClient, lfgChannelSettings, queries } from '../db.ts';
import { CommandDetails } from '../types/commandTypes.ts'; import { CommandDetails } from '../types/commandTypes.ts';
import utils from '../utils.ts'; import utils from '../utils.ts';

View File

@ -1,7 +1,7 @@
import { Bot, BotWithCache, Interaction } from '../../deps.ts'; import { Bot, BotWithCache, Interaction } from '../../deps.ts';
import { buttons } from '../buttons/_index.ts'; import { buttons } from '../buttons/_index.ts';
import { commands } from '../commands/_index.ts'; import { commands } from '../commands/_index.ts';
import { idSeparator } from '../buttons/event-creation/utils.ts' import { idSeparator } from '../buttons/event-creation/utils.ts';
const commandNames: Array<string> = commands.map((command) => command.details.name); const commandNames: Array<string> = commands.map((command) => command.details.name);
const buttonNames: Array<string> = buttons.map((button) => button.customId); const buttonNames: Array<string> = buttons.map((button) => button.customId);