From 5ffce3ff95e8cb24d38642b7b5696e00cd86ada3 Mon Sep 17 00:00:00 2001 From: Emily J Date: Sat, 17 Oct 2020 23:03:50 +1100 Subject: [PATCH] move permission handler into functions --- bot/util/functions.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/bot/util/functions.js b/bot/util/functions.js index 3402303..d91ef08 100644 --- a/bot/util/functions.js +++ b/bot/util/functions.js @@ -74,11 +74,26 @@ class Functions { return role; } - intBetween (min, max) { - return Math.round((Math.random() * (max - min) + min)); + checkPermissions (command, message, member) { + const missingPerms = []; + + if (member.user.bot) { + command.conf.botPerms.forEach(p => { + if (!message.channel.permissionsFor(member).has(p)) missingPerms.push(p); + }); + } else { + command.conf.userPerms.forEach(p => { + if (!message.channel.permissionsFor(member).has(p)) missingPerms.push(p); + }); + } + + if (missingPerms.length > 0) return missingPerms; } + intBetween (min, max) { + return Math.round((Math.random() * (max - min) + min)); + } isDeveloper (id) { if (this.client.config.ownerIDs.includes(id)) {