From 6e289fe32659df1a26ac75f923755782ce60c53f Mon Sep 17 00:00:00 2001 From: nolan Date: Mon, 10 May 2021 13:25:35 -0700 Subject: [PATCH] add protection role verification --- .../languages/en_us/en_us_general.lang | 5 ++++- structure/moderation/interfaces/Infraction.js | 19 +++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/structure/language/languages/en_us/en_us_general.lang b/structure/language/languages/en_us/en_us_general.lang index d2581b0..39bbadb 100644 --- a/structure/language/languages/en_us/en_us_general.lang +++ b/structure/language/languages/en_us/en_us_general.lang @@ -265,9 +265,12 @@ You can increase the amount of targets by upgrading to premium. [INFRACTION_ERROR] an error occured -[INFRACTION_PROTECTIONERROR] +[INFRACTION_PROTECTIONPOSITIONERROR] they have hierarchy over you +[INFRACTION_PROTECTIONROLEERROR] +their roles are protected + [INFRACTION_AUTOMODESCALATION] This action was automatically escalated by auto-moderation. diff --git a/structure/moderation/interfaces/Infraction.js b/structure/moderation/interfaces/Infraction.js index 0c92ba7..bd2c0e7 100644 --- a/structure/moderation/interfaces/Infraction.js +++ b/structure/moderation/interfaces/Infraction.js @@ -267,16 +267,23 @@ class Infraction { } async _verify() { + const { protection } = await this.guild.settings(); if (this.executor.id === this.guild.ownerID) return this._succeed(); - if (this.guild && this.guild._settings.protection.enabled && this.targetType === 'USER') { - //Idk what the thought process here has been, but the user object does not have roles, and the executor is a user object + if (this.guild && protection.enabled && this.targetType === 'USER') { const executor = await this.guild.members.fetch(this.executor.id).catch(); const target = await this.guild.members.fetch(this.target.id).catch(); if (!target) return this._succeed(); - const executorHighest = executor.roles.highest; //this.executor.roles.highest; - const targetHighest = target.roles.highest; //this.member.roles.highest; - if (executorHighest.comparePositionTo(targetHighest) < 0) { - return this._fail('INFRACTION_PROTECTIONERROR'); + if(protection.type === 'position') { + const executorHighest = executor.roles.highest; + const targetHighest = target.roles.highest; + if (executorHighest.comparePositionTo(targetHighest) < 0) { + return this._fail('INFRACTION_PROTECTIONPOSITIONERROR'); + } + } else if(protection.type === 'role') { + const contains = target.roles.cache.some((r) => protection.roles.includes(r.id)); + if(contains) { + return this._fail('INFRACTION_PROTECTIONROLEERROR'); + } } } return this._succeed();