From 208652d2707d8d099ee4ddb8a7f532a1c80501c4 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Sun, 28 May 2017 02:30:06 +0000 Subject: [PATCH] Custom hasPermission --- commands/moderation/ban.js | 5 ++++- commands/moderation/kick.js | 5 ++++- commands/moderation/lockdown.js | 5 ++++- commands/moderation/prune.js | 5 ++++- commands/moderation/softban.js | 5 ++++- commands/moderation/unban.js | 5 ++++- commands/moderation/warn.js | 5 ++++- commands/settings/clear-setting.js | 3 ++- commands/settings/invite-guard.js | 3 ++- commands/settings/join-role.js | 3 ++- commands/settings/member-channel.js | 3 ++- commands/settings/member-message.js | 3 ++- commands/settings/mod-channel.js | 3 ++- commands/settings/single-role.js | 3 ++- commands/settings/staff-role.js | 3 ++- commands/settings/starboard.js | 3 ++- package.json | 2 +- 17 files changed, 47 insertions(+), 17 deletions(-) diff --git a/commands/moderation/ban.js b/commands/moderation/ban.js index be252d64..a066b8e6 100644 --- a/commands/moderation/ban.js +++ b/commands/moderation/ban.js @@ -31,7 +31,10 @@ module.exports = class BanCommand extends Command { } hasPermission(msg) { - return msg.member.hasPermission('BAN_MEMBERS') || msg.member.roles.has(msg.guild.settings.get('staffRole')); + const staffRole = msg.guild.roles.get(msg.guild.settings.get('staffRole')); + if (staffRole && !msg.member.roles.has(staffRole)) return `You do not have the ${staffRole.name} role.`; + else if (!msg.member.hasPermission('BAN_MEMBERS')) return 'You do not have the `Ban Members` Permission.'; + else return true; } async run(msg, args) { diff --git a/commands/moderation/kick.js b/commands/moderation/kick.js index eb3ff2a1..a2c5ab42 100644 --- a/commands/moderation/kick.js +++ b/commands/moderation/kick.js @@ -30,7 +30,10 @@ module.exports = class KickCommand extends Command { } hasPermission(msg) { - return msg.member.hasPermission('KICK_MEMBERS') || msg.member.roles.has(msg.guild.settings.get('staffRole')); + const staffRole = msg.guild.roles.get(msg.guild.settings.get('staffRole')); + if (staffRole && !msg.member.roles.has(staffRole)) return `You do not have the ${staffRole.name} role.`; + else if (!msg.member.hasPermission('KICK_MEMBERS')) return 'You do not have the `Kick Members` Permission.'; + else return true; } async run(msg, args) { diff --git a/commands/moderation/lockdown.js b/commands/moderation/lockdown.js index 61267382..1fc5d240 100644 --- a/commands/moderation/lockdown.js +++ b/commands/moderation/lockdown.js @@ -26,7 +26,10 @@ module.exports = class LockdownCommand extends Command { } hasPermission(msg) { - return msg.member.hasPermission('ADMINISTRATOR') || msg.member.roles.has(msg.guild.settings.get('staffRole')); + const staffRole = msg.guild.roles.get(msg.guild.settings.get('staffRole')); + if (staffRole && !msg.member.roles.has(staffRole)) return `You do not have the ${staffRole.name} role.`; + else if (!msg.member.hasPermission('ADMINISTRATOR')) return 'You do not have the `Administrator` Permission.'; + else return true; } async run(msg, args) { diff --git a/commands/moderation/prune.js b/commands/moderation/prune.js index 4ee48954..531e3130 100644 --- a/commands/moderation/prune.js +++ b/commands/moderation/prune.js @@ -28,7 +28,10 @@ module.exports = class PruneCommand extends Command { } hasPermission(msg) { - return msg.member.hasPermission('MANAGE_MESSAGES') || msg.member.roles.has(msg.guild.settings.get('staffRole')); + const staffRole = msg.guild.roles.get(msg.guild.settings.get('staffRole')); + if (staffRole && !msg.member.roles.has(staffRole)) return `You do not have the ${staffRole.name} role.`; + else if (!msg.member.hasPermission('MANAGE_MESSAGES')) return 'You do not have the `Manage Messages` Permission.'; + else return true; } async run(msg, args) { diff --git a/commands/moderation/softban.js b/commands/moderation/softban.js index d88f6f7d..22bb5d7a 100644 --- a/commands/moderation/softban.js +++ b/commands/moderation/softban.js @@ -31,7 +31,10 @@ module.exports = class SoftbanCommand extends Command { } hasPermission(msg) { - return msg.member.hasPermission('KICK_MEMBERS') || msg.member.roles.has(msg.guild.settings.get('staffRole')); + const staffRole = msg.guild.roles.get(msg.guild.settings.get('staffRole')); + if (staffRole && !msg.member.roles.has(staffRole)) return `You do not have the ${staffRole.name} role.`; + else if (!msg.member.hasPermission('KICK_MEMBERS')) return 'You do not have the `Kick Members` Permission.'; + else return true; } async run(msg, args) { diff --git a/commands/moderation/unban.js b/commands/moderation/unban.js index 5abe1e33..ea32e100 100644 --- a/commands/moderation/unban.js +++ b/commands/moderation/unban.js @@ -31,7 +31,10 @@ module.exports = class UnbanCommand extends Command { } hasPermission(msg) { - return msg.member.hasPermission('BAN_MEMBERS') || msg.member.roles.has(msg.guild.settings.get('staffRole')); + const staffRole = msg.guild.roles.get(msg.guild.settings.get('staffRole')); + if (staffRole && !msg.member.roles.has(staffRole)) return `You do not have the ${staffRole.name} role.`; + else if (!msg.member.hasPermission('BAN_MEMBERS')) return 'You do not have the `Ban Members` Permission.'; + else return true; } async run(msg, args) { diff --git a/commands/moderation/warn.js b/commands/moderation/warn.js index ce96644b..a2a6df75 100644 --- a/commands/moderation/warn.js +++ b/commands/moderation/warn.js @@ -30,7 +30,10 @@ module.exports = class WarnCommand extends Command { } hasPermission(msg) { - return msg.member.hasPermission('KICK_MEMBERS') || msg.member.roles.has(msg.guild.settings.get('staffRole')); + const staffRole = msg.guild.roles.get(msg.guild.settings.get('staffRole')); + if (staffRole && !msg.member.roles.has(staffRole)) return `You do not have the ${staffRole.name} role.`; + else if (!msg.member.hasPermission('KICK_MEMBERS')) return 'You do not have the `Kick Members` Permission.'; + else return true; } async run(msg, args) { diff --git a/commands/settings/clear-setting.js b/commands/settings/clear-setting.js index 8776e5ec..3d62d6b4 100644 --- a/commands/settings/clear-setting.js +++ b/commands/settings/clear-setting.js @@ -24,7 +24,8 @@ module.exports = class ClearSettingCommand extends Command { } hasPermission(msg) { - return msg.member.hasPermission('ADMINISTRATOR'); + if (!msg.member.hasPermission('ADMINISTRATOR')) return 'You do not have the `Administrator` Permission.'; + else return true; } run(msg, args) { diff --git a/commands/settings/invite-guard.js b/commands/settings/invite-guard.js index 0ffeb078..556e95ed 100644 --- a/commands/settings/invite-guard.js +++ b/commands/settings/invite-guard.js @@ -12,7 +12,8 @@ module.exports = class InviteGuardCommand extends Command { } hasPermission(msg) { - return msg.member.hasPermission('ADMINISTRATOR'); + if (!msg.member.hasPermission('ADMINISTRATOR')) return 'You do not have the `Administrator` Permission.'; + else return true; } run(msg) { diff --git a/commands/settings/join-role.js b/commands/settings/join-role.js index 56eef6bd..1e390203 100644 --- a/commands/settings/join-role.js +++ b/commands/settings/join-role.js @@ -19,7 +19,8 @@ module.exports = class JoinRoleCommand extends Command { } hasPermission(msg) { - return msg.member.hasPermission('ADMINISTRATOR'); + if (!msg.member.hasPermission('ADMINISTRATOR')) return 'You do not have the `Administrator` Permission.'; + else return true; } run(msg, args) { diff --git a/commands/settings/member-channel.js b/commands/settings/member-channel.js index e456dd7a..71164aa1 100644 --- a/commands/settings/member-channel.js +++ b/commands/settings/member-channel.js @@ -19,7 +19,8 @@ module.exports = class MemberLogCommand extends Command { } hasPermission(msg) { - return msg.member.hasPermission('ADMINISTRATOR'); + if (!msg.member.hasPermission('ADMINISTRATOR')) return 'You do not have the `Administrator` Permission.'; + else return true; } run(msg, args) { diff --git a/commands/settings/member-message.js b/commands/settings/member-message.js index 4e4b071e..17f0b6b7 100644 --- a/commands/settings/member-message.js +++ b/commands/settings/member-message.js @@ -34,7 +34,8 @@ module.exports = class MemberMsgCommand extends Command { } hasPermission(msg) { - return msg.member.hasPermission('ADMINISTRATOR'); + if (!msg.member.hasPermission('ADMINISTRATOR')) return 'You do not have the `Administrator` Permission.'; + else return true; } run(msg, args) { diff --git a/commands/settings/mod-channel.js b/commands/settings/mod-channel.js index 67941ad5..ccfbf5c3 100644 --- a/commands/settings/mod-channel.js +++ b/commands/settings/mod-channel.js @@ -19,7 +19,8 @@ module.exports = class ModChannelCommand extends Command { } hasPermission(msg) { - return msg.member.hasPermission('ADMINISTRATOR'); + if (!msg.member.hasPermission('ADMINISTRATOR')) return 'You do not have the `Administrator` Permission.'; + else return true; } run(msg, args) { diff --git a/commands/settings/single-role.js b/commands/settings/single-role.js index 8bd2a369..0d7e1d11 100644 --- a/commands/settings/single-role.js +++ b/commands/settings/single-role.js @@ -19,7 +19,8 @@ module.exports = class SingleRoleCommand extends Command { } hasPermission(msg) { - return msg.member.hasPermission('ADMINISTRATOR'); + if (!msg.member.hasPermission('ADMINISTRATOR')) return 'You do not have the `Administrator` Permission.'; + else return true; } run(msg, args) { diff --git a/commands/settings/staff-role.js b/commands/settings/staff-role.js index 0b268bff..6cddab14 100644 --- a/commands/settings/staff-role.js +++ b/commands/settings/staff-role.js @@ -19,7 +19,8 @@ module.exports = class StaffRoleCommand extends Command { } hasPermission(msg) { - return msg.member.hasPermission('ADMINISTRATOR'); + if (!msg.member.hasPermission('ADMINISTRATOR')) return 'You do not have the `Administrator` Permission.'; + else return true; } run(msg, args) { diff --git a/commands/settings/starboard.js b/commands/settings/starboard.js index 93995104..e686ccf1 100644 --- a/commands/settings/starboard.js +++ b/commands/settings/starboard.js @@ -19,7 +19,8 @@ module.exports = class StarboardCommand extends Command { } hasPermission(msg) { - return msg.member.hasPermission('ADMINISTRATOR'); + if (!msg.member.hasPermission('ADMINISTRATOR')) return 'You do not have the `Administrator` Permission.'; + else return true; } run(msg, args) { diff --git a/package.json b/package.json index fb140440..4595be75 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "21.4.0", + "version": "21.4.1", "description": "A Discord Bot", "main": "Shard.js", "scripts": {