From 36555c1cea5d559eb5cfbaebec7866b21cd1a835 Mon Sep 17 00:00:00 2001 From: Isabella Date: Mon, 15 Jan 2018 18:32:40 -0600 Subject: [PATCH] refactor(GuildMember#manageable): refactored kickable and bannable (#2211) * refactor(GuildMember#manageable): merged kickable and bannable code * hydar suggestion --- src/structures/GuildMember.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/structures/GuildMember.js b/src/structures/GuildMember.js index 80c6ce48c..c7384d875 100644 --- a/src/structures/GuildMember.js +++ b/src/structures/GuildMember.js @@ -259,17 +259,24 @@ class GuildMember extends Base { return new Permissions(this.roles.map(role => role.permissions)).freeze(); } + /** + * Whether the member is manageable in terms of role hierarchy by the client user + * @type {boolean} + * @readonly + */ + get manageable() { + if (this.user.id === this.guild.ownerID) return false; + if (this.user.id === this.client.user.id) return false; + return this.guild.me.highestRole.comparePositionTo(this.highestRole) > 0; + } + /** * Whether the member is kickable by the client user * @type {boolean} * @readonly */ get kickable() { - if (this.user.id === this.guild.ownerID) return false; - if (this.user.id === this.client.user.id) return false; - const clientMember = this.guild.member(this.client.user); - if (!clientMember.permissions.has(Permissions.FLAGS.KICK_MEMBERS)) return false; - return clientMember.highestRole.comparePositionTo(this.highestRole) > 0; + return this.manageable && this.guild.me.permissions.has(Permissions.FLAGS.KICK_MEMBERS); } /** @@ -278,11 +285,7 @@ class GuildMember extends Base { * @readonly */ get bannable() { - if (this.user.id === this.guild.ownerID) return false; - if (this.user.id === this.client.user.id) return false; - const clientMember = this.guild.member(this.client.user); - if (!clientMember.permissions.has(Permissions.FLAGS.BAN_MEMBERS)) return false; - return clientMember.highestRole.comparePositionTo(this.highestRole) > 0; + return this.manageable && this.guild.me.permissions.has(Permissions.FLAGS.BAN_MEMBERS); } /**