From 482a38a80b5ba518354457b97e13bd7696cb04c0 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Sun, 17 Jul 2022 23:56:05 +0300 Subject: [PATCH] bugfixes --- src/localization/en_gb/commands/en_gb_utility.lang | 4 ++++ src/structure/components/commands/utility/Selfrole.js | 10 +++++++--- src/structure/components/settings/utility/Selfrole.js | 6 +++--- src/structure/interfaces/Setting.js | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/localization/en_gb/commands/en_gb_utility.lang b/src/localization/en_gb/commands/en_gb_utility.lang index 6fae370..69d46fa 100644 --- a/src/localization/en_gb/commands/en_gb_utility.lang +++ b/src/localization/en_gb/commands/en_gb_utility.lang @@ -143,4 +143,8 @@ Successfully removed all your selfroles. [COMMAND_SELFROLE_INVALID] {emoji_failure} The following roles are not self-assignable: +**{roles}** + +[COMMAND_SELFROLE_TOOHIGH] +{emoji_failure} The following roles are too high for the bot to manage: **{roles}** \ No newline at end of file diff --git a/src/structure/components/commands/utility/Selfrole.js b/src/structure/components/commands/utility/Selfrole.js index fef0737..84adb22 100644 --- a/src/structure/components/commands/utility/Selfrole.js +++ b/src/structure/components/commands/utility/Selfrole.js @@ -34,12 +34,16 @@ class SelfroleCommand extends SlashCommand { const { guild, member } = invoker; const { selfrole } = await guild.settings(); if (!selfrole.roles.length) return { index: 'COMMAND_SELFROLE_NONE', emoji: 'failure' }; + const ownHighest = guild.me.roles.highest; const memberRoles = member.roles.cache.map((r) => r.id); + const tooHigh = roles?.value.filter((r) => r.position > ownHighest.position); const invalid = roles?.value.filter((r) => !selfrole.roles.includes(r.id)) || []; - const _roles = roles?.value.filter((r) => selfrole.roles.includes(r.id)) || []; - let warning = null; - if (invalid.length) warning = guild.format('COMMAND_SELFROLE_INVALID', { roles: invalid.map((r) => r.name).join('**, **') }); + const _roles = roles?.value.filter((r) => selfrole.roles.includes(r.id) && !tooHigh.some((x) => x.id === r.id)) || []; + // console.log(tooHigh, invalid, _roles); + let warning = ''; + if (invalid.length) warning += guild.format('COMMAND_SELFROLE_INVALID', { roles: invalid.map((r) => r.name).join('**, **') }); + if (tooHigh.length) warning += `\n\n${guild.format('COMMAND_SELFROLE_TOOHIGH', { roles: tooHigh.map((r) => r.name).join('**, **') })}`; if(!_roles.length && subcommand !== 'clear') return { content: warning }; let index = null, diff --git a/src/structure/components/settings/utility/Selfrole.js b/src/structure/components/settings/utility/Selfrole.js index 1883db5..11a8ad6 100644 --- a/src/structure/components/settings/utility/Selfrole.js +++ b/src/structure/components/settings/utility/Selfrole.js @@ -95,9 +95,9 @@ class SelfroleSetting extends Setting { components }; - const msg = await oldChannel.messages.fetch(setting.message).catch(() => null); - if (msg && newChannel === oldChannel) { - await msg.edit(payload); + if (newChannel === oldChannel) { + const msg = await oldChannel.messages.fetch(setting.message).catch(() => null); + if(msg) await msg.edit(payload); } else { const msg = await newChannel.send(payload); setting.message = msg.id; diff --git a/src/structure/interfaces/Setting.js b/src/structure/interfaces/Setting.js index 5dffd08..1c0641e 100644 --- a/src/structure/interfaces/Setting.js +++ b/src/structure/interfaces/Setting.js @@ -209,7 +209,7 @@ class Setting extends Component { if (!response) return { error: true, message: invoker.format('ERR_TIMEOUT') }; const content = response.content.toLowerCase(); if(invoker.channel.permissionsFor(invoker.guild.me).has('MANAGE_MESSAGES')) - await response.delete(); + await response.delete().catch(() => null); if (['cancel', 'abort', 'exit'].includes(content)) return { error: true, message: invoker.format('ERR_CANCEL')