From b83ee14cbab4e55290bf7cba53e413f92de8d2b6 Mon Sep 17 00:00:00 2001 From: MatteZ02 <47610069+MatteZ02@users.noreply.github.com> Date: Mon, 25 Nov 2019 20:48:56 +0200 Subject: [PATCH] cmduses --- commands/cmduses.js | 28 ++++++++++++++++++++++++++++ funcs/exe.js | 1 + index.js | 1 + 3 files changed, 30 insertions(+) create mode 100644 commands/cmduses.js diff --git a/commands/cmduses.js b/commands/cmduses.js new file mode 100644 index 00000000..93281b91 --- /dev/null +++ b/commands/cmduses.js @@ -0,0 +1,28 @@ +module.exports = { + name: 'cmduses', + usage: '', + description: 'Command usage statistics', + uses: 0, + async execute(msg, args, client, Discord) { + const cmduses = []; + client.commands.forEach((value, key) => { + cmduses.push([key, value.uses]); + }); + cmduses.sort((a, b) => { + return b[1] - a[1]; + }); + const cmdnamelength = Math.max(...cmduses.map(x => x[0].length)) + 4; + const numberlength = Math.max(...cmduses.map(x => x[1].toString().length), 4); + const markdownrows = ['Command' + ' '.repeat(cmdnamelength - 'command'.length) + ' '.repeat(numberlength - 'uses'.length) + 'Uses']; + cmduses.forEach(x => { + if (x[1] > 0) markdownrows.push(x[0] + '.'.repeat(cmdnamelength - x[0].length) + ' '.repeat(numberlength - x[1].toString().length) + x[1].toString()); + }); + const embed = new Discord.RichEmbed(); + embed + .setTitle('Musix Command Usage During Current Uptime') + .setDescription('```ml\n' + markdownrows.join('\n') + '\n```') + .setFooter('These statistics are from the current uptime.') + .setColor('#b50002'); + msg.channel.send(embed); + }, +}; \ No newline at end of file diff --git a/funcs/exe.js b/funcs/exe.js index 3d1c9382..b8849e60 100644 --- a/funcs/exe.js +++ b/funcs/exe.js @@ -2,6 +2,7 @@ module.exports = function (message, args, client, Discord, prefix, command) { const permissions = message.channel.permissionsFor(message.client.user); if (!permissions.has('EMBED_LINKS')) return message.channel.send(':x: I cannot send embeds (Embed links), make sure I have the proper permissions!'); try { + command.uses++; command.execute(message, args, client, Discord, prefix); } catch (error) { message.reply(`:x: there was an error trying to execute that command! Please contact support with \`${prefix}bug\`!`); diff --git a/index.js b/index.js index 330a4268..e79acda2 100644 --- a/index.js +++ b/index.js @@ -41,6 +41,7 @@ client.config = require('./config/config.js'); const commandFiles = fs.readdirSync('./commands/').filter(f => f.endsWith('.js')); for (const file of commandFiles) { const command = require(`./commands/${file}`); + command.uses = 0; client.commands.set(command.name, command); client.commandAliases.set(command.alias, command); }