diff --git a/bot/base/Command.js b/bot/base/Command.js index ad4cb52..11e3a39 100644 --- a/bot/base/Command.js +++ b/bot/base/Command.js @@ -9,11 +9,12 @@ class Command { guildOnly = false, devOnly = false, aliases = new Array(), - permLevel = "User", + userPerms = new Array(), + botPerms = new Array (), cooldown = 2000 }) { this.client = client; - this.conf = { enabled, guildOnly, devOnly, aliases, permLevel, cooldown }; + this.conf = { enabled, guildOnly, devOnly, aliases, userPerms, botPerms, cooldown }; this.help = { name, description, category, usage }; } } diff --git a/bot/events/message.js b/bot/events/message.js index 9f588aa..9446487 100644 --- a/bot/events/message.js +++ b/bot/events/message.js @@ -75,10 +75,32 @@ module.exports = class { if (cmd && cmd.conf.devOnly && this.client.functions.isDeveloper(message.author.id) !== true) { return message.channel.send("devs only!"); - } + }; + if (cmd && !message.guild && cmd.conf.guildOnly === true) { return message.channel.send("This command is unavailable via private message. Please run this command in a guild."); - } + }; + + // Permission handler, for both Woomy and the user + if (message.guild) { + var missingUserPerms = cmd.conf.userPerms.filter(perms => { + !message.channel.permissionsFor(message.author).has(perms) + }); + + if (missingUserPerms.length > 0) { + missingUserPerms = '`' + (missingUserPerms.join('`, `')) + '`' + return message.channel.send(`You don't have sufficient permissions to run this command! Missing: ${missingBotPerms}`); + }; + + var missingBotPerms = cmd.conf.botPerms.filter(perms => { + !message.channel.permissionsFor(this.client.user).has(perms) + }); + + if (missingBotPerms.length > 0) { + missingBotPerms = '`' + (missingBotPerms.join('`, `')) + '`'; + return message.channel.send(`Failed to run this command because I am missing the following permissions: ${missingBotPerms}`); + }; + }; // Cooldown if (this.client.cooldown.get(cmd.help.name).has(message.author.id)) {