Add Group Leaderboard

This commit is contained in:
Dragon Fire
2021-02-09 17:45:43 -05:00
parent 0437a66e29
commit f6b9457b23
3 changed files with 62 additions and 2 deletions
+2 -1
View File
@@ -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.
+59
View File
@@ -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);
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "129.0.3",
"version": "129.1.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {