From 011120845e043f78f3fcc9c0dbfaf6c28332c1b2 Mon Sep 17 00:00:00 2001 From: "Ean Milligan (Bastion)" Date: Fri, 24 Jun 2022 21:32:18 -0400 Subject: [PATCH] created callIncCnt function for simplicity --- src/commands/apiCmd.ts | 4 ++-- src/commands/audit.ts | 4 ++-- src/commands/emoji.ts | 4 ++-- src/commands/handleMentions.ts | 4 ++-- src/commands/help.ts | 4 ++-- src/commands/info.ts | 4 ++-- src/commands/ping.ts | 4 ++-- src/commands/privacy.ts | 4 ++-- src/commands/report.ts | 4 ++-- src/commands/rip.ts | 4 ++-- src/commands/roll.ts | 4 ++-- src/commands/rollHelp.ts | 4 ++-- src/commands/stats.ts | 4 ++-- src/commands/version.ts | 4 ++-- src/db.ts | 1 + 15 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/commands/apiCmd.ts b/src/commands/apiCmd.ts index 8d5d684..88cd481 100644 --- a/src/commands/apiCmd.ts +++ b/src/commands/apiCmd.ts @@ -1,4 +1,4 @@ -import { dbClient } from '../db.ts'; +import { dbClient, queries } from '../db.ts'; import { // Discordeno deps DiscordenoMessage, @@ -10,7 +10,7 @@ import utils from '../utils.ts'; export const api = async (message: DiscordenoMessage, args: string[]) => { // Light telemetry to see how many times a command is being run - dbClient.execute(`CALL INC_CNT("api");`).catch((e) => utils.commonLoggers.dbError('apiCmd.ts:16', 'call sproc INC_CNT on', e)); + dbClient.execute(queries.callIncCnt('api')).catch((e) => utils.commonLoggers.dbError('apiCmd.ts:16', 'call sproc INC_CNT on', e)); // Local apiArg in lowercase const apiArg = (args[0] || 'help').toLowerCase(); diff --git a/src/commands/audit.ts b/src/commands/audit.ts index 43eea83..306cb96 100644 --- a/src/commands/audit.ts +++ b/src/commands/audit.ts @@ -1,5 +1,5 @@ import config from '../../config.ts'; -import { dbClient } from '../db.ts'; +import { dbClient, queries } from '../db.ts'; import { // Discordeno deps DiscordenoMessage, @@ -10,7 +10,7 @@ import utils from '../utils.ts'; export const audit = async (message: DiscordenoMessage, args: string[]) => { // Light telemetry to see how many times a command is being run - dbClient.execute(`CALL INC_CNT("audit");`).catch((e) => utils.commonLoggers.dbError('audit.ts:16', 'call sproc INC_CNT on', e)); + dbClient.execute(queries.callIncCnt('audit')).catch((e) => utils.commonLoggers.dbError('audit.ts:16', 'call sproc INC_CNT on', e)); // Local apiArg in lowercase const auditArg = (args[0] || 'help').toLowerCase(); diff --git a/src/commands/emoji.ts b/src/commands/emoji.ts index 9f5b7bc..e348fa6 100644 --- a/src/commands/emoji.ts +++ b/src/commands/emoji.ts @@ -1,5 +1,5 @@ import config from '../../config.ts'; -import { dbClient } from '../db.ts'; +import { dbClient, queries } from '../db.ts'; import { // Discordeno deps DiscordenoMessage, @@ -25,7 +25,7 @@ export const emoji = (message: DiscordenoMessage, command: string) => { // If a match gets found if (emji.aliases.indexOf(command || '') > -1) { // Light telemetry to see how many times a command is being run - dbClient.execute(`CALL INC_CNT("emojis");`).catch((e) => utils.commonLoggers.dbError('emojis.ts:28', 'call sproc INC_CNT on', e)); + dbClient.execute(queries.callIncCnt('emojis')).catch((e) => utils.commonLoggers.dbError('emojis.ts:28', 'call sproc INC_CNT on', e)); // Send the needed emoji message.send(`<${emji.animated ? 'a' : ''}:${emji.name}:${emji.id}>`).catch((e: Error) => utils.commonLoggers.messageSendError('emoji.ts:33', message, e)); diff --git a/src/commands/handleMentions.ts b/src/commands/handleMentions.ts index 68a1b93..b90b463 100644 --- a/src/commands/handleMentions.ts +++ b/src/commands/handleMentions.ts @@ -1,5 +1,5 @@ import config from '../../config.ts'; -import { dbClient } from '../db.ts'; +import { dbClient, queries } from '../db.ts'; import { // Discordeno deps DiscordenoMessage, @@ -14,7 +14,7 @@ export const handleMentions = (message: DiscordenoMessage) => { log(LT.LOG, `Handling @mention message: ${JSON.stringify(message)}`); // Light telemetry to see how many times a command is being run - dbClient.execute(`CALL INC_CNT("mention");`).catch((e) => utils.commonLoggers.dbError('handleMentions.ts:17', 'call sproc INC_CNT on', e)); + dbClient.execute(queries.callIncCnt('mention')).catch((e) => utils.commonLoggers.dbError('handleMentions.ts:17', 'call sproc INC_CNT on', e)); message.send({ embeds: [{ diff --git a/src/commands/help.ts b/src/commands/help.ts index 7f7a2a8..e91eaa4 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -1,5 +1,5 @@ import config from '../../config.ts'; -import { dbClient } from '../db.ts'; +import { dbClient, queries } from '../db.ts'; import { // Discordeno deps DiscordenoMessage, @@ -9,7 +9,7 @@ import utils from '../utils.ts'; export const help = (message: DiscordenoMessage) => { // Light telemetry to see how many times a command is being run - dbClient.execute(`CALL INC_CNT("help");`).catch((e) => utils.commonLoggers.dbError('htlp.ts:15', 'call sproc INC_CNT on', e)); + dbClient.execute(queries.callIncCnt('help')).catch((e) => utils.commonLoggers.dbError('htlp.ts:15', 'call sproc INC_CNT on', e)); message.send({ embeds: [{ diff --git a/src/commands/info.ts b/src/commands/info.ts index b918c5c..cf6b3c2 100644 --- a/src/commands/info.ts +++ b/src/commands/info.ts @@ -1,4 +1,4 @@ -import { dbClient } from '../db.ts'; +import { dbClient, queries } from '../db.ts'; import { // Discordeno deps DiscordenoMessage, @@ -8,7 +8,7 @@ import utils from '../utils.ts'; export const info = (message: DiscordenoMessage) => { // Light telemetry to see how many times a command is being run - dbClient.execute(`CALL INC_CNT("info");`).catch((e) => utils.commonLoggers.dbError('info.ts:14', 'call sproc INC_CNT on', e)); + dbClient.execute(queries.callIncCnt('info')).catch((e) => utils.commonLoggers.dbError('info.ts:14', 'call sproc INC_CNT on', e)); message.send({ embeds: [{ diff --git a/src/commands/ping.ts b/src/commands/ping.ts index 56e32d7..39cf5d2 100644 --- a/src/commands/ping.ts +++ b/src/commands/ping.ts @@ -1,4 +1,4 @@ -import { dbClient } from '../db.ts'; +import { dbClient, queries } from '../db.ts'; import { // Discordeno deps DiscordenoMessage, @@ -8,7 +8,7 @@ import utils from '../utils.ts'; export const ping = async (message: DiscordenoMessage) => { // Light telemetry to see how many times a command is being run - dbClient.execute(`CALL INC_CNT("ping");`).catch((e) => utils.commonLoggers.dbError('ping.ts:14', 'call sproc INC_CNT on', e)); + dbClient.execute(queries.callIncCnt('ping')).catch((e) => utils.commonLoggers.dbError('ping.ts:14', 'call sproc INC_CNT on', e)); // Calculates ping between sending a message and editing it, giving a nice round-trip latency. try { diff --git a/src/commands/privacy.ts b/src/commands/privacy.ts index 5a4716d..d916dbb 100644 --- a/src/commands/privacy.ts +++ b/src/commands/privacy.ts @@ -1,5 +1,5 @@ import config from '../../config.ts'; -import { dbClient } from '../db.ts'; +import { dbClient, queries } from '../db.ts'; import { // Discordeno deps DiscordenoMessage, @@ -9,7 +9,7 @@ import utils from '../utils.ts'; export const privacy = (message: DiscordenoMessage) => { // Light telemetry to see how many times a command is being run - dbClient.execute(`CALL INC_CNT("privacy");`).catch((e) => utils.commonLoggers.dbError('privacy.ts:15', 'call sproc INC_CNT on', e)); + dbClient.execute(queries.callIncCnt('privacy')).catch((e) => utils.commonLoggers.dbError('privacy.ts:15', 'call sproc INC_CNT on', e)); message.send({ embeds: [{ diff --git a/src/commands/report.ts b/src/commands/report.ts index 106eaad..4fc39e9 100644 --- a/src/commands/report.ts +++ b/src/commands/report.ts @@ -1,5 +1,5 @@ import config from '../../config.ts'; -import { dbClient } from '../db.ts'; +import { dbClient, queries } from '../db.ts'; import { // Discordeno deps DiscordenoMessage, @@ -11,7 +11,7 @@ import utils from '../utils.ts'; export const report = (message: DiscordenoMessage, args: string[]) => { // Light telemetry to see how many times a command is being run - dbClient.execute(`CALL INC_CNT("report");`).catch((e) => utils.commonLoggers.dbError('report.ts:17', 'call sproc INC_CNT on', e)); + dbClient.execute(queries.callIncCnt('report')).catch((e) => utils.commonLoggers.dbError('report.ts:17', 'call sproc INC_CNT on', e)); if (args.join(' ')) { sendMessage(config.reportChannel, generateReport(args.join(' '))).catch((e: Error) => utils.commonLoggers.messageSendError('report.ts:22', message, e)); diff --git a/src/commands/rip.ts b/src/commands/rip.ts index ed2945e..5f25759 100644 --- a/src/commands/rip.ts +++ b/src/commands/rip.ts @@ -1,4 +1,4 @@ -import { dbClient } from '../db.ts'; +import { dbClient, queries } from '../db.ts'; import { // Discordeno deps DiscordenoMessage, @@ -8,7 +8,7 @@ import utils from '../utils.ts'; export const rip = (message: DiscordenoMessage) => { // Light telemetry to see how many times a command is being run - dbClient.execute(`CALL INC_CNT("rip");`).catch((e) => utils.commonLoggers.dbError('rip.ts:14', 'call sproc INC_CNT on', e)); + dbClient.execute(queries.callIncCnt('rip')).catch((e) => utils.commonLoggers.dbError('rip.ts:14', 'call sproc INC_CNT on', e)); message.send({ embeds: [{ diff --git a/src/commands/roll.ts b/src/commands/roll.ts index c8e9b90..1a21f48 100644 --- a/src/commands/roll.ts +++ b/src/commands/roll.ts @@ -1,6 +1,6 @@ import config from '../../config.ts'; import { DEVMODE } from '../../flags.ts'; -import { dbClient } from '../db.ts'; +import { dbClient, queries } from '../db.ts'; import { // Discordeno deps DiscordenoMessage, @@ -16,7 +16,7 @@ import utils from '../utils.ts'; export const roll = async (message: DiscordenoMessage, args: string[], command: string) => { // Light telemetry to see how many times a command is being run - dbClient.execute(`CALL INC_CNT("roll");`).catch((e) => utils.commonLoggers.dbError('roll.ts:19', 'call sproc INC_CNT on', e)); + dbClient.execute(queries.callIncCnt('roll')).catch((e) => utils.commonLoggers.dbError('roll.ts:19', 'call sproc INC_CNT on', e)); // If DEVMODE is on, only allow this command to be used in the devServer if (DEVMODE && message.guildId !== config.devServer) { diff --git a/src/commands/rollHelp.ts b/src/commands/rollHelp.ts index 92043ff..0142151 100644 --- a/src/commands/rollHelp.ts +++ b/src/commands/rollHelp.ts @@ -1,5 +1,5 @@ import config from '../../config.ts'; -import { dbClient } from '../db.ts'; +import { dbClient, queries } from '../db.ts'; import { // Discordeno deps DiscordenoMessage, @@ -9,7 +9,7 @@ import utils from '../utils.ts'; export const rollHelp = (message: DiscordenoMessage) => { // Light telemetry to see how many times a command is being run - dbClient.execute(`CALL INC_CNT("rollhelp");`).catch((e) => utils.commonLoggers.dbError('rollHelp.ts:15', 'call sproc INC_CNT on', e)); + dbClient.execute(queries.callIncCnt('rollhelp')).catch((e) => utils.commonLoggers.dbError('rollHelp.ts:15', 'call sproc INC_CNT on', e)); message.send({ embeds: [ diff --git a/src/commands/stats.ts b/src/commands/stats.ts index ad220d7..d6272e0 100644 --- a/src/commands/stats.ts +++ b/src/commands/stats.ts @@ -1,4 +1,4 @@ -import { dbClient } from '../db.ts'; +import { dbClient, queries } from '../db.ts'; import { // Discordeno deps cache, @@ -11,7 +11,7 @@ import utils from '../utils.ts'; export const stats = async (message: DiscordenoMessage) => { // Light telemetry to see how many times a command is being run - dbClient.execute(`CALL INC_CNT("stats");`).catch((e) => utils.commonLoggers.dbError('stats.ts', 'call sproc INC_CNT on', e)); + dbClient.execute(queries.callIncCnt('stats')).catch((e) => utils.commonLoggers.dbError('stats.ts', 'call sproc INC_CNT on', e)); try { const m = await message.send(compilingStats); diff --git a/src/commands/version.ts b/src/commands/version.ts index d4e72d0..35ae95a 100644 --- a/src/commands/version.ts +++ b/src/commands/version.ts @@ -1,5 +1,5 @@ import config from '../../config.ts'; -import { dbClient } from '../db.ts'; +import { dbClient, queries } from '../db.ts'; import { // Discordeno deps DiscordenoMessage, @@ -9,7 +9,7 @@ import utils from '../utils.ts'; export const version = (message: DiscordenoMessage) => { // Light telemetry to see how many times a command is being run - dbClient.execute(`CALL INC_CNT("version");`).catch((e) => utils.commonLoggers.dbError('version.ts:15', 'call sproc INC_CNT on', e)); + dbClient.execute(queries.callIncCnt('version')).catch((e) => utils.commonLoggers.dbError('version.ts:15', 'call sproc INC_CNT on', e)); message.send({ embeds: [{ diff --git a/src/db.ts b/src/db.ts index 65ef64b..ec83c63 100644 --- a/src/db.ts +++ b/src/db.ts @@ -12,4 +12,5 @@ export const dbClient = await new Client().connect({ export const queries = { insertRollLogCmd: (api: number, error: number) => `INSERT INTO roll_log(input,result,resultid,api,error) values(?,?,?,${api},${error})`, + callIncCnt: (cmdName: string) => `CALL INC_CNT("${cmdName}");`, };