Added calculating stats message to stats command

This commit is contained in:
Ean Milligan (Bastion) 2022-05-05 23:08:30 -04:00
parent d422db9cc0
commit 06df068ac2
2 changed files with 26 additions and 15 deletions

View File

@ -6,7 +6,7 @@ import {
// Log4Deno deps // Log4Deno deps
LT, log LT, log
} from "../../deps.ts"; } from "../../deps.ts";
import { generateStats } from "../constantCmds.ts"; import { constantCmds, generateStats } from "../constantCmds.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
@ -14,6 +14,9 @@ export const stats = async (message: DiscordenoMessage) => {
log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`); log(LT.ERROR, `Failed to call stored procedure INC_CNT: ${JSON.stringify(e)}`);
}); });
try {
const m = await message.send(constantCmds.loadingStats);
// Calculate how many times commands have been run // Calculate how many times commands have been run
const rollQuery = await dbClient.query(`SELECT count FROM command_cnt WHERE command = "roll";`).catch(e => { const rollQuery = await dbClient.query(`SELECT count FROM command_cnt WHERE command = "roll";`).catch(e => {
log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e)}`); log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e)}`);
@ -27,7 +30,10 @@ export const stats = async (message: DiscordenoMessage) => {
const cachedGuilds = await cacheHandlers.size("guilds"); const cachedGuilds = await cacheHandlers.size("guilds");
const cachedChannels = await cacheHandlers.size("channels"); const cachedChannels = await cacheHandlers.size("channels");
const cachedMembers = await cacheHandlers.size("members"); const cachedMembers = await cacheHandlers.size("members");
message.send(generateStats(cachedGuilds + cache.dispatchedGuildIds.size, cachedChannels + cache.dispatchedChannelIds.size, cachedMembers, rolls, total - rolls)).catch(e => { m.edit(generateStats(cachedGuilds + cache.dispatchedGuildIds.size, cachedChannels + cache.dispatchedChannelIds.size, cachedMembers, rolls, total - rolls)).catch(e => {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`); log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
}); });
} catch (e) {
log(LT.ERROR, `Failed to send message: ${JSON.stringify(message)} | ${JSON.stringify(e)}`);
}
}; };

View File

@ -146,6 +146,11 @@ export const constantCmds = {
}] }]
}] }]
}, },
loadingStats: {
embeds: [{
title: "Compiling latest statistics . . ."
}]
},
privacy: { privacy: {
embeds: [{ embeds: [{
title: "Privacy Policy", title: "Privacy Policy",