diff --git a/db/populateDefaults.ts b/db/populateDefaults.ts index bd2c4bb..727643a 100644 --- a/db/populateDefaults.ts +++ b/db/populateDefaults.ts @@ -10,7 +10,7 @@ await dbClient.execute('INSERT INTO all_keys(userid,apiKey) values(?,?)', [confi console.log('Inesrtion done'); console.log('Attempting to insert default commands into command_cnt'); -const commands = ['ping', 'rip', 'rollhelp', 'help', 'info', 'version', 'report', 'stats', 'roll', 'emojis', 'api', 'privacy', 'mention', 'audit']; +const commands = ['ping', 'rip', 'rollhelp', 'help', 'info', 'version', 'report', 'stats', 'roll', 'emojis', 'api', 'privacy', 'mention', 'audit', 'heatmap']; for (const command of commands) { await dbClient.execute('INSERT INTO command_cnt(command) values(?)', [command]).catch((e) => { console.log(`Failed to insert ${command} into database`, e); diff --git a/mod.ts b/mod.ts index b71827b..0f1b727 100644 --- a/mod.ts +++ b/mod.ts @@ -196,6 +196,12 @@ startBot({ // Audit sub commands commands.audit(message, args); break; + case 'heatmap': + case 'hm': + // [[heatmap or [[hm + // Audit sub commands + commands.heatmap(message); + break; default: // Non-standard commands if (command?.startsWith('xdy')) { diff --git a/src/commands/_index.ts b/src/commands/_index.ts index ad6a367..e0388e9 100644 --- a/src/commands/_index.ts +++ b/src/commands/_index.ts @@ -12,6 +12,7 @@ import { emoji } from './emoji.ts'; import { roll } from './roll.ts'; import { handleMentions } from './handleMentions.ts'; import { audit } from './audit.ts'; +import { heatmap } from './heatmap.ts'; export default { ping, @@ -28,4 +29,5 @@ export default { roll, handleMentions, audit, + heatmap, }; diff --git a/src/commands/auditCmd/auditDB.ts b/src/commands/auditCmd/auditDB.ts index 31930c3..a4927fd 100644 --- a/src/commands/auditCmd/auditDB.ts +++ b/src/commands/auditCmd/auditDB.ts @@ -35,7 +35,7 @@ export const auditDB = async (message: DiscordenoMessage) => { timestamp: new Date().toISOString(), fields: embedFields, }], - }).catch((e: Error) => utils.commonLoggers.messageSendError('auditDB.ts:43', message, e)); + }).catch((e: Error) => utils.commonLoggers.messageEditError('auditDB.ts:43', message, e)); } catch (e) { utils.commonLoggers.messageSendError('auditDB.ts:45', message, e); } diff --git a/src/commands/heatmap.ts b/src/commands/heatmap.ts new file mode 100644 index 0000000..23f193d --- /dev/null +++ b/src/commands/heatmap.ts @@ -0,0 +1,27 @@ +import { dbClient, queries } from '../db.ts'; +import { + // Discordeno deps + DiscordenoMessage, +} from '../../deps.ts'; +import { } from '../commandUtils.ts'; +import { compilingStats } from '../commonEmbeds.ts'; +import utils from '../utils.ts'; + +export const heatmap = async (message: DiscordenoMessage) => { + // Light telemetry to see how many times a command is being run + dbClient.execute(queries.callIncCnt('heatmap')).catch((e) => utils.commonLoggers.dbError('heatmap.ts:14', 'call sproc INC_CNT on', e)); + + try { + const m = await message.send(compilingStats); + + // Calculate how many times commands have been run + const hmQuery = await dbClient.query(`SELECT * FROM roll_time_heatmap`).catch((e) => utils.commonLoggers.dbError('heatmap.ts:20', 'query', e)); + console.log(hmQuery); + + m.edit('').catch((e: Error) => + utils.commonLoggers.messageEditError('heatmap.ts:21', m, e) + ); + } catch (e) { + utils.commonLoggers.messageSendError('heatmap.ts:24', message, e); + } +}; diff --git a/src/commands/stats.ts b/src/commands/stats.ts index 24c2218..1e26cd5 100644 --- a/src/commands/stats.ts +++ b/src/commands/stats.ts @@ -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(queries.callIncCnt('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:14', 'call sproc INC_CNT on', e)); try { const m = await message.send(compilingStats); @@ -28,7 +28,7 @@ export const stats = async (message: DiscordenoMessage) => { const cachedChannels = await cacheHandlers.size('channels'); const cachedMembers = await cacheHandlers.size('members'); m.edit(generateStats(cachedGuilds + cache.dispatchedGuildIds.size, cachedChannels + cache.dispatchedChannelIds.size, cachedMembers, rolls, (total - rolls), rollRate, (totalRate - rollRate))).catch((e: Error) => - utils.commonLoggers.messageSendError('stats.ts:38', message, e) + utils.commonLoggers.messageEditError('stats.ts:38', m, e) ); } catch (e) { utils.commonLoggers.messageSendError('stats.ts:41', message, e); diff --git a/src/solver/rollQueue.ts b/src/solver/rollQueue.ts index 2da271f..5f28caf 100644 --- a/src/solver/rollQueue.ts +++ b/src/solver/rollQueue.ts @@ -190,7 +190,7 @@ export const queueRoll = async (rq: QueuedRoll) => { The results for this roll will replace this message when it is done.`, }], - }).catch((e: Error) => utils.commonLoggers.messageSendError('rollQueue.ts:197', rq.dd.m, e)); + }).catch((e: Error) => utils.commonLoggers.messageEditError('rollQueue.ts:197', rq.dd.m, e)); rollQueue.push(rq); } }; @@ -201,7 +201,7 @@ setInterval(async () => { if (rollQueue.length && currentWorkers < config.limits.maxWorkers) { const temp = rollQueue.shift(); if (temp) { - temp.dd.m.edit(rollingEmbed).catch((e: Error) => utils.commonLoggers.messageSendError('rollQueue.ts:208', temp.dd.m, e)); + temp.dd.m.edit(rollingEmbed).catch((e: Error) => utils.commonLoggers.messageEditError('rollQueue.ts:208', temp.dd.m, e)); handleRollWorker(temp); } }