From 50a729bc6f378d8b40a71ff339a7b6e7952d61da Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Mon, 3 May 2021 17:14:18 -0400 Subject: [PATCH] Don't track unknown command AT ALL --- Xiao.js | 1 + commands/util-public/group-leaderboard.js | 5 ++++- commands/util-public/last-run.js | 4 +++- commands/util-public/uses.js | 4 +++- structures/Client.js | 2 ++ 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Xiao.js b/Xiao.js index b56d7303..6b9a10a4 100644 --- a/Xiao.js +++ b/Xiao.js @@ -357,6 +357,7 @@ client.on('error', err => client.logger.error(err.stack)); client.on('warn', warn => client.logger.warn(warn)); client.on('commandRun', async command => { + if (command.unknown) return; client.logger.info(`[COMMAND] ${command.name} was used.`); if (command.uses === undefined) return; command.uses++; diff --git a/commands/util-public/group-leaderboard.js b/commands/util-public/group-leaderboard.js index f6cbb032..986985df 100644 --- a/commands/util-public/group-leaderboard.js +++ b/commands/util-public/group-leaderboard.js @@ -25,7 +25,10 @@ module.exports = class GroupLeaderboardCommand extends Command { run(msg, { page }) { const groups = this.client.registry.groups.map(group => { - const uses = group.commands.reduce((a, b) => a + (b.uses || 0), 0); + const uses = group.commands.reduce((a, b) => { + if (b.unknown || !b.uses) return a; + return a + b.uses; + }, 0); return { uses, group }; }); const totalPages = Math.ceil(this.client.registry.groups.size / 10); diff --git a/commands/util-public/last-run.js b/commands/util-public/last-run.js index 20f0481c..3ba7ef8b 100644 --- a/commands/util-public/last-run.js +++ b/commands/util-public/last-run.js @@ -21,7 +21,9 @@ module.exports = class LastRunCommand extends Command { } run(msg, { command }) { - if (command.lastRun === undefined) return msg.reply('That command\'s usage stats aren\'t being tracked.'); + if (command.unknown || command.lastRun === undefined) { + return msg.reply('That command\'s usage stats aren\'t being tracked.'); + } if (!command.lastRun) return msg.reply(`The \`${command.name}\` command has never been run.`); const displayTime = moment.utc(command.lastRun).format('MM/DD/YYYY h:mm A'); return msg.say(`The \`${command.name}\` command was last run on **${displayTime}**.`); diff --git a/commands/util-public/uses.js b/commands/util-public/uses.js index 4d67146b..4f5f2516 100644 --- a/commands/util-public/uses.js +++ b/commands/util-public/uses.js @@ -21,7 +21,9 @@ module.exports = class UsesCommand extends Command { } run(msg, { command }) { - if (command.uses === undefined) return msg.reply('That command\'s usage stats aren\'t being tracked.'); + if (command.unknown || command.uses === undefined) { + return msg.reply('That command\'s usage stats aren\'t being tracked.'); + } return msg.say(`The \`${command.name}\` command has been used **${formatNumber(command.uses)}** times.`); } }; diff --git a/structures/Client.js b/structures/Client.js index 8ce5643c..820d07d2 100644 --- a/structures/Client.js +++ b/structures/Client.js @@ -213,6 +213,7 @@ module.exports = class XiaoClient extends CommandoClient { exportCommandLeaderboard() { let text = '{'; for (const command of this.registry.commands.values()) { + if (command.unknown) continue; if (command.uses === undefined) continue; text += `\n "${command.name}": ${command.uses},`; } @@ -245,6 +246,7 @@ module.exports = class XiaoClient extends CommandoClient { exportLastRun() { let text = '{'; for (const command of this.registry.commands.values()) { + if (command.unknown) continue; if (command.lastRun === undefined) continue; text += `\n "${command.name}": ${command.lastRun ? `"${command.lastRun.toISOString()}"` : null},`; }