Initial work on [[heatmap, fixed some loggers to be edit instead of send
This commit is contained in:
parent
2b22df032c
commit
e8464cf7bb
|
@ -10,7 +10,7 @@ await dbClient.execute('INSERT INTO all_keys(userid,apiKey) values(?,?)', [confi
|
||||||
console.log('Inesrtion done');
|
console.log('Inesrtion done');
|
||||||
|
|
||||||
console.log('Attempting to insert default commands into command_cnt');
|
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) {
|
for (const command of commands) {
|
||||||
await dbClient.execute('INSERT INTO command_cnt(command) values(?)', [command]).catch((e) => {
|
await dbClient.execute('INSERT INTO command_cnt(command) values(?)', [command]).catch((e) => {
|
||||||
console.log(`Failed to insert ${command} into database`, e);
|
console.log(`Failed to insert ${command} into database`, e);
|
||||||
|
|
6
mod.ts
6
mod.ts
|
@ -196,6 +196,12 @@ startBot({
|
||||||
// Audit sub commands
|
// Audit sub commands
|
||||||
commands.audit(message, args);
|
commands.audit(message, args);
|
||||||
break;
|
break;
|
||||||
|
case 'heatmap':
|
||||||
|
case 'hm':
|
||||||
|
// [[heatmap or [[hm
|
||||||
|
// Audit sub commands
|
||||||
|
commands.heatmap(message);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
// Non-standard commands
|
// Non-standard commands
|
||||||
if (command?.startsWith('xdy')) {
|
if (command?.startsWith('xdy')) {
|
||||||
|
|
|
@ -12,6 +12,7 @@ import { emoji } from './emoji.ts';
|
||||||
import { roll } from './roll.ts';
|
import { roll } from './roll.ts';
|
||||||
import { handleMentions } from './handleMentions.ts';
|
import { handleMentions } from './handleMentions.ts';
|
||||||
import { audit } from './audit.ts';
|
import { audit } from './audit.ts';
|
||||||
|
import { heatmap } from './heatmap.ts';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
ping,
|
ping,
|
||||||
|
@ -28,4 +29,5 @@ export default {
|
||||||
roll,
|
roll,
|
||||||
handleMentions,
|
handleMentions,
|
||||||
audit,
|
audit,
|
||||||
|
heatmap,
|
||||||
};
|
};
|
||||||
|
|
|
@ -35,7 +35,7 @@ export const auditDB = async (message: DiscordenoMessage) => {
|
||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
fields: embedFields,
|
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) {
|
} catch (e) {
|
||||||
utils.commonLoggers.messageSendError('auditDB.ts:45', message, e);
|
utils.commonLoggers.messageSendError('auditDB.ts:45', message, e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
};
|
|
@ -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(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 {
|
try {
|
||||||
const m = await message.send(compilingStats);
|
const m = await message.send(compilingStats);
|
||||||
|
@ -28,7 +28,7 @@ export const stats = async (message: DiscordenoMessage) => {
|
||||||
const cachedChannels = await cacheHandlers.size('channels');
|
const cachedChannels = await cacheHandlers.size('channels');
|
||||||
const cachedMembers = await cacheHandlers.size('members');
|
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) =>
|
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) {
|
} catch (e) {
|
||||||
utils.commonLoggers.messageSendError('stats.ts:41', message, e);
|
utils.commonLoggers.messageSendError('stats.ts:41', message, e);
|
||||||
|
|
|
@ -190,7 +190,7 @@ export const queueRoll = async (rq: QueuedRoll) => {
|
||||||
|
|
||||||
The results for this roll will replace this message when it is done.`,
|
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);
|
rollQueue.push(rq);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -201,7 +201,7 @@ setInterval(async () => {
|
||||||
if (rollQueue.length && currentWorkers < config.limits.maxWorkers) {
|
if (rollQueue.length && currentWorkers < config.limits.maxWorkers) {
|
||||||
const temp = rollQueue.shift();
|
const temp = rollQueue.shift();
|
||||||
if (temp) {
|
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);
|
handleRollWorker(temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue