From 777059c18b4becfb3fab8e16a25b83b66873be8d Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Wed, 2 Aug 2017 21:23:22 +0000 Subject: [PATCH] Command Uses --- XiaoBot.js | 2 ++ commands/util/command-leaderboard.js | 33 ++++++++++++++++++++++++++++ package.json | 2 +- structures/Command.js | 1 + 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 commands/util/command-leaderboard.js diff --git a/XiaoBot.js b/XiaoBot.js index 2c48082e..7af4e93f 100644 --- a/XiaoBot.js +++ b/XiaoBot.js @@ -60,6 +60,8 @@ client.on('warn', console.warn); client.on('commandError', (command, err) => console.error(command.name, err)); +client.on('commandRun', command => ++command.uses); + client.on('message', async msg => { if (!msg.guild || msg.author.bot) return; const topic = msg.guild.defaultChannel.topic || ''; diff --git a/commands/util/command-leaderboard.js b/commands/util/command-leaderboard.js new file mode 100644 index 00000000..ab98370b --- /dev/null +++ b/commands/util/command-leaderboard.js @@ -0,0 +1,33 @@ +const Command = require('../../structures/Command'); + +module.exports = class CommandLeaderboardCommand extends Command { + constructor(client) { + super(client, { + name: 'command-leaderboard', + aliases: ['cmd-leaderboard', 'cmd-board'], + group: 'util', + memberName: 'command-leaderboard', + description: 'Responds with the most used commands.', + details: '**Note:** This only counts this session for this shard.', + guarded: true, + args: [ + { + key: 'page', + prompt: 'Which page do you want to view?', + type: 'integer', + default: 1 + } + ] + }); + } + + run(msg, args) { + const { page } = args; + let i = 0; + const list = this.client.registry.commands + .sort((a, b) => a.uses - b.uses) + .map(cmd => `**${++i}.** ${cmd.name} (${cmd.uses} Uses)`) + .slice((page - 1) * 10, page * 10); + return msg.say(list.split('\n')); + } +}; diff --git a/package.json b/package.json index 1a894085..9c2cedd7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "28.2.2", + "version": "28.3.0", "description": "Your personal server companion.", "main": "Shard.js", "scripts": { diff --git a/structures/Command.js b/structures/Command.js index ca94076f..353e60b3 100644 --- a/structures/Command.js +++ b/structures/Command.js @@ -13,6 +13,7 @@ class XiaoCommand extends Command { usages: 1, duration: 2 }; + this.uses = 0; } hasPermission(msg) {