From 18f61d07f66eb21e5cb2a169f3768c3c1d3d4229 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Wed, 17 Aug 2022 12:35:04 +0300 Subject: [PATCH] bugfixes, perms checks --- src/localization/en_gb/commands/en_gb_moderation.lang | 3 +++ .../components/commands/moderation/History.js | 1 + src/structure/components/commands/utility/Remind.js | 2 +- src/structure/components/observers/UtilityHook.js | 7 +++++-- .../components/settings/administration/Indexing.js | 2 +- src/structure/infractions/Prune.js | 11 +++++++++++ 6 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/localization/en_gb/commands/en_gb_moderation.lang b/src/localization/en_gb/commands/en_gb_moderation.lang index f1d4018..d4c7d21 100644 --- a/src/localization/en_gb/commands/en_gb_moderation.lang +++ b/src/localization/en_gb/commands/en_gb_moderation.lang @@ -203,6 +203,9 @@ I could not find any messages with those arguments [C_PRUNE_NODELETE] I had issues deleting those messages +[C_PRUNE_MISSING_ACCESS] +Missing access to read messages in the channel. Ensure the bot has permissions to view channel and read message history. + //Vckick Command [COMMAND_VCKICK_HELP] Kick provided members from their connected voice-channel. diff --git a/src/structure/components/commands/moderation/History.js b/src/structure/components/commands/moderation/History.js index 1c0ccc4..0f1bd92 100644 --- a/src/structure/components/commands/moderation/History.js +++ b/src/structure/components/commands/moderation/History.js @@ -184,6 +184,7 @@ class HistoryCommand extends SlashCommand { } string += `\n**Reason:** \`${infraction.reason ? handleReason(infraction.reason) : '`N/A`'}\``; + if (infraction.resolved) string += `\n${guild.format('INFRACTION_RESOLVED')}`; if (i !== results.length - 1) string += `\n${ZeroWidthChar}`; //Space out cases (as long as its not at the end) embed.fields.push({ diff --git a/src/structure/components/commands/utility/Remind.js b/src/structure/components/commands/utility/Remind.js index 4d098ae..1b44cf3 100644 --- a/src/structure/components/commands/utility/Remind.js +++ b/src/structure/components/commands/utility/Remind.js @@ -47,7 +47,7 @@ class RemindCommand extends SlashCommand { const reminders = guild.callbacks.filter((cb) => cb.data.user === author.id).map((val) => val); const embed = this._remindersEmbed(reminders, guild); const msg = await invoker.promptMessage(guild.format('COMMAND_REMIND_SELECT'), { embed }); - await msg.delete(); + if(msg) await msg.delete(); const response = msg?.content; if (!response) return invoker.editReply({ index: 'COMMAND_REMIND_DELETE_TIMEOUT', embeds: [] }); diff --git a/src/structure/components/observers/UtilityHook.js b/src/structure/components/observers/UtilityHook.js index d362a26..113a32f 100644 --- a/src/structure/components/observers/UtilityHook.js +++ b/src/structure/components/observers/UtilityHook.js @@ -72,7 +72,7 @@ class UtilityHook extends Observer { } else if (infraction.data.muteType === 1) { if (!role) return; - await Util.wait(5 * 1000); //wait 5 seconds in case other bots add roles that would break the mute + await Util.wait(7.5 * 1000); //wait 5 seconds in case other bots add roles that would break the mute const roles = member.roles.cache; const managed = roles.find((r) => r.managed); const remove = roles.filter((r) => !r.managed); //Have to do this bs for managed roles -.- @@ -84,7 +84,7 @@ class UtilityHook extends Observer { } else if (infraction.data.muteType === 2) { - await Util.wait(5 * 1000); //wait 5 seconds in case other bots add roles that would break the mute + await Util.wait(7.5 * 1000); //wait 5 seconds in case other bots add roles that would break the mute const roles = member.roles.cache; const remove = roles.filter((r) => !r.managed); //Have to do this bs for managed roles -.- @@ -123,6 +123,9 @@ class UtilityHook extends Observer { const _roles = await guild.resolveRoles(setting.roles); if (_roles.some((r) => r.position >= me.roles.highest.position)) return; const roles = _roles.map((r) => r.id); + // Sometimes the member isn't available on the API for some reason, + // seeing if waiting a bit helps, so we don't try to patch a member that's still being processed on discord's API + await Util.wait(5 * 1000); await member.roles.add(roles, 'Adding autoroles').catch(this.logger.error.bind(this.logger)); } diff --git a/src/structure/components/settings/administration/Indexing.js b/src/structure/components/settings/administration/Indexing.js index 149ff22..f4955cb 100644 --- a/src/structure/components/settings/administration/Indexing.js +++ b/src/structure/components/settings/administration/Indexing.js @@ -33,7 +33,7 @@ class IndexSetting extends Setting { if (enabled) setting.enabled = enabled.value; if (description) setting.description = description.value; - return { index: 'SETTING_SUCCES_ALT' }; + return { index: 'SETTING_SUCCESS_ALT' }; } diff --git a/src/structure/infractions/Prune.js b/src/structure/infractions/Prune.js index 78916a8..ca0a1b3 100644 --- a/src/structure/infractions/Prune.js +++ b/src/structure/infractions/Prune.js @@ -195,6 +195,17 @@ class PruneInfraction extends Infraction { return `\n${this.guild.format('INFRACTION_DESCRIPTIONAMOUNT', { amount: this.data.amount })}`; } + async verify() { + + const me = await this.guild.resolveMember(this.client.user); + const perms = this.target.permissionsFor(me); + if (perms.missing('ViewChannel', 'ReadMessageHistory').length) return this._fail('C_PRUNE_MISSING_ACCESS', true); + if (perms.missing('ManageMessages').length) return this._fail('C_PRUNE_INSUFFICIENTPERMISSIONS', true); + + return super._verify(); + + } + } module.exports = PruneInfraction; \ No newline at end of file