diff --git a/README.md b/README.md index d0949575..3dbb0ce0 100644 --- a/README.md +++ b/README.md @@ -262,7 +262,7 @@ in the appropriate channel's topic to use it. ## Commands -Total: 593 +Total: 594 ### Utility: @@ -271,6 +271,7 @@ Total: 593 * **command-leaderboard:** Responds with the bot's most used commands. * **credit:** Responds with a command's credits list. * **donate:** Responds with the bot's donation links. +* **group-leaderboard:** Responds with the bot's most used command groups. * **help:** Displays a list of available commands, or detailed information for a specific command. * **high-scores:** Responds with the high scores the bot has saved. * **info:** Responds with detailed bot information. diff --git a/commands/util-public/group-leaderboard.js b/commands/util-public/group-leaderboard.js new file mode 100644 index 00000000..ee3b53a6 --- /dev/null +++ b/commands/util-public/group-leaderboard.js @@ -0,0 +1,59 @@ +const Command = require('../../structures/Command'); +const { stripIndents } = require('common-tags'); +const { formatNumber } = require('../../util/Util'); + +module.exports = class GroupLeaderboardCommand extends Command { + constructor(client) { + super(client, { + name: 'group-leaderboard', + aliases: ['grp-lb', 'grp-leaderboard', 'group-lb'], + group: 'util-public', + memberName: 'group-leaderboard', + description: 'Responds with the bot\'s most used command groups.', + guarded: true, + args: [ + { + key: 'page', + prompt: 'What page do you want to view?', + type: 'integer', + default: 1, + min: 1 + } + ] + }); + } + + run(msg, { page }) { + const groups = this.client.registry.groups.map(group => { + return { + uses: group.commands.reduce((a, b) => a + (b.uses || 0), 0), + group + }; + }); + const totalPages = Math.ceil(groups.size / 10); + if (page > totalPages) return msg.say(`Page ${page} does not exist (yet).`); + return msg.say(stripIndents` + __**Command Group Usage Leaderboard (Page ${page}/${totalPages}):**__ + ${this.makeLeaderboard(groups, page).join('\n')} + `); + } + + makeLeaderboard(groups, page) { + let i = 0; + let previousPts = null; + let positionsMoved = 1; + return groups + .sort((a, b) => b.uses - a.uses) + .map(groups => { + if (previousPts === groups.uses) { + positionsMoved++; + } else { + i += positionsMoved; + positionsMoved = 1; + } + previousPts = groups.uses; + return `**${i}.** ${group.group.name} (${formatNumber(groups.uses)} Use${groups.uses === 1 ? '' : 's'})`; + }) + .slice((page - 1) * 10, page * 10); + } +}; diff --git a/package.json b/package.json index 49fdfb0b..10e20bd3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "129.0.3", + "version": "129.1.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {