Log custom events to our db to find common events
This commit is contained in:
parent
74e59b30a0
commit
ed18f556b1
|
@ -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!');
|
||||
|
|
|
@ -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<number> = 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) || '';
|
||||
|
|
|
@ -76,8 +76,7 @@ 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
|
||||
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}`,
|
||||
}],
|
||||
},
|
||||
|
@ -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<string> = finalizedIdxPath.split(pathIdxSeparator);
|
||||
const idxPath: Array<number> = rawIdxPath.map((rawIdx) => rawIdx ? parseInt(rawIdx) : -1);
|
||||
|
@ -193,8 +195,7 @@ 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({
|
||||
description: `Changing activity for [this event](${utils.idsToMessageUrl({
|
||||
guildId: interaction.guildId,
|
||||
channelId: evtChannelId,
|
||||
messageId: evtMessageId,
|
||||
|
|
|
@ -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<string, LfgChannelSetting> = new Map();
|
||||
|
|
Loading…
Reference in New Issue