created callIncCnt function for simplicity

This commit is contained in:
Ean Milligan (Bastion) 2022-06-24 21:32:18 -04:00
parent b0266ad385
commit 011120845e
15 changed files with 29 additions and 28 deletions

View File

@ -1,4 +1,4 @@
import { dbClient } from '../db.ts'; import { dbClient, queries } from '../db.ts';
import { import {
// Discordeno deps // Discordeno deps
DiscordenoMessage, DiscordenoMessage,
@ -10,7 +10,7 @@ import utils from '../utils.ts';
export const api = async (message: DiscordenoMessage, args: string[]) => { export const api = async (message: DiscordenoMessage, args: string[]) => {
// Light telemetry to see how many times a command is being run // 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 // Local apiArg in lowercase
const apiArg = (args[0] || 'help').toLowerCase(); const apiArg = (args[0] || 'help').toLowerCase();

View File

@ -1,5 +1,5 @@
import config from '../../config.ts'; import config from '../../config.ts';
import { dbClient } from '../db.ts'; import { dbClient, queries } from '../db.ts';
import { import {
// Discordeno deps // Discordeno deps
DiscordenoMessage, DiscordenoMessage,
@ -10,7 +10,7 @@ import utils from '../utils.ts';
export const audit = async (message: DiscordenoMessage, args: string[]) => { export const audit = async (message: DiscordenoMessage, args: string[]) => {
// Light telemetry to see how many times a command is being run // 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 // Local apiArg in lowercase
const auditArg = (args[0] || 'help').toLowerCase(); const auditArg = (args[0] || 'help').toLowerCase();

View File

@ -1,5 +1,5 @@
import config from '../../config.ts'; import config from '../../config.ts';
import { dbClient } from '../db.ts'; import { dbClient, queries } from '../db.ts';
import { import {
// Discordeno deps // Discordeno deps
DiscordenoMessage, DiscordenoMessage,
@ -25,7 +25,7 @@ export const emoji = (message: DiscordenoMessage, command: string) => {
// If a match gets found // If a match gets found
if (emji.aliases.indexOf(command || '') > -1) { if (emji.aliases.indexOf(command || '') > -1) {
// Light telemetry to see how many times a command is being run // 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 // Send the needed emoji
message.send(`<${emji.animated ? 'a' : ''}:${emji.name}:${emji.id}>`).catch((e: Error) => utils.commonLoggers.messageSendError('emoji.ts:33', message, e)); message.send(`<${emji.animated ? 'a' : ''}:${emji.name}:${emji.id}>`).catch((e: Error) => utils.commonLoggers.messageSendError('emoji.ts:33', message, e));

View File

@ -1,5 +1,5 @@
import config from '../../config.ts'; import config from '../../config.ts';
import { dbClient } from '../db.ts'; import { dbClient, queries } from '../db.ts';
import { import {
// Discordeno deps // Discordeno deps
DiscordenoMessage, DiscordenoMessage,
@ -14,7 +14,7 @@ export const handleMentions = (message: DiscordenoMessage) => {
log(LT.LOG, `Handling @mention message: ${JSON.stringify(message)}`); log(LT.LOG, `Handling @mention message: ${JSON.stringify(message)}`);
// Light telemetry to see how many times a command is being run // 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({ message.send({
embeds: [{ embeds: [{

View File

@ -1,5 +1,5 @@
import config from '../../config.ts'; import config from '../../config.ts';
import { dbClient } from '../db.ts'; import { dbClient, queries } from '../db.ts';
import { import {
// Discordeno deps // Discordeno deps
DiscordenoMessage, DiscordenoMessage,
@ -9,7 +9,7 @@ import utils from '../utils.ts';
export const help = (message: DiscordenoMessage) => { export const help = (message: DiscordenoMessage) => {
// Light telemetry to see how many times a command is being run // 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({ message.send({
embeds: [{ embeds: [{

View File

@ -1,4 +1,4 @@
import { dbClient } from '../db.ts'; import { dbClient, queries } from '../db.ts';
import { import {
// Discordeno deps // Discordeno deps
DiscordenoMessage, DiscordenoMessage,
@ -8,7 +8,7 @@ import utils from '../utils.ts';
export const info = (message: DiscordenoMessage) => { export const info = (message: DiscordenoMessage) => {
// Light telemetry to see how many times a command is being run // 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({ message.send({
embeds: [{ embeds: [{

View File

@ -1,4 +1,4 @@
import { dbClient } from '../db.ts'; import { dbClient, queries } from '../db.ts';
import { import {
// Discordeno deps // Discordeno deps
DiscordenoMessage, DiscordenoMessage,
@ -8,7 +8,7 @@ import utils from '../utils.ts';
export const ping = async (message: DiscordenoMessage) => { export const ping = async (message: DiscordenoMessage) => {
// Light telemetry to see how many times a command is being run // 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. // Calculates ping between sending a message and editing it, giving a nice round-trip latency.
try { try {

View File

@ -1,5 +1,5 @@
import config from '../../config.ts'; import config from '../../config.ts';
import { dbClient } from '../db.ts'; import { dbClient, queries } from '../db.ts';
import { import {
// Discordeno deps // Discordeno deps
DiscordenoMessage, DiscordenoMessage,
@ -9,7 +9,7 @@ import utils from '../utils.ts';
export const privacy = (message: DiscordenoMessage) => { export const privacy = (message: DiscordenoMessage) => {
// Light telemetry to see how many times a command is being run // 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({ message.send({
embeds: [{ embeds: [{

View File

@ -1,5 +1,5 @@
import config from '../../config.ts'; import config from '../../config.ts';
import { dbClient } from '../db.ts'; import { dbClient, queries } from '../db.ts';
import { import {
// Discordeno deps // Discordeno deps
DiscordenoMessage, DiscordenoMessage,
@ -11,7 +11,7 @@ import utils from '../utils.ts';
export const report = (message: DiscordenoMessage, args: string[]) => { export const report = (message: DiscordenoMessage, args: string[]) => {
// Light telemetry to see how many times a command is being run // 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(' ')) { if (args.join(' ')) {
sendMessage(config.reportChannel, generateReport(args.join(' '))).catch((e: Error) => utils.commonLoggers.messageSendError('report.ts:22', message, e)); sendMessage(config.reportChannel, generateReport(args.join(' '))).catch((e: Error) => utils.commonLoggers.messageSendError('report.ts:22', message, e));

View File

@ -1,4 +1,4 @@
import { dbClient } from '../db.ts'; import { dbClient, queries } from '../db.ts';
import { import {
// Discordeno deps // Discordeno deps
DiscordenoMessage, DiscordenoMessage,
@ -8,7 +8,7 @@ import utils from '../utils.ts';
export const rip = (message: DiscordenoMessage) => { export const rip = (message: DiscordenoMessage) => {
// Light telemetry to see how many times a command is being run // 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({ message.send({
embeds: [{ embeds: [{

View File

@ -1,6 +1,6 @@
import config from '../../config.ts'; import config from '../../config.ts';
import { DEVMODE } from '../../flags.ts'; import { DEVMODE } from '../../flags.ts';
import { dbClient } from '../db.ts'; import { dbClient, queries } from '../db.ts';
import { import {
// Discordeno deps // Discordeno deps
DiscordenoMessage, DiscordenoMessage,
@ -16,7 +16,7 @@ import utils from '../utils.ts';
export const roll = async (message: DiscordenoMessage, args: string[], command: string) => { export const roll = async (message: DiscordenoMessage, args: string[], command: string) => {
// Light telemetry to see how many times a command is being run // 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 is on, only allow this command to be used in the devServer
if (DEVMODE && message.guildId !== config.devServer) { if (DEVMODE && message.guildId !== config.devServer) {

View File

@ -1,5 +1,5 @@
import config from '../../config.ts'; import config from '../../config.ts';
import { dbClient } from '../db.ts'; import { dbClient, queries } from '../db.ts';
import { import {
// Discordeno deps // Discordeno deps
DiscordenoMessage, DiscordenoMessage,
@ -9,7 +9,7 @@ import utils from '../utils.ts';
export const rollHelp = (message: DiscordenoMessage) => { export const rollHelp = (message: DiscordenoMessage) => {
// Light telemetry to see how many times a command is being run // 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({ message.send({
embeds: [ embeds: [

View File

@ -1,4 +1,4 @@
import { dbClient } from '../db.ts'; import { dbClient, queries } from '../db.ts';
import { import {
// Discordeno deps // Discordeno deps
cache, cache,
@ -11,7 +11,7 @@ import utils from '../utils.ts';
export const stats = async (message: DiscordenoMessage) => { export const stats = async (message: DiscordenoMessage) => {
// Light telemetry to see how many times a command is being run // 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 { try {
const m = await message.send(compilingStats); const m = await message.send(compilingStats);

View File

@ -1,5 +1,5 @@
import config from '../../config.ts'; import config from '../../config.ts';
import { dbClient } from '../db.ts'; import { dbClient, queries } from '../db.ts';
import { import {
// Discordeno deps // Discordeno deps
DiscordenoMessage, DiscordenoMessage,
@ -9,7 +9,7 @@ import utils from '../utils.ts';
export const version = (message: DiscordenoMessage) => { export const version = (message: DiscordenoMessage) => {
// Light telemetry to see how many times a command is being run // 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({ message.send({
embeds: [{ embeds: [{

View File

@ -12,4 +12,5 @@ export const dbClient = await new Client().connect({
export const queries = { export const queries = {
insertRollLogCmd: (api: number, error: number) => `INSERT INTO roll_log(input,result,resultid,api,error) values(?,?,?,${api},${error})`, insertRollLogCmd: (api: number, error: number) => `INSERT INTO roll_log(input,result,resultid,api,error) values(?,?,?,${api},${error})`,
callIncCnt: (cmdName: string) => `CALL INC_CNT("${cmdName}");`,
}; };