From d066818e368e4b729363ed6709b4df780e67e2c6 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Wed, 11 May 2022 13:51:35 +0300 Subject: [PATCH] bugfix --- .../en_gb/commands/en_gb_utility.lang | 6 +++++- .../components/commands/utility/Selfrole.js | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/localization/en_gb/commands/en_gb_utility.lang b/src/localization/en_gb/commands/en_gb_utility.lang index bc7a3fd..1e9bf8e 100644 --- a/src/localization/en_gb/commands/en_gb_utility.lang +++ b/src/localization/en_gb/commands/en_gb_utility.lang @@ -136,4 +136,8 @@ Successfully gave you **{roles}**. Successfully removed **{roles}** from you. [COMMAND_SELFROLE_CLEAR_SUCCESS] -Successfully removed all your selfroles. \ No newline at end of file +Successfully removed all your selfroles. + +[COMMAND_SELFROLE_INVALID] +{emoji_failure} The following roles are not self-assignable: +**{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 4bfcf83..54c9ef1 100644 --- a/src/structure/components/commands/utility/Selfrole.js +++ b/src/structure/components/commands/utility/Selfrole.js @@ -36,22 +36,32 @@ class SelfroleCommand extends SlashCommand { if (!selfrole.roles.length) return { index: 'COMMAND_SELFROLE_NONE', emoji: 'failure' }; const memberRoles = member.roles.cache.map((r) => r.id); + 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('**, **') }); + if(!_roles.length) return { content: warning }; + let index = null, + params = {}; if (subcommand === 'add') { await member.roles.set([...new Set([...memberRoles, ..._roles.map((r) => r.id)])]); - return { index: 'COMMAND_SELFROLE_ADD_SUCCESS', emoji: 'success', params: { roles: _roles.map((r) => r.name).join('**, **') } }; + index = 'COMMAND_SELFROLE_ADD_SUCCESS'; + params = { roles: _roles.map((r) => r.name).join('**, **') }; } else if (subcommand === 'remove') { const ids = _roles.map((r) => r.id); const set = memberRoles.filter((r) => !ids.includes(r)); await member.roles.set([...new Set(set)]); - return { index: 'COMMAND_SELFROLE_REMOVE_SUCCESS', emoji: 'success', params: { roles: _roles.map((r) => r.name).join('**, **') } }; + index = 'COMMAND_SELFROLE_REMOVE_SUCCESS'; + params= { roles: _roles.map((r) => r.name).join('**, **') }; } else if (subcommand === 'clear') { const set = memberRoles.filter((r) => !selfrole.roles.includes(r)); await member.roles.set([...new Set(set)]); - return { index: 'COMMAND_SELFROLE_CLEAR_SUCCESS', emoji: 'success', }; + index= 'COMMAND_SELFROLE_CLEAR_SUCCESS'; } + return { content: guild.format(index, params) + warning? `\n\n${warning}` : '', emoji: 'success' }; + } async _listRoles(invoker) {