From ed18f556b1120f3cfab98ecc3dc2c4b351326302 Mon Sep 17 00:00:00 2001 From: "Ean Milligan (Bastion)" Date: Sat, 29 Apr 2023 03:57:18 -0400 Subject: [PATCH] Log custom events to our db to find common events --- db/initialize.ts | 14 +++++++++++++ src/buttons/event-creation/step2-finalize.ts | 8 ++++++++ src/buttons/live-event/editActivity.ts | 21 ++++++++++---------- src/db.ts | 1 + 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/db/initialize.ts b/db/initialize.ts index c332294..2379689 100644 --- a/db/initialize.ts +++ b/db/initialize.ts @@ -14,6 +14,7 @@ await dbClient.execute(`DROP PROCEDURE IF EXISTS INC_CNT;`); await dbClient.execute(`DROP TABLE IF EXISTS command_cnt;`); await dbClient.execute(`DROP TABLE IF EXISTS guild_settings;`); await dbClient.execute(`DROP TABLE IF EXISTS active_events;`); +await dbClient.execute(`DROP TABLE IF EXISTS custom_activities;`); console.log('Tables dropped'); console.log('Attempting to create table command_cnt'); @@ -79,5 +80,18 @@ console.log('Table created'); * If both are -1, the event failed to delete */ +console.log('Attempting to create table custom_activities'); +await dbClient.execute(` + CREATE TABLE custom_activities ( + id int unsigned NOT NULL AUTO_INCREMENT, + activityTitle char(35) NOT NULL, + activitySubtitle char(50) NOT NULL, + maxMembers tinyint NOT NULL, + PRIMARY KEY (id), + UNIQUE KEY custom_activities_id_UNIQUE (id) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +`); +console.log('Table created'); + await dbClient.close(); console.log('Done!'); diff --git a/src/buttons/event-creation/step2-finalize.ts b/src/buttons/event-creation/step2-finalize.ts index 667014c..8f10ff6 100644 --- a/src/buttons/event-creation/step2-finalize.ts +++ b/src/buttons/event-creation/step2-finalize.ts @@ -6,6 +6,7 @@ import { addTokenToMap } from '../tokenCleanup.ts'; import { Activities, Activity } from './activities.ts'; import { getDateFromRawInput } from './dateTimeUtils.ts'; import utils from '../../utils.ts'; +import { dbClient, queries } from '../../db.ts'; export const customId = 'finalize'; @@ -24,7 +25,9 @@ const execute = async (bot: Bot, interaction: Interaction) => { const idxPath: Array = rawIdxPath.map((rawIdx) => rawIdx ? parseInt(rawIdx) : -1); let category: string; let activity: Activity; + let customAct = false; if (idxPath.some((idx) => isNaN(idx) || idx < 0)) { + customAct = true; // Handle custom activity category = rawIdxPath[0]; activity = { @@ -42,6 +45,11 @@ const execute = async (bot: Bot, interaction: Interaction) => { somethingWentWrong(bot, interaction, `missingActivityFromFinalize@${category}_${activity.name}_${activity.maxMembers}`); } + // Log custom event to see if we should add it as a preset + if (customAct) { + dbClient.execute(queries.insertCustomActivity, [category, activity.name, activity.maxMembers]).catch((e) => utils.commonLoggers.dbError('step2-finalize.ts@custom', 'insert into', e)) + } + const rawEventTime = tempDataMap.get(eventTimeId) || ''; const rawEventTimeZone = tempDataMap.get(eventTimeZoneId) || ''; const rawEventDate = tempDataMap.get(eventDateId) || ''; diff --git a/src/buttons/live-event/editActivity.ts b/src/buttons/live-event/editActivity.ts index d18da33..2389b88 100644 --- a/src/buttons/live-event/editActivity.ts +++ b/src/buttons/live-event/editActivity.ts @@ -76,9 +76,8 @@ 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 re-edit 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 re-edit this activity, but make sure the maximum player count is between 1 and 99.\n\n${safelyDismissMsg}`, }], }, }).catch((e: Error) => utils.commonLoggers.interactionSendError('editActivity.ts@invalidPlayer', interaction, e)); @@ -92,6 +91,9 @@ const execute = async (bot: Bot, interaction: Interaction) => { selectedCategory = activityTitle; selectedActivity.name = activitySubtitle; selectedActivity.maxMembers = activityMaxPlayers; + + // Log custom event to see if we should add it as a preset + dbClient.execute(queries.insertCustomActivity, [selectedCategory, selectedActivity.name, selectedActivity.maxMembers]).catch((e) => utils.commonLoggers.dbError('editActivity.ts@custom', 'insert into', e)) } else { const rawIdxPath: Array = finalizedIdxPath.split(pathIdxSeparator); const idxPath: Array = rawIdxPath.map((rawIdx) => rawIdx ? parseInt(rawIdx) : -1); @@ -193,13 +195,12 @@ const execute = async (bot: Bot, interaction: Interaction) => { data: { embeds: [{ title: 'Please select a Game and Activity, or create a Custom Event.', - description: `Changing activity for [this event](${ - utils.idsToMessageUrl({ - guildId: interaction.guildId, - channelId: evtChannelId, - messageId: evtMessageId, - }) - }).\n\n${selfDestructMessage(new Date().getTime())}`, + description: `Changing activity for [this event](${utils.idsToMessageUrl({ + guildId: interaction.guildId, + channelId: evtChannelId, + messageId: evtMessageId, + }) + }).\n\n${selfDestructMessage(new Date().getTime())}`, color: infoColor1, }], flags: ApplicationCommandFlags.Ephemeral, diff --git a/src/db.ts b/src/db.ts index 9edf91e..91002e7 100644 --- a/src/db.ts +++ b/src/db.ts @@ -19,6 +19,7 @@ export const queries = { updateEventTime: 'UPDATE active_events SET eventTime = ? WHERE channelId = ? AND messageId = ?', updateEventFlags: (notifiedFlag: number, lockedFlag: number) => `UPDATE active_events SET notifiedFlag = ${notifiedFlag}, lockedFlag = ${lockedFlag} WHERE channelId = ? AND messageId = ?`, deleteEvent: 'DELETE FROM active_events WHERE channelId = ? AND messageId = ?', + insertCustomActivity: 'INSERT INTO custom_activities(activityTitle,activitySubtitle,maxMembers) values(?,?,?)', }; export const lfgChannelSettings: Map = new Map();