This commit is contained in:
Erik 2022-07-17 23:56:05 +03:00
parent 722b514cef
commit 482a38a80b
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
4 changed files with 15 additions and 7 deletions

View File

@ -144,3 +144,7 @@ Successfully removed all your selfroles.
[COMMAND_SELFROLE_INVALID] [COMMAND_SELFROLE_INVALID]
{emoji_failure} The following roles are not self-assignable: {emoji_failure} The following roles are not self-assignable:
**{roles}** **{roles}**
[COMMAND_SELFROLE_TOOHIGH]
{emoji_failure} The following roles are too high for the bot to manage:
**{roles}**

View File

@ -34,12 +34,16 @@ class SelfroleCommand extends SlashCommand {
const { guild, member } = invoker; const { guild, member } = invoker;
const { selfrole } = await guild.settings(); const { selfrole } = await guild.settings();
if (!selfrole.roles.length) return { index: 'COMMAND_SELFROLE_NONE', emoji: 'failure' }; 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 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 invalid = roles?.value.filter((r) => !selfrole.roles.includes(r.id)) || [];
const _roles = roles?.value.filter((r) => selfrole.roles.includes(r.id)) || []; const _roles = roles?.value.filter((r) => selfrole.roles.includes(r.id) && !tooHigh.some((x) => x.id === r.id)) || [];
let warning = null; // console.log(tooHigh, invalid, _roles);
if (invalid.length) warning = guild.format('COMMAND_SELFROLE_INVALID', { roles: invalid.map((r) => r.name).join('**, **') }); 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 }; if(!_roles.length && subcommand !== 'clear') return { content: warning };
let index = null, let index = null,

View File

@ -95,9 +95,9 @@ class SelfroleSetting extends Setting {
components components
}; };
if (newChannel === oldChannel) {
const msg = await oldChannel.messages.fetch(setting.message).catch(() => null); const msg = await oldChannel.messages.fetch(setting.message).catch(() => null);
if (msg && newChannel === oldChannel) { if(msg) await msg.edit(payload);
await msg.edit(payload);
} else { } else {
const msg = await newChannel.send(payload); const msg = await newChannel.send(payload);
setting.message = msg.id; setting.message = msg.id;

View File

@ -209,7 +209,7 @@ class Setting extends Component {
if (!response) return { error: true, message: invoker.format('ERR_TIMEOUT') }; if (!response) return { error: true, message: invoker.format('ERR_TIMEOUT') };
const content = response.content.toLowerCase(); const content = response.content.toLowerCase();
if(invoker.channel.permissionsFor(invoker.guild.me).has('MANAGE_MESSAGES')) 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 { if (['cancel', 'abort', 'exit'].includes(content)) return {
error: true, error: true,
message: invoker.format('ERR_CANCEL') message: invoker.format('ERR_CANCEL')