Filter hidden and unknown commands out of lb

This commit is contained in:
Dragon Fire
2020-06-15 10:35:14 -04:00
parent 4581e631b7
commit 2d58e3a631
2 changed files with 10 additions and 6 deletions
+9 -5
View File
@@ -23,20 +23,20 @@ module.exports = class CommandLeaderboardCommand extends Command {
} }
run(msg, { page }) { run(msg, { page }) {
const totalPages = Math.ceil(this.client.registry.commands.size / 10); const commands = this.filterCommands(this.client.registry.commands);
const totalPages = Math.ceil(commands.size / 10);
if (page > totalPages) return msg.say(`Page ${page} does not exist (yet).`); if (page > totalPages) return msg.say(`Page ${page} does not exist (yet).`);
return msg.say(stripIndents` return msg.say(stripIndents`
__**Command Usage Leaderboard (Page ${page}/${totalPages}):**__ __**Command Usage Leaderboard (Page ${page}/${totalPages}):**__
${this.makeLeaderboard(page).join('\n')} ${this.makeLeaderboard(commands, page).join('\n')}
`); `);
} }
makeLeaderboard(page) { makeLeaderboard(commands, page) {
let i = 0; let i = 0;
let previousPts = null; let previousPts = null;
let positionsMoved = 1; let positionsMoved = 1;
return this.client.registry.commands return commands
.filter(command => command.uses !== undefined)
.sort((a, b) => b.uses - a.uses) .sort((a, b) => b.uses - a.uses)
.map(command => { .map(command => {
if (previousPts === command.uses) { if (previousPts === command.uses) {
@@ -50,4 +50,8 @@ module.exports = class CommandLeaderboardCommand extends Command {
}) })
.slice((page - 1) * 10, page * 10); .slice((page - 1) * 10, page * 10);
} }
filterCommands(commands) {
return commands.filter(command => command.uses !== undefined && !command.unknown && !command.hidden);
}
}; };
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "xiao", "name": "xiao",
"version": "116.27.2", "version": "116.27.3",
"description": "Your personal server companion.", "description": "Your personal server companion.",
"main": "Xiao.js", "main": "Xiao.js",
"scripts": { "scripts": {