diff --git a/src/buttons/event-creation/step1-gameSelection.ts b/src/buttons/event-creation/step1-gameSelection.ts index 171f292..e2c4794 100644 --- a/src/buttons/event-creation/step1-gameSelection.ts +++ b/src/buttons/event-creation/step1-gameSelection.ts @@ -3,19 +3,15 @@ import { infoColor1, somethingWentWrong } from '../../commandUtils.ts'; import { CommandDetails } from '../../types/commandTypes.ts'; import { Activities } from './activities.ts'; import { generateActionRow, getNestedActivity } from './utils.ts'; -import { idSeparator, LfgEmbedIndexes, lfgStartTimeName, pathIdxEnder, pathIdxSeparator } from '../eventUtils.ts'; +import { dateTimeFields, descriptionTextField, idSeparator, LfgEmbedIndexes, lfgStartTimeName, pathIdxEnder, pathIdxSeparator } from '../eventUtils.ts'; import { addTokenToMap, deleteTokenEarly, generateMapId, selfDestructMessage, tokenMap } from '../tokenCleanup.ts'; import utils from '../../utils.ts'; import { customId as createCustomActivityBtnId } from './step1a-openCustomModal.ts'; import { customId as finalizeEventBtnId } from './step2-finalize.ts'; -import { isDSTActive, monthsShort } from './dateTimeUtils.ts'; +import { monthsShort } from './dateTimeUtils.ts'; import { dbClient, queries } from '../../db.ts'; export const customId = 'gameSel'; -export const eventTimeId = 'eventTime'; -export const eventTimeZoneId = 'eventTimeZone'; -export const eventDateId = 'eventDate'; -export const eventDescriptionId = 'eventDescription'; const slashCommandName = 'create-event'; const details: CommandDetails = { name: slashCommandName, @@ -65,64 +61,12 @@ const execute = async (bot: Bot, interaction: Interaction) => { prefillDescription = interaction.message.embeds[0].fields[LfgEmbedIndexes.Description].value.trim(); } - // DST notice to try to get people to use the right TZ - const dstNotice = isDSTActive() ? '(Note: DST is in effect in NA)' : ''; - bot.helpers.sendInteractionResponse(interaction.id, interaction.token, { type: InteractionResponseTypes.Modal, data: { title: 'Enter Event Details', customId: `${finalizeEventBtnId}${idSeparator}${finalizedIdxPath}`, - components: [{ - type: MessageComponentTypes.ActionRow, - components: [{ - type: MessageComponentTypes.InputText, - customId: eventTimeId, - label: 'Start Time:', - placeholder: 'Enter the start time as "HH:MM AM/PM"', - style: TextStyles.Short, - minLength: 1, - maxLength: 8, - value: prefillTime || undefined, - }], - }, { - type: MessageComponentTypes.ActionRow, - components: [{ - type: MessageComponentTypes.InputText, - customId: eventTimeZoneId, - label: `Time Zone: ${dstNotice}`, - placeholder: 'Enter your time zone abbreviation (UTC±## also works)', - style: TextStyles.Short, - minLength: 2, - maxLength: 8, - value: prefillTimeZone || undefined, - }], - }, { - type: MessageComponentTypes.ActionRow, - components: [{ - type: MessageComponentTypes.InputText, - customId: eventDateId, - label: 'Start Date:', - placeholder: 'Enter date as "MONTH/DAY/YEAR" or "Month Day, Year"', - style: TextStyles.Short, - minLength: 1, - maxLength: 20, - value: prefillDate || undefined, - }], - }, { - type: MessageComponentTypes.ActionRow, - components: [{ - type: MessageComponentTypes.InputText, - customId: eventDescriptionId, - label: 'Description:', - placeholder: 'Briefly describe the event', - style: TextStyles.Paragraph, - required: false, - minLength: 0, - maxLength: 1000, - value: prefillDescription || undefined, - }], - }], + components: [...dateTimeFields(prefillTime, prefillTimeZone, prefillDate), descriptionTextField(prefillDescription)], }, }).catch((e: Error) => utils.commonLoggers.interactionSendError('step1-gameSelection.ts:modal', interaction, e)); return; diff --git a/src/buttons/event-creation/step2-finalize.ts b/src/buttons/event-creation/step2-finalize.ts index dcadef5..5f68d8b 100644 --- a/src/buttons/event-creation/step2-finalize.ts +++ b/src/buttons/event-creation/step2-finalize.ts @@ -1,8 +1,7 @@ import { Bot, Interaction } from '../../../deps.ts'; import { somethingWentWrong } from '../../commandUtils.ts'; -import { eventDateId, eventDescriptionId, eventTimeId, eventTimeZoneId } from './step1-gameSelection.ts'; import { createLFGPost, getFinalActivity } from './utils.ts'; -import { idSeparator, pathIdxSeparator } from '../eventUtils.ts'; +import { eventDateId, eventDescriptionId, eventTimeId, eventTimeZoneId, idSeparator, pathIdxSeparator } from '../eventUtils.ts'; import { addTokenToMap } from '../tokenCleanup.ts'; import { Activities, Activity } from './activities.ts'; import { getDateFromRawInput } from './dateTimeUtils.ts'; diff --git a/src/buttons/eventUtils.ts b/src/buttons/eventUtils.ts index acee272..84e91d0 100644 --- a/src/buttons/eventUtils.ts +++ b/src/buttons/eventUtils.ts @@ -1,4 +1,6 @@ +import { ActionRow, MessageComponentTypes, TextStyles } from '../../deps.ts'; import { LFGMember } from '../types/commandTypes.ts'; +import { isDSTActive } from './event-creation/dateTimeUtils.ts'; // Index enum to standardize access to the field export enum LfgEmbedIndexes { @@ -26,3 +28,64 @@ export const generateMemberTitle = (memberList: Array, maxMembers: nu export const generateMemberList = (memberList: Array): string => memberList.length ? memberList.map((member) => `${member.name} - <@${member.id}>`).join('\n') : noMembersStr; export const generateAlternateList = (alternateList: Array): string => alternateList.length ? alternateList.map((member) => `${member.name} - <@${member.id}>${member.joined ? ' *' : ''}`).join('\n') : noMembersStr; + +// Fields for event creation and editing modals +export const eventTimeId = 'eventTime'; +export const eventTimeZoneId = 'eventTimeZone'; +export const eventDateId = 'eventDate'; +export const eventDescriptionId = 'eventDescription'; + +export const descriptionTextField = (prefillDescription = ''): ActionRow => ({ + type: MessageComponentTypes.ActionRow, + components: [{ + type: MessageComponentTypes.InputText, + customId: eventDescriptionId, + label: 'Description:', + placeholder: 'Briefly describe the event', + style: TextStyles.Paragraph, + required: false, + minLength: 0, + maxLength: 1000, + value: prefillDescription || undefined, + }], +}); + +// DST notice to try to get people to use the right TZ +const dstNotice = isDSTActive() ? '(Note: DST is in effect in NA)' : ''; +export const dateTimeFields = (prefillTime = '', prefillTimeZone = '', prefillDate = ''): ActionRow[] => [{ + type: MessageComponentTypes.ActionRow, + components: [{ + type: MessageComponentTypes.InputText, + customId: eventTimeId, + label: 'Start Time:', + placeholder: 'Enter the start time as "HH:MM AM/PM"', + style: TextStyles.Short, + minLength: 1, + maxLength: 8, + value: prefillTime || undefined, + }], +}, { + type: MessageComponentTypes.ActionRow, + components: [{ + type: MessageComponentTypes.InputText, + customId: eventTimeZoneId, + label: `Time Zone: ${dstNotice}`, + placeholder: 'Enter your time zone abbreviation (UTC±## also works)', + style: TextStyles.Short, + minLength: 2, + maxLength: 8, + value: prefillTimeZone || undefined, + }], +}, { + type: MessageComponentTypes.ActionRow, + components: [{ + type: MessageComponentTypes.InputText, + customId: eventDateId, + label: 'Start Date:', + placeholder: 'Enter date as "MONTH/DAY/YEAR" or "Month Day, Year"', + style: TextStyles.Short, + minLength: 1, + maxLength: 20, + value: prefillDate || undefined, + }], +}]; diff --git a/src/events/messageCreate.ts b/src/events/messageCreate.ts index f3e3987..38b6e5a 100644 --- a/src/events/messageCreate.ts +++ b/src/events/messageCreate.ts @@ -5,6 +5,9 @@ import { infoEmbed } from '../commandUtils.ts'; import { dbClient, generateGuildSettingKey, lfgChannelSettings, queries } from '../db.ts'; export const messageCreate = async (bot: Bot, message: Message) => { + // Ignore self + if (botId === message.authorId) return; + // Delete all messages sent to a LFG Channel if (lfgChannelSettings.has(generateGuildSettingKey(message.guildId || 0n, message.channelId))) { bot.helpers.deleteMessage(message.channelId, message.id, 'Cleaning LFG Channel').catch((e: Error) => utils.commonLoggers.messageDeleteError('messageCreate.ts', 'Clean LFG Channel', e));