From 4ddfd70655dea4629ceb8e61a0a5ff6019cc5013 Mon Sep 17 00:00:00 2001 From: "Ean Milligan (Bastion)" Date: Sun, 26 Mar 2023 21:37:47 -0400 Subject: [PATCH] deno fmt --- src/buttons/event-creation/dateTimeUtils.ts | 24 +++++++-------- .../event-creation/step1-gameSelection.ts | 6 ++-- .../step1b-verifyCustomActivity.ts | 22 +++++++------- src/buttons/event-creation/step2-finalize.ts | 8 ++--- src/buttons/event-creation/utils.ts | 30 ++++++++++--------- src/commandUtils.ts | 2 +- src/commands/delete.ts | 2 +- src/commands/setup.ts | 2 +- src/events/interactionCreate.ts | 2 +- 9 files changed, 51 insertions(+), 47 deletions(-) diff --git a/src/buttons/event-creation/dateTimeUtils.ts b/src/buttons/event-creation/dateTimeUtils.ts index 4d78b57..9578395 100644 --- a/src/buttons/event-creation/dateTimeUtils.ts +++ b/src/buttons/event-creation/dateTimeUtils.ts @@ -1,5 +1,5 @@ -const monthsLong: Array = ["JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"]; -const monthsShort: Array = monthsLong.map(month => month.slice(0, 3)); +const monthsLong: Array = ['JANUARY', 'FEBRUARY', 'MARCH', 'APRIL', 'MAY', 'JUNE', 'JULY', 'AUGUST', 'SEPTEMBER', 'OCTOBER', 'NOVEMBER', 'DECEMBER']; +const monthsShort: Array = monthsLong.map((month) => month.slice(0, 3)); const tzMap: Map = new Map([ ['CDT', '-05:00'], ['CST', '-06:00'], @@ -70,7 +70,7 @@ const parseEventTime = (preParsedEventTime: string): [string, string, string] => parsedEventTimeHours = preParsedEventTime.slice(0, -2).trim(); } else { parsedEventTimeHours = preParsedEventTime.trim(); - parsedEventTimeMinutes = '00' + parsedEventTimeMinutes = '00'; } // Determine if we need to remove the time period if (parseInt(parsedEventTimeHours) > 12) { @@ -78,7 +78,7 @@ const parseEventTime = (preParsedEventTime: string): [string, string, string] => } return [parsedEventTimeHours, parsedEventTimeMinutes, parsedEventTimePeriod]; -} +}; // Takes user input Time Zone and makes it actually usable const parseEventTimeZone = (preParsedEventTimeZone: string): string => { @@ -141,18 +141,18 @@ const parseEventDate = (preParsedEventDate: string): [string, string, string] => } return [parsedEventYear, parsedEventMonth, parsedEventDay]; -} +}; // Take full raw Date/Time input and convert it to a proper Date export const getDateFromRawInput = (rawEventTime: string, rawEventTimeZone: string, rawEventDate: string): Date => { - // Verify/Set Time - const [parsedEventTimeHours, parsedEventTimeMinutes, parsedEventTimePeriod] = parseEventTime(rawEventTime.replaceAll(':', '').toUpperCase()) + // Verify/Set Time + const [parsedEventTimeHours, parsedEventTimeMinutes, parsedEventTimePeriod] = parseEventTime(rawEventTime.replaceAll(':', '').toUpperCase()); - // Verify/Set Time Zone - const parsedEventTimeZone = parseEventTimeZone(rawEventTimeZone.replaceAll(' ', '').trim().toUpperCase()); + // Verify/Set Time Zone + const parsedEventTimeZone = parseEventTimeZone(rawEventTimeZone.replaceAll(' ', '').trim().toUpperCase()); - // Verify/Set Date - const [parsedEventYear, parsedEventMonth, parsedEventDay] = parseEventDate(rawEventDate.trim().toUpperCase()); + // Verify/Set Date + const [parsedEventYear, parsedEventMonth, parsedEventDay] = parseEventDate(rawEventDate.trim().toUpperCase()); - return new Date(`${parsedEventMonth} ${parsedEventDay}, ${parsedEventYear} ${parsedEventTimeHours}:${parsedEventTimeMinutes} ${parsedEventTimePeriod} ${parsedEventTimeZone}`); + return new Date(`${parsedEventMonth} ${parsedEventDay}, ${parsedEventYear} ${parsedEventTimeHours}:${parsedEventTimeMinutes} ${parsedEventTimePeriod} ${parsedEventTimeZone}`); }; diff --git a/src/buttons/event-creation/step1-gameSelection.ts b/src/buttons/event-creation/step1-gameSelection.ts index 27a47fc..32bb1d1 100644 --- a/src/buttons/event-creation/step1-gameSelection.ts +++ b/src/buttons/event-creation/step1-gameSelection.ts @@ -2,7 +2,7 @@ import { ActionRow, ApplicationCommandFlags, ApplicationCommandTypes, Bot, Butto import { infoColor1, somethingWentWrong } from '../../commandUtils.ts'; import { CommandDetails } from '../../types/commandTypes.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 { customId as createCustomActivityBtnId } from './step1a-openCustomModal.ts'; import { customId as finalizeEventBtnId } from './step2-finalize.ts'; @@ -32,8 +32,8 @@ const customEventRow: ActionRow = { const execute = async (bot: Bot, interaction: Interaction) => { if (interaction.data && (interaction.data.name === slashCommandName || interaction.data.customId) && interaction.member && interaction.guildId && interaction.channelId) { // Check if we are done - const customIdIdxPath = ((interaction.data.customId || '').substring((interaction.data.customId || '').indexOf(idSeparator) + 1) || ''); - const valuesIdxPath = (interaction.data?.values?.[0] || ''); + const customIdIdxPath = (interaction.data.customId || '').substring((interaction.data.customId || '').indexOf(idSeparator) + 1) || ''; + const valuesIdxPath = interaction.data?.values?.[0] || ''; const strippedIdxPath = interaction.data.customId?.includes(idSeparator) ? customIdIdxPath : valuesIdxPath; 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)) { diff --git a/src/buttons/event-creation/step1b-verifyCustomActivity.ts b/src/buttons/event-creation/step1b-verifyCustomActivity.ts index bb8d23f..f64e3e3 100644 --- a/src/buttons/event-creation/step1b-verifyCustomActivity.ts +++ b/src/buttons/event-creation/step1b-verifyCustomActivity.ts @@ -1,8 +1,8 @@ import config from '../../../config.ts'; -import { Bot, Interaction, InteractionResponseTypes, MessageComponentTypes, ButtonStyles, ApplicationCommandFlags } from '../../../deps.ts'; -import { infoColor1, somethingWentWrong, failColor, safelyDismissMsg } from '../../commandUtils.ts'; -import { addTokenToMap, idSeparator, pathIdxSeparator, pathIdxEnder, selfDestructMessage } from './utils.ts'; -import { activityTitleId, activitySubtitleId, activityMaxPlayersId } from './step1a-openCustomModal.ts'; +import { ApplicationCommandFlags, Bot, ButtonStyles, Interaction, InteractionResponseTypes, MessageComponentTypes } from '../../../deps.ts'; +import { failColor, infoColor1, safelyDismissMsg, somethingWentWrong } from '../../commandUtils.ts'; +import { addTokenToMap, idSeparator, pathIdxEnder, pathIdxSeparator, selfDestructMessage } from './utils.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'; @@ -32,9 +32,11 @@ const execute = async (bot: Bot, interaction: Interaction) => { embeds: [{ color: failColor, 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)); return; } @@ -72,14 +74,14 @@ const execute = async (bot: Bot, interaction: Interaction) => { style: ButtonStyles.Success, label: 'Yup, looks great!', customId: `${gameSelectionId}${idxPath}${pathIdxEnder}`, - },{ + }, { type: MessageComponentTypes.Button, style: ButtonStyles.Danger, label: 'Nope, let me change something.', customId: `${openCustomModalId}${idxPath}`, - }] - }] - } + }], + }], + }, }).catch((e: Error) => utils.commonLoggers.interactionSendError('step1b-verifyCustomActivity.ts:message', interaction, e)); } else { somethingWentWrong(bot, interaction, 'noDataFromCustomActivityModal'); diff --git a/src/buttons/event-creation/step2-finalize.ts b/src/buttons/event-creation/step2-finalize.ts index a316273..8c3a2f0 100644 --- a/src/buttons/event-creation/step2-finalize.ts +++ b/src/buttons/event-creation/step2-finalize.ts @@ -1,6 +1,6 @@ import { Bot, Interaction, InteractionResponseTypes, MessageComponentTypes, TextStyles } from '../../../deps.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 { Activities, Activity } from './activities.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 = 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)) { + if (idxPath.some((idx) => isNaN(idx) || idx < 0)) { // Handle custom activity category = rawIdxPath[0]; activity = { @@ -32,7 +32,7 @@ const execute = async (bot: Bot, interaction: Interaction) => { } else { // Handle preset activity category = Activities[idxPath[0]].name; - activity = getFinalActivity(idxPath, Activities) + activity = getFinalActivity(idxPath, Activities); } if (!category || !activity.name || !activity.maxMembers || isNaN(activity.maxMembers)) { diff --git a/src/buttons/event-creation/utils.ts b/src/buttons/event-creation/utils.ts index a2fe87a..dae1c09 100644 --- a/src/buttons/event-creation/utils.ts +++ b/src/buttons/event-creation/utils.ts @@ -8,7 +8,8 @@ export const tokenTimeoutMS = tokenTimeoutS * 1000; 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 selfDestructMessage = (currentTime: number) => + `**Please note:** This message will self destruct due to limits imposed by the Discord API.`; export const tokenMap: Map, activities: Array, activities: Array): Activity => getNestedActivity(idxPath, activities)[idxPath[idxPath.length - 1]]; +export const getFinalActivity = (idxPath: Array, activities: Array): Activity => getNestedActivity(idxPath, activities)[idxPath[idxPath.length - 1]]; const getSelectOptions = (baseValue: string, activities: Array, defaultIdx?: number): Array => activities.map((act, idx) => ({ @@ -45,18 +46,19 @@ export const generateActionRow = (baseValue: string, activities: Array 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), { - token: interaction.token, - timeoutId: setTimeout( - (guildId, channelId, userId) => { - deleteTokenEarly(bot, interaction, guildId, channelId, userId); - }, - tokenTimeoutMS, - 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, + timeoutId: setTimeout( + (guildId, channelId, userId) => { + deleteTokenEarly(bot, interaction, guildId, channelId, userId); + }, + tokenTimeoutMS, + guildId, + channelId, + userId, + ), + }); export const deleteTokenEarly = async (bot: Bot, interaction: Interaction, guildId: bigint, channelId: bigint, userId: bigint) => { const tokenMapEntry = tokenMap.get(generateMapId(guildId, channelId, userId)); diff --git a/src/commandUtils.ts b/src/commandUtils.ts index baf97b2..80f72be 100644 --- a/src/commandUtils.ts +++ b/src/commandUtils.ts @@ -9,7 +9,7 @@ export const successColor = 0x0f8108; export const infoColor1 = 0x313bf9; 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 => { const statuses = [ diff --git a/src/commands/delete.ts b/src/commands/delete.ts index c917dbc..d81a64c 100644 --- a/src/commands/delete.ts +++ b/src/commands/delete.ts @@ -1,6 +1,6 @@ import config from '../../config.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 { CommandDetails } from '../types/commandTypes.ts'; import utils from '../utils.ts'; diff --git a/src/commands/setup.ts b/src/commands/setup.ts index 2989253..a118bd4 100644 --- a/src/commands/setup.ts +++ b/src/commands/setup.ts @@ -14,7 +14,7 @@ import { OverwriteTypes, sendMessage, } 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 { CommandDetails } from '../types/commandTypes.ts'; import utils from '../utils.ts'; diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts index dddbc03..f0e3888 100644 --- a/src/events/interactionCreate.ts +++ b/src/events/interactionCreate.ts @@ -1,7 +1,7 @@ import { Bot, BotWithCache, Interaction } from '../../deps.ts'; import { buttons } from '../buttons/_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 = commands.map((command) => command.details.name); const buttonNames: Array = buttons.map((button) => button.customId);