Added calculating stats message to stats command
This commit is contained in:
parent
d422db9cc0
commit
06df068ac2
|
@ -6,7 +6,7 @@ import {
|
|||
// Log4Deno deps
|
||||
LT, log
|
||||
} from "../../deps.ts";
|
||||
import { generateStats } from "../constantCmds.ts";
|
||||
import { constantCmds, generateStats } from "../constantCmds.ts";
|
||||
|
||||
export const stats = async (message: DiscordenoMessage) => {
|
||||
// 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)}`);
|
||||
});
|
||||
|
||||
// Calculate how many times commands have been run
|
||||
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)}`);
|
||||
});
|
||||
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);
|
||||
try {
|
||||
const m = await message.send(constantCmds.loadingStats);
|
||||
|
||||
const cachedGuilds = await cacheHandlers.size("guilds");
|
||||
const cachedChannels = await cacheHandlers.size("channels");
|
||||
const cachedMembers = await cacheHandlers.size("members");
|
||||
message.send(generateStats(cachedGuilds + cache.dispatchedGuildIds.size, cachedChannels + cache.dispatchedChannelIds.size, cachedMembers, rolls, total - rolls)).catch(e => {
|
||||
// Calculate how many times commands have been run
|
||||
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)}`);
|
||||
});
|
||||
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)}`);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -146,6 +146,11 @@ export const constantCmds = {
|
|||
}]
|
||||
}]
|
||||
},
|
||||
loadingStats: {
|
||||
embeds: [{
|
||||
title: "Compiling latest statistics . . ."
|
||||
}]
|
||||
},
|
||||
privacy: {
|
||||
embeds: [{
|
||||
title: "Privacy Policy",
|
||||
|
|
Loading…
Reference in New Issue