utils reorg, moved things that are shared between live, editing, and creation to general utils file

This commit is contained in:
Ean Milligan (Bastion) 2023-04-08 02:52:54 -04:00
parent fa0ffe35e5
commit 3769fe5724
8 changed files with 36 additions and 57 deletions

View File

@ -2,20 +2,8 @@ import { ActionRow, ApplicationCommandFlags, ApplicationCommandTypes, Bot, Butto
import { infoColor1, somethingWentWrong } from '../../commandUtils.ts';
import { CommandDetails } from '../../types/commandTypes.ts';
import { Activities } from './activities.ts';
import {
addTokenToMap,
deleteTokenEarly,
generateActionRow,
generateMapId,
getNestedActivity,
idSeparator,
LfgEmbedIndexes,
lfgStartTimeName,
pathIdxEnder,
pathIdxSeparator,
selfDestructMessage,
tokenMap,
} from './utils.ts';
import { addTokenToMap, deleteTokenEarly, generateActionRow, generateMapId, getNestedActivity, pathIdxEnder, pathIdxSeparator, selfDestructMessage, tokenMap } from './utils.ts';
import { idSeparator, LfgEmbedIndexes, lfgStartTimeName } from '../eventUtils.ts';
import utils from '../../utils.ts';
import { customId as createCustomActivityBtnId } from './step1a-openCustomModal.ts';
import { customId as finalizeEventBtnId } from './step2-finalize.ts';

View File

@ -1,5 +1,6 @@
import { Bot, Interaction, InteractionResponseTypes, MessageComponentTypes, TextStyles } from '../../../deps.ts';
import { deleteTokenEarly, idSeparator, pathIdxSeparator } from './utils.ts';
import { deleteTokenEarly, pathIdxSeparator } from './utils.ts';
import { idSeparator } from '../eventUtils.ts';
import { customId as verifyCustomActivityId } from './step1b-verifyCustomActivity.ts';
import utils from '../../utils.ts';
import { dbClient, queries } from '../../db.ts';

View File

@ -1,7 +1,8 @@
import config from '../../../config.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 { addTokenToMap, pathIdxEnder, pathIdxSeparator, selfDestructMessage } from './utils.ts';
import { idSeparator } from '../eventUtils.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';

View File

@ -1,7 +1,8 @@
import { Bot, Interaction } from '../../../deps.ts';
import { somethingWentWrong } from '../../commandUtils.ts';
import { eventDateId, eventDescriptionId, eventTimeId, eventTimeZoneId } from './step1-gameSelection.ts';
import { addTokenToMap, createLFGPost, getFinalActivity, idSeparator, pathIdxSeparator } from './utils.ts';
import { addTokenToMap, createLFGPost, getFinalActivity, pathIdxSeparator } from './utils.ts';
import { idSeparator } from '../eventUtils.ts';
import { Activities, Activity } from './activities.ts';
import { getDateFromRawInput } from './dateTimeUtils.ts';
import utils from '../../utils.ts';

View File

@ -1,5 +1,6 @@
import { Bot, Interaction, InteractionResponseTypes, MessageComponentTypes } from '../../../deps.ts';
import { deleteTokenEarly, generateLFGButtons, idSeparator, LfgEmbedIndexes } from './utils.ts';
import { deleteTokenEarly, generateLFGButtons } from './utils.ts';
import { idSeparator, LfgEmbedIndexes } from '../eventUtils.ts';
import { somethingWentWrong } from '../../commandUtils.ts';
import { dbClient, queries } from '../../db.ts';
import utils from '../../utils.ts';

View File

@ -1,5 +1,3 @@
import config from '../../../config.ts';
import { Activity } from './activities.ts';
import {
ActionRow,
ApplicationCommandFlags,
@ -12,7 +10,10 @@ import {
MessageComponentTypes,
SelectOption,
} from '../../../deps.ts';
import config from '../../../config.ts';
import utils from '../../utils.ts';
import { Activity } from './activities.ts';
import { generateAlternateList, generateMemberList, generateMemberTitle, idSeparator, lfgStartTimeName } from '../eventUtils.ts';
import { successColor } from '../../commandUtils.ts';
import { LFGMember } from '../../types/commandTypes.ts';
import { customId as gameSelCustomId } from './step1-gameSelection.ts';
@ -24,7 +25,6 @@ import { customId as alternateEventCustomId } from '../live-event/alternateEvent
// Discord Interaction Tokens last 15 minutes, we will self kill after 14.5 minutes
const tokenTimeoutS = (15 * 60) - 30;
export const tokenTimeoutMS = tokenTimeoutS * 1000;
export const idSeparator = '@';
export const pathIdxSeparator = '|';
export const pathIdxEnder = '&';
export const selfDestructMessage = (currentTime: number) =>
@ -143,41 +143,6 @@ export const generateLFGButtons = (whitelist: boolean): [ButtonComponent, Button
},
}];
// Get Member Counts from the title
export const getEventMemberCount = (rawMemberTitle: string): [number, number] => {
const [rawCurrentCount, rawMaxCount] = rawMemberTitle.split('/');
const currentMemberCount = parseInt(rawCurrentCount.split(':')[1] || '0');
const maxMemberCount = parseInt(rawMaxCount || '0');
return [currentMemberCount, maxMemberCount];
};
// Get LFGMember objects from string list
export const getLfgMembers = (rawMemberList: string): Array<LFGMember> =>
rawMemberList.split('\n').map((rawMember) => {
const [memberName, memberMention] = rawMember.split('-');
const lfgMember: LFGMember = {
id: BigInt(memberMention.split('<@')[1].split('>')[0].trim() || '0'),
name: memberName.trim(),
joined: rawMember.endsWith('*'),
};
return lfgMember;
});
// Member List generators
export const generateMemberTitle = (memberList: Array<LFGMember>, maxMembers: number): string => `Members Joined: ${memberList.length}/${maxMembers}`;
export const generateMemberList = (memberList: Array<LFGMember>): string => memberList.length ? memberList.map((member) => `${member.name} - <@${member.id}>`).join('\n') : 'None';
export const generateAlternateList = (alternateList: Array<LFGMember>): string =>
alternateList.length ? alternateList.map((member) => `${member.name} - <@${member.id}>${member.joined ? ' *' : ''}`).join('\n') : 'None';
export enum LfgEmbedIndexes {
Activity,
StartTime,
ICSLink,
Description,
JoinedMembers,
AlternateMembers,
}
export const lfgStartTimeName = 'Start Time:';
export const createLFGPost = (
category: string,
activity: Activity,

22
src/buttons/eventUtils.ts Normal file
View File

@ -0,0 +1,22 @@
import { LFGMember } from '../types/commandTypes.ts';
// Index enum to standardize access to the field
export enum LfgEmbedIndexes {
Activity,
StartTime,
ICSLink,
Description,
JoinedMembers,
AlternateMembers,
}
// Common strings
export const lfgStartTimeName = 'Start Time:';
export const idSeparator = '@';
export const noMembersStr = 'None';
// Member List generators
export const generateMemberTitle = (memberList: Array<LFGMember>, maxMembers: number): string => `Members Joined: ${memberList.length}/${maxMembers}`;
export const generateMemberList = (memberList: Array<LFGMember>): string => memberList.length ? memberList.map((member) => `${member.name} - <@${member.id}>`).join('\n') : noMembersStr;
export const generateAlternateList = (alternateList: Array<LFGMember>): string =>
alternateList.length ? alternateList.map((member) => `${member.name} - <@${member.id}>${member.joined ? ' *' : ''}`).join('\n') : noMembersStr;

View File

@ -1,7 +1,7 @@
import { Bot, BotWithCache, Interaction, log, LT } 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/eventUtils.ts';
const commandNames: Array<string> = commands.map((command) => command.details.name);
const buttonNames: Array<string> = buttons.map((button) => button.customId);