fix command usage statistics

This commit is contained in:
Erik 2022-07-30 17:59:48 +03:00
parent e3fbbd9a17
commit 2202de48ea
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB

View File

@ -104,16 +104,29 @@ class StatsCommand extends SlashCommand {
};
//Command statistics - probably expand this further
const { commands } = this.client.registry;
const commandValues = {
invokes: commands.reduce((acc, cmd) => acc + cmd._invokes.success + cmd._invokes.fail, 0),
success: commands.reduce((acc, cmd) => acc + cmd._invokes.success, 0),
fail: commands.reduce((acc, cmd) => acc + cmd._invokes.fail, 0),
successExecTime: Math.round(commands.reduce((acc, cmd) => acc + cmd._invokes.successTime, 0) / commands.size),
failExecTime: Math.round(commands.reduce((acc, cmd) => acc + cmd._invokes.failTime, 0) / commands.size),
const commandsEval = (client) => {
const { commands } = client.registry;
const values = {
invokes: commands.reduce((acc, cmd) => acc + cmd._invokes.success + cmd._invokes.fail, 0),
success: commands.reduce((acc, cmd) => acc + cmd._invokes.success, 0),
fail: commands.reduce((acc, cmd) => acc + cmd._invokes.fail, 0),
successExecTime: Math.round(commands.reduce((acc, cmd) => acc + cmd._invokes.successTime, 0) / commands.size),
failExecTime: Math.round(commands.reduce((acc, cmd) => acc + cmd._invokes.failTime, 0) / commands.size),
};
values.avgTime = Math.round((values.successExecTime + values.failExecTime) / 2);
return values;
};
commandValues.avgTime = Math.round((commandValues.successExecTime + commandValues.failExecTime) / 2);
const commandValues = {};
const commandResult = await shard.broadcastEval(commandsEval).catch((error) => this.client.logger.error(error.stack || error));
// commandValues.avgTime = Math.round((commandValues.successExecTime + commandValues.failExecTime) / 2);
for (const result of commandResult) {
for (const key of Object.keys(result)) {
if(!commandValues[key]) commandValues[key] = 0;
commandValues[key] += result[key];
}
}
commandValues.avgTime /= commandResult.length;
const embed = {
title: invoker.format('COMMAND_STATS_TITLE', {