Command Leaderboard

This commit is contained in:
Dragon Fire
2020-05-23 13:43:13 -04:00
parent 125419c109
commit 72c8d382c5
4 changed files with 59 additions and 1 deletions
+51
View File
@@ -0,0 +1,51 @@
const Command = require('../../structures/Command');
const { stripIndents } = require('common-tags');
module.exports = class CommandLeaderboardCommand extends Command {
constructor(client) {
super(client, {
name: 'command-leaderboard',
aliases: ['cmd-lb', 'cmd-leaderboard', 'command-lb'],
group: 'util',
memberName: 'command-leaderboard',
description: 'Responds with the bot\'s most used commands.',
guarded: true,
args: [
{
key: 'page',
prompt: 'What page do you want to view?',
type: 'integer',
min: 1,
max: () => Math.ceil(this.client.registry.commands.size / 10)
}
]
});
}
run(msg, { page }) {
return msg.say(stripIndents`
__**Command Usage Leaderboard (as of Last Restart):**__
${this.makeLeaderboard(page).join('\n')}
`);
}
makeLeaderboard(page) {
let i = 0;
let previousPts = null;
let positionsMoved = 1;
return this.client.registry.commands
.filter(command => command.uses !== undefined)
.sort((a, b) => b.uses - a.uses)
.map(command => {
if (previousPts === command.uses) {
positionsMoved++;
} else {
i += positionsMoved;
positionsMoved = 1;
}
previousPts = command.uses;
return `**${i}.** ${command.name} (${command.uses} Use${command.uses === 1 ? '' : 's'})`;
})
.slice((page - 1) * 10, page * 10);
}
};