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 command_cnt;`);
|
||||||
await dbClient.execute(`DROP TABLE IF EXISTS guild_settings;`);
|
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 active_events;`);
|
||||||
|
await dbClient.execute(`DROP TABLE IF EXISTS custom_activities;`);
|
||||||
console.log('Tables dropped');
|
console.log('Tables dropped');
|
||||||
|
|
||||||
console.log('Attempting to create table command_cnt');
|
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
|
* 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();
|
await dbClient.close();
|
||||||
console.log('Done!');
|
console.log('Done!');
|
||||||
|
|
|
@ -6,6 +6,7 @@ import { addTokenToMap } from '../tokenCleanup.ts';
|
||||||
import { Activities, Activity } from './activities.ts';
|
import { Activities, Activity } from './activities.ts';
|
||||||
import { getDateFromRawInput } from './dateTimeUtils.ts';
|
import { getDateFromRawInput } from './dateTimeUtils.ts';
|
||||||
import utils from '../../utils.ts';
|
import utils from '../../utils.ts';
|
||||||
|
import { dbClient, queries } from '../../db.ts';
|
||||||
|
|
||||||
export const customId = 'finalize';
|
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);
|
const idxPath: Array<number> = rawIdxPath.map((rawIdx) => rawIdx ? parseInt(rawIdx) : -1);
|
||||||
let category: string;
|
let category: string;
|
||||||
let activity: Activity;
|
let activity: Activity;
|
||||||
|
let customAct = false;
|
||||||
if (idxPath.some((idx) => isNaN(idx) || idx < 0)) {
|
if (idxPath.some((idx) => isNaN(idx) || idx < 0)) {
|
||||||
|
customAct = true;
|
||||||
// Handle custom activity
|
// Handle custom activity
|
||||||
category = rawIdxPath[0];
|
category = rawIdxPath[0];
|
||||||
activity = {
|
activity = {
|
||||||
|
@ -42,6 +45,11 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
||||||
somethingWentWrong(bot, interaction, `missingActivityFromFinalize@${category}_${activity.name}_${activity.maxMembers}`);
|
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 rawEventTime = tempDataMap.get(eventTimeId) || '';
|
||||||
const rawEventTimeZone = tempDataMap.get(eventTimeZoneId) || '';
|
const rawEventTimeZone = tempDataMap.get(eventTimeZoneId) || '';
|
||||||
const rawEventDate = tempDataMap.get(eventDateId) || '';
|
const rawEventDate = tempDataMap.get(eventDateId) || '';
|
||||||
|
|
|
@ -76,9 +76,8 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
||||||
embeds: [{
|
embeds: [{
|
||||||
color: failColor,
|
color: failColor,
|
||||||
title: 'Invalid Max Member count!',
|
title: 'Invalid Max Member count!',
|
||||||
description: `${config.name} parsed the max members as \`${
|
description: `${config.name} parsed the max members as \`${isNaN(activityMaxPlayers) ? 'Not a Number' : activityMaxPlayers
|
||||||
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}`,
|
||||||
}\`, 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));
|
}).catch((e: Error) => utils.commonLoggers.interactionSendError('editActivity.ts@invalidPlayer', interaction, e));
|
||||||
|
@ -92,6 +91,9 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
||||||
selectedCategory = activityTitle;
|
selectedCategory = activityTitle;
|
||||||
selectedActivity.name = activitySubtitle;
|
selectedActivity.name = activitySubtitle;
|
||||||
selectedActivity.maxMembers = activityMaxPlayers;
|
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 {
|
} else {
|
||||||
const rawIdxPath: Array<string> = finalizedIdxPath.split(pathIdxSeparator);
|
const rawIdxPath: Array<string> = finalizedIdxPath.split(pathIdxSeparator);
|
||||||
const idxPath: Array<number> = rawIdxPath.map((rawIdx) => rawIdx ? parseInt(rawIdx) : -1);
|
const idxPath: Array<number> = rawIdxPath.map((rawIdx) => rawIdx ? parseInt(rawIdx) : -1);
|
||||||
|
@ -193,13 +195,12 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
||||||
data: {
|
data: {
|
||||||
embeds: [{
|
embeds: [{
|
||||||
title: 'Please select a Game and Activity, or create a Custom Event.',
|
title: 'Please select a Game and Activity, or create a Custom Event.',
|
||||||
description: `Changing activity for [this event](${
|
description: `Changing activity for [this event](${utils.idsToMessageUrl({
|
||||||
utils.idsToMessageUrl({
|
guildId: interaction.guildId,
|
||||||
guildId: interaction.guildId,
|
channelId: evtChannelId,
|
||||||
channelId: evtChannelId,
|
messageId: evtMessageId,
|
||||||
messageId: evtMessageId,
|
})
|
||||||
})
|
}).\n\n${selfDestructMessage(new Date().getTime())}`,
|
||||||
}).\n\n${selfDestructMessage(new Date().getTime())}`,
|
|
||||||
color: infoColor1,
|
color: infoColor1,
|
||||||
}],
|
}],
|
||||||
flags: ApplicationCommandFlags.Ephemeral,
|
flags: ApplicationCommandFlags.Ephemeral,
|
||||||
|
|
|
@ -19,6 +19,7 @@ export const queries = {
|
||||||
updateEventTime: 'UPDATE active_events SET eventTime = ? WHERE channelId = ? AND messageId = ?',
|
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 = ?`,
|
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 = ?',
|
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();
|
export const lfgChannelSettings: Map<string, LfgChannelSetting> = new Map();
|
||||||
|
|
Loading…
Reference in New Issue