mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 15:07:42 +02:00
Add Group Leaderboard
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "129.0.3",
|
||||
"version": "129.1.0",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user