Move creation fields to common location to reuse for editing

also fix bot deleting own messages like an idiot
This commit is contained in:
Ean Milligan (Bastion) 2023-04-25 04:31:12 -04:00
parent 7352554ddf
commit 75aeda6195
4 changed files with 70 additions and 61 deletions

View File

@ -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;

View File

@ -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';

View File

@ -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<LFGMember>, maxMembers: nu
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;
// 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,
}],
}];

View File

@ -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));