From fa0ffe35e502b98dc778b200eba02de1098c98f7 Mon Sep 17 00:00:00 2001 From: "Ean Milligan (Bastion)" Date: Fri, 7 Apr 2023 01:45:33 -0400 Subject: [PATCH] Properly initialize join/leave/alt btns --- db/populateDefaults.ts | 4 ++++ src/buttons/live-event/alternateEvent.ts | 12 +++++++++++- src/buttons/live-event/joinEvent.ts | 15 ++++++++++++++- src/buttons/live-event/leaveEvent.ts | 12 +++++++++++- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/db/populateDefaults.ts b/db/populateDefaults.ts index b93fe0a..e5bc476 100644 --- a/db/populateDefaults.ts +++ b/db/populateDefaults.ts @@ -13,6 +13,10 @@ const actions = [ 'btn-customAct', 'btn-createEvt', 'btn-createWLEvt', + 'btn-joinEvent', + 'btn-joinWLEvent', + 'btn-leaveEvent', + 'btn-altEvent', ]; for (const action of actions) { await dbClient.execute('INSERT INTO command_cnt(command) values(?)', [action]).catch((e) => { diff --git a/src/buttons/live-event/alternateEvent.ts b/src/buttons/live-event/alternateEvent.ts index 64b3a74..cf260e7 100644 --- a/src/buttons/live-event/alternateEvent.ts +++ b/src/buttons/live-event/alternateEvent.ts @@ -1,8 +1,18 @@ import { Bot, Interaction } from '../../../deps.ts'; +import { dbClient, queries } from '../../db.ts'; +import { somethingWentWrong } from '../../commandUtils.ts'; +import utils from '../../utils.ts'; export const customId = 'alternateEvent'; -export const execute = async (bot: Bot, interaction: Interaction) => {}; +export const execute = async (bot: Bot, interaction: Interaction) => { + if (interaction.data?.customId && interaction.member && interaction.message && interaction.message.embeds[0] && interaction.message.embeds[0].fields) { + // Light Telemetry + dbClient.execute(queries.callIncCnt('btn-altEvent')).catch((e) => utils.commonLoggers.dbError('alternateEvent.ts', 'call sproc INC_CNT on', e)); + } else { + somethingWentWrong(bot, interaction, 'noDataFromAlternateEventButton'); + } +}; export const alternateEventButton = { customId, diff --git a/src/buttons/live-event/joinEvent.ts b/src/buttons/live-event/joinEvent.ts index f50d4c1..683eae0 100644 --- a/src/buttons/live-event/joinEvent.ts +++ b/src/buttons/live-event/joinEvent.ts @@ -1,8 +1,21 @@ import { Bot, Interaction } from '../../../deps.ts'; +import { dbClient, queries } from '../../db.ts'; +import { somethingWentWrong } from '../../commandUtils.ts'; +import { idSeparator } from '../event-creation/utils.ts'; +import utils from '../../utils.ts'; export const customId = 'joinEvent'; -export const execute = async (bot: Bot, interaction: Interaction) => {}; +export const execute = async (bot: Bot, interaction: Interaction) => { + if (interaction.data?.customId && interaction.member && interaction.message && interaction.message.embeds[0] && interaction.message.embeds[0].fields) { + // Light Telemetry + dbClient.execute(queries.callIncCnt(interaction.data.customId.includes(idSeparator) ? 'btn-joinWLEvent' : 'btn-joinEvent')).catch((e) => + utils.commonLoggers.dbError('joinEvent.ts', 'call sproc INC_CNT on', e) + ); + } else { + somethingWentWrong(bot, interaction, 'noDataFromJoinEventButton'); + } +}; export const joinEventButton = { customId, diff --git a/src/buttons/live-event/leaveEvent.ts b/src/buttons/live-event/leaveEvent.ts index ba9d2eb..108298a 100644 --- a/src/buttons/live-event/leaveEvent.ts +++ b/src/buttons/live-event/leaveEvent.ts @@ -1,8 +1,18 @@ import { Bot, Interaction } from '../../../deps.ts'; +import { dbClient, queries } from '../../db.ts'; +import { somethingWentWrong } from '../../commandUtils.ts'; +import utils from '../../utils.ts'; export const customId = 'leaveEvent'; -export const execute = async (bot: Bot, interaction: Interaction) => {}; +export const execute = async (bot: Bot, interaction: Interaction) => { + if (interaction.data?.customId && interaction.member && interaction.message && interaction.message.embeds[0] && interaction.message.embeds[0].fields) { + // Light Telemetry + dbClient.execute(queries.callIncCnt('btn-leaveEvent')).catch((e) => utils.commonLoggers.dbError('leaveEvent.ts', 'call sproc INC_CNT on', e)); + } else { + somethingWentWrong(bot, interaction, 'noDataFromLeaveEventButton'); + } +}; export const leaveEventButton = { customId,