From e04587ffca35db47012b825c2c7327512e8d9318 Mon Sep 17 00:00:00 2001 From: Keanu Date: Wed, 1 Jul 2020 15:35:37 +0200 Subject: [PATCH] Finished help command. Also categorized all commands. --- config.json.example | 5 ++-- .../{Utilities => Information}/Botinfo.js | 3 ++- .../{Utilities => Information}/Serverinfo.js | 3 ++- .../{Utilities => Information}/Userinfo.js | 3 ++- src/Commands/Utilities/Help.js | 25 +++++++++++++++++-- src/Commands/Utilities/Ping.js | 3 ++- src/Commands/Utilities/Uptime.js | 7 ++++++ src/Structures/BotClient.js | 2 ++ src/Structures/Command.js | 2 +- 9 files changed, 44 insertions(+), 9 deletions(-) rename src/Commands/{Utilities => Information}/Botinfo.js (96%) rename src/Commands/{Utilities => Information}/Serverinfo.js (97%) rename src/Commands/{Utilities => Information}/Userinfo.js (97%) diff --git a/config.json.example b/config.json.example index cc51b4a..968e009 100644 --- a/config.json.example +++ b/config.json.example @@ -1,4 +1,5 @@ { - "prefix": "!!", - "token": "" + "prefix": "!!", // Bot Prefix + "token": "", // Bot Token + "owners": [""] // Array of bot owner IDs } \ No newline at end of file diff --git a/src/Commands/Utilities/Botinfo.js b/src/Commands/Information/Botinfo.js similarity index 96% rename from src/Commands/Utilities/Botinfo.js rename to src/Commands/Information/Botinfo.js index 22cb43b..5d35c75 100644 --- a/src/Commands/Utilities/Botinfo.js +++ b/src/Commands/Information/Botinfo.js @@ -9,7 +9,8 @@ module.exports = class extends Command { constructor(...args) { super(...args, { - aliases: ['info', 'bot', 'botinfo'] + aliases: ['info', 'bot', 'botinfo'], + category: 'Information' }); } diff --git a/src/Commands/Utilities/Serverinfo.js b/src/Commands/Information/Serverinfo.js similarity index 97% rename from src/Commands/Utilities/Serverinfo.js rename to src/Commands/Information/Serverinfo.js index 6b580bc..4247e6d 100644 --- a/src/Commands/Utilities/Serverinfo.js +++ b/src/Commands/Information/Serverinfo.js @@ -36,7 +36,8 @@ module.exports = class extends Command { constructor(...args) { super(...args, { - aliases: ['server', 'guild', 'guildinfo'] + aliases: ['server', 'guild', 'guildinfo'], + category: 'Information' }); } diff --git a/src/Commands/Utilities/Userinfo.js b/src/Commands/Information/Userinfo.js similarity index 97% rename from src/Commands/Utilities/Userinfo.js rename to src/Commands/Information/Userinfo.js index ad11fc6..919c183 100644 --- a/src/Commands/Utilities/Userinfo.js +++ b/src/Commands/Information/Userinfo.js @@ -22,7 +22,8 @@ module.exports = class extends Command { constructor(...args) { super(...args, { - aliases: ['user', 'ui'] + aliases: ['user', 'ui'], + category: 'Information' }); } diff --git a/src/Commands/Utilities/Help.js b/src/Commands/Utilities/Help.js index 03c69e8..25dd2e8 100644 --- a/src/Commands/Utilities/Help.js +++ b/src/Commands/Utilities/Help.js @@ -5,7 +5,8 @@ module.exports = class extends Command { constructor(...args) { super(...args, { - aliases: ['help', 'halp'] + aliases: ['help', 'halp'], + category: 'Utilities' }); } @@ -22,13 +23,33 @@ module.exports = class extends Command { if (!cmd) return message.channel.send(`\`${command}\` is not a valid command.`); - embed.setAuthor(`${this.client.utils.captalise(cmd.name)} Command Help`, this.client.user.displayAvatarURL()); + embed.setAuthor(`${this.client.utils.capitalise(cmd.name)} Command Help`, this.client.user.displayAvatarURL()); embed.setDescription([ `**❯ Aliases:** ${cmd.aliases.length ? cmd.aliases.map(alias => `\`${alias}\``).join(' ') : 'No Aliases'}`, `**❯ Description:** ${cmd.description}`, `**❯ Category:** ${cmd.category}`, `**❯ Usage:** ${cmd.usage}` ]); + + return message.channel.send(embed); + } else { + embed.setDescription([ + `These are the available commands for ${message.guild.name}`, + `This bot's prefix is: ${this.client.prefix}`, + `Command Parameters: \`<>\` is a strict & \`[]\` is optional` + ]); + let categories; + if (!this.client.owners.includes(message.author.id)) { + categories = this.client.utils.removeDuplicates(this.client.commands.filter(cmd => cmd.category !== 'Owner').map(cmd => cmd.category)); + } else { + categories = this.client.utils.removeDuplicates(this.client.commands.map(cmd => cmd.category)); + } + + for (const category of categories) { + embed.addField(`**${this.client.utils.capitalise(category)}**`, this.client.commands.filter(cmd => + cmd.category === category).map(cmd => `\`${cmd.name}\``).join(' ')); + } + return message.channel.send(embed); } } diff --git a/src/Commands/Utilities/Ping.js b/src/Commands/Utilities/Ping.js index c73527e..17b75c1 100644 --- a/src/Commands/Utilities/Ping.js +++ b/src/Commands/Utilities/Ping.js @@ -4,7 +4,8 @@ module.exports = class extends Command { constructor(...args) { super(...args, { - aliases: ['pong'] + aliases: ['pong'], + category: 'Utilities' }); } diff --git a/src/Commands/Utilities/Uptime.js b/src/Commands/Utilities/Uptime.js index 0652a5f..b782654 100644 --- a/src/Commands/Utilities/Uptime.js +++ b/src/Commands/Utilities/Uptime.js @@ -3,6 +3,13 @@ const ms = require('ms'); module.exports = class extends Command { + constructor(...args) { + super(...args)({ + aliases: ['uptime'], + category: 'Utilities' + }); + } + async run(message) { message.channel.send(`My uptime is \`${ms(this.client.uptime, { long: true })}\``); } diff --git a/src/Structures/BotClient.js b/src/Structures/BotClient.js index e9a0b7a..4d5568e 100644 --- a/src/Structures/BotClient.js +++ b/src/Structures/BotClient.js @@ -15,6 +15,8 @@ module.exports = class BotClient extends Client { this.utils = new Util(this); + this.owners = options.owners; + this.once('ready', () => { console.log(`Logged in as ${this.user.username}.`); }); diff --git a/src/Structures/Command.js b/src/Structures/Command.js index f9a9399..02fb6f1 100644 --- a/src/Structures/Command.js +++ b/src/Structures/Command.js @@ -6,7 +6,7 @@ module.exports = class Command { this.aliases = options.aliases || []; this.description = options.description || 'No description provided.'; this.category = options.category || 'Miscellaneous'; - this.usage = `${this.client.prefix}${this.name} ${options.usage || ''}`.trim() + this.usage = `${this.client.prefix}${this.name} ${options.usage || ''}`.trim(); } // eslint-disable-next-line no-unused-vars