From 9dc16a293b25e503ab70e7a28067d7e2a544fe56 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Tue, 10 May 2022 22:01:31 +0300 Subject: [PATCH] filter out managed roles for settings that assign --- .../components/settings/moderation/Grantable.js | 2 +- src/structure/components/settings/moderation/Mute.js | 12 ++++++++---- .../components/settings/utility/Autorole.js | 2 +- .../components/settings/utility/StickyRole.js | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/structure/components/settings/moderation/Grantable.js b/src/structure/components/settings/moderation/Grantable.js index 609a57c..5cb29d3 100644 --- a/src/structure/components/settings/moderation/Grantable.js +++ b/src/structure/components/settings/moderation/Grantable.js @@ -56,7 +56,7 @@ class Grantable extends Setting { const resolved = await guild.resolveRoles(params); if (!resolved.length) return { error: true, index: 'RESOLVE_FAIL', params: { type: 'roles' } }; - this[roles.value](setting.roles, resolved.map((r) => r.id)); + this[roles.value](setting.roles, resolved.filter((r) => !r.managed).map((r) => r.id)); } diff --git a/src/structure/components/settings/moderation/Mute.js b/src/structure/components/settings/moderation/Mute.js index bbf035f..5695622 100644 --- a/src/structure/components/settings/moderation/Mute.js +++ b/src/structure/components/settings/moderation/Mute.js @@ -136,6 +136,10 @@ class MuteSetting extends Setting { response.embeds = [embed]; updated.push('role'); + } else if (opt.name === 'role') { + if(opt.value.managed) return { error: true, index: 'SETTING_MUTE_ROLE_MANAGED' }; + setting.role = opt.value.id; + updated.push(opt.name); } else { setting[opt.name] = opt.value; updated.push(opt.name); @@ -193,7 +197,7 @@ class MuteSetting extends Setting { if (existing) { const prompt = await interaction.promptInteraction({ - content: interaction.format('SETTING_MUTE_ROLEPROMPT', { + content: interaction.format(`SETTING_MUTE_ROLEPROMPT${existing.managed ? '_MANAGED' : ''}`, { name: existing.name, id: existing.id }), @@ -224,12 +228,12 @@ class MuteSetting extends Setting { error: true }; - await prompt.update({ content: `${Emojis.working} Working...`, components: [] }); const boolean = this.client.resolver.resolveBoolean(prompt.customId); + await prompt.update({ content: `${Emojis.working} Working...`, components: [] }); - if (boolean) { + if (boolean && !existing.managed) { role = existing; - } + } else return { index: 'SETTING_MUTE_ABORT', error: true }; } else interaction.editReply({ content: 'Working...', emoji: 'working' }); if (!role) { diff --git a/src/structure/components/settings/utility/Autorole.js b/src/structure/components/settings/utility/Autorole.js index afb6c99..efca1af 100644 --- a/src/structure/components/settings/utility/Autorole.js +++ b/src/structure/components/settings/utility/Autorole.js @@ -57,7 +57,7 @@ class Autorole extends Setting { if (content.error) return content; const words = Util.parseQuotes(content).map(([word]) => word); - const params = (await guild.resolveRoles(words)).map((role) => role.id); + const params = (await guild.resolveRoles(words)).filter((r) => !r.managed).map((role) => role.id); if (!params.length) return { error: true, index: 'RESOLVE_FAIL', params: { type: 'roles' } }; this[method](setting.roles, params); diff --git a/src/structure/components/settings/utility/StickyRole.js b/src/structure/components/settings/utility/StickyRole.js index b650dad..2235316 100644 --- a/src/structure/components/settings/utility/StickyRole.js +++ b/src/structure/components/settings/utility/StickyRole.js @@ -58,7 +58,7 @@ class Autorole extends Setting { if (content.error) return content; const words = Util.parseQuotes(content).map(([word]) => word); - const params = (await guild.resolveRoles(words)).map((role) => role.id); + const params = (await guild.resolveRoles(words)).filter((r) => !r.managed).map((role) => role.id); if (!params.length) return { error: true, index: 'RESOLVE_FAIL', params: { type: 'roles' } }; this[method](setting.roles, params);