mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Command Leaderboard
This commit is contained in:
@@ -224,13 +224,14 @@ in the appropriate channel's topic to use it.
|
||||
|
||||
## Commands
|
||||
|
||||
Total: 438
|
||||
Total: 441
|
||||
|
||||
### Utility:
|
||||
|
||||
* **eval:** Executes JavaScript code. (Owner-Only)
|
||||
* **changelog:** Responds with the bot's latest 10 commits.
|
||||
* **cloc:** Responds with the bot's code line count.
|
||||
* **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.
|
||||
* **help:** Displays a list of available commands, or detailed information for a specific command.
|
||||
|
||||
@@ -115,6 +115,11 @@ client.on('error', err => client.logger.error(err.stack));
|
||||
|
||||
client.on('warn', warn => client.logger.warn(warn));
|
||||
|
||||
client.on('commandRun', command => {
|
||||
if (command.uses === undefined) return;
|
||||
command.uses++;
|
||||
});
|
||||
|
||||
client.on('commandError', (command, err) => client.logger.error(`[COMMAND:${command.name}]\n${err.stack}`));
|
||||
|
||||
client.login(XIAO_TOKEN);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
@@ -6,6 +6,7 @@ module.exports = class XiaoCommand extends Command {
|
||||
|
||||
this.argsSingleQuotes = info.argsSingleQuotes || false;
|
||||
this.throttling = info.throttling || { usages: 1, duration: 2 };
|
||||
this.uses = 0;
|
||||
this.credit = info.credit || [];
|
||||
this.credit.push({
|
||||
name: 'Dragon Fire',
|
||||
|
||||
Reference in New Issue
Block a user