deno fmt
This commit is contained in:
parent
716913b24c
commit
4ddfd70655
|
@ -1,5 +1,5 @@
|
|||
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 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 tzMap: Map<string, string> = 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}`);
|
||||
};
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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<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)) {
|
||||
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)) {
|
||||
|
|
|
@ -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 <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, {
|
||||
token: string;
|
||||
|
@ -25,7 +26,7 @@ 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]];
|
||||
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> =>
|
||||
activities.map((act, idx) => ({
|
||||
|
@ -45,18 +46,19 @@ export const generateActionRow = (baseValue: string, activities: Array<Activity>
|
|||
|
||||
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));
|
||||
|
|
|
@ -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 = [
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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<string> = commands.map((command) => command.details.name);
|
||||
const buttonNames: Array<string> = buttons.map((button) => button.customId);
|
||||
|
|
Loading…
Reference in New Issue