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,20 +14,26 @@ 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)}`);
}); });
// Calculate how many times commands have been run try {
const rollQuery = await dbClient.query(`SELECT count FROM command_cnt WHERE command = "roll";`).catch(e => { const m = await message.send(constantCmds.loadingStats);
log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e)}`);
});
const totalQuery = await dbClient.query(`SELECT SUM(count) as count FROM command_cnt;`).catch(e => {
log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e)}`);
});
const rolls = BigInt(rollQuery[0].count);
const total = BigInt(totalQuery[0].count);
const cachedGuilds = await cacheHandlers.size("guilds"); // Calculate how many times commands have been run
const cachedChannels = await cacheHandlers.size("channels"); const rollQuery = await dbClient.query(`SELECT count FROM command_cnt WHERE command = "roll";`).catch(e => {
const cachedMembers = await cacheHandlers.size("members"); log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e)}`);
message.send(generateStats(cachedGuilds + cache.dispatchedGuildIds.size, cachedChannels + cache.dispatchedChannelIds.size, cachedMembers, rolls, total - rolls)).catch(e => { });
const totalQuery = await dbClient.query(`SELECT SUM(count) as count FROM command_cnt;`).catch(e => {
log(LT.ERROR, `Failed to query DB: ${JSON.stringify(e)}`);
});
const rolls = BigInt(rollQuery[0].count);
const total = BigInt(totalQuery[0].count);
const cachedGuilds = await cacheHandlers.size("guilds");
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)).catch(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)}`); 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",