From 6139fccfb5ec13f9a325cd2fb9b3710c97e7a90c Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Tue, 2 Jul 2024 01:16:09 -0400 Subject: [PATCH] Add total uses stat --- commands/util-public/command-leaderboard.js | 2 ++ commands/util-public/info.js | 2 +- commands/util-public/uses.js | 7 ++++++- framework/Registry.js | 9 +++++++++ package.json | 2 +- structures/Activity.js | 4 ++++ 6 files changed, 23 insertions(+), 3 deletions(-) diff --git a/commands/util-public/command-leaderboard.js b/commands/util-public/command-leaderboard.js index 4968ae7b..17373b38 100644 --- a/commands/util-public/command-leaderboard.js +++ b/commands/util-public/command-leaderboard.js @@ -32,6 +32,8 @@ module.exports = class CommandLeaderboardCommand extends Command { return msg.say(stripIndents` __**Command Usage Leaderboard (Page ${page}/${totalPages}):**__ ${this.makeLeaderboard(commands, page).join('\n')} + + _Total Uses: ${formatNumber(this.client.registry.totalUses)}_ `); } diff --git a/commands/util-public/info.js b/commands/util-public/info.js index e3d374d2..cf3ac271 100644 --- a/commands/util-public/info.js +++ b/commands/util-public/info.js @@ -27,7 +27,7 @@ module.exports = class InfoCommand extends Command { .setFooter({ text: copyright.join('\n') }) .addField('❯ Servers', formatNumber(this.client.guilds.cache.size), true) .addField('❯ Commands', formatNumber(this.client.registry.commands.size), true) - .addField('❯ Shards', formatNumber(this.client.options.shardCount), true) + .addField('❯ Total Usage', formatNumber(this.client.registry.totalUses), true) .addField('❯ Home Server', this.client.options.invite ? embedURL('Invite', this.client.options.invite) : 'None', true) .addField('❯ Invite', embedURL('Add Me', invite), true) diff --git a/commands/util-public/uses.js b/commands/util-public/uses.js index 585ed396..63c3c9ce 100644 --- a/commands/util-public/uses.js +++ b/commands/util-public/uses.js @@ -12,13 +12,18 @@ module.exports = class UsesCommand extends Command { args: [ { key: 'command', - type: 'command' + type: 'command', + default: '' } ] }); } run(msg, { command }) { + if (!command) { + const uses = formatNumber(this.client.registry.totalUses); + return msg.say(`All commands have been used a total of **${uses}** times.`); + } if (command.unknown || command.uses === undefined) { return msg.reply('That command\'s usage stats aren\'t being tracked.'); } diff --git a/framework/Registry.js b/framework/Registry.js index 3b2bf29a..efee81a8 100644 --- a/framework/Registry.js +++ b/framework/Registry.js @@ -78,4 +78,13 @@ module.exports = class Registry { registerDefaultTypes() { return this.registerTypesIn(path.join(__dirname, 'types')); } + + get totalUses() { + let uses = 0; + for (const command of this.commands.values()) { + if (command.ownerOnly || command.unknown || command.uses === undefined) continue; + uses += command.uses; + } + return uses; + } }; diff --git a/package.json b/package.json index 7b107d03..ab2a139c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "152.0.2", + "version": "152.1.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { diff --git a/structures/Activity.js b/structures/Activity.js index d23e9d97..55ad75e1 100644 --- a/structures/Activity.js +++ b/structures/Activity.js @@ -65,5 +65,9 @@ module.exports = [ { text: client => `with ${formatNumber(client.registry.commands.size)} commands`, type: ActivityType.Playing + }, + { + text: client => `with ${formatNumber(client.registry.totalUses)} command uses`, + type: ActivityType.Playing } ];