From e28b2f28906c536301bf016cb506fc18173d7545 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Mon, 19 Sep 2022 22:02:28 +0300 Subject: [PATCH] fixes, changed error log to use plain text when missing embed perms --- src/structure/client/ModerationManager.js | 2 +- .../components/observers/Automoderation.js | 24 ++++++++++++------- .../components/observers/ErrorLog.js | 11 ++++++--- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/structure/client/ModerationManager.js b/src/structure/client/ModerationManager.js index 50093c5..5fb6bfa 100644 --- a/src/structure/client/ModerationManager.js +++ b/src/structure/client/ModerationManager.js @@ -306,7 +306,7 @@ class ModerationManager { if (target instanceof GuildMember) { // The cached member is sometimes outdated, ensure we get the latest member so the perm checks don't fail // Would help if members had a cached timestamp, might have to change this to work with a wrapper - target = await guild.members.fetch({ user: target, force: true }); + target = await guild.members.fetch({ user: target, force: true }).catch(() => null); } else if (!(target instanceof User)) { target = await wrapper.channels.fetch(target.id, { force: true }); } diff --git a/src/structure/components/observers/Automoderation.js b/src/structure/components/observers/Automoderation.js index c8a68ee..3a05eff 100644 --- a/src/structure/components/observers/Automoderation.js +++ b/src/structure/components/observers/Automoderation.js @@ -137,7 +137,8 @@ module.exports = class AutoModeration extends Observer { if (!enabled || roles.some((r) => bypass.includes(r)) || ignore.includes(channel.id)) return; - const missing = channel.permissionsFor(this.client.user)?.missing('ManageMessages') || []; + const perms = channel.permissionsFor(this.client.user); + const missing = perms?.missing('ManageMessages') || []; if (missing.length) { this.client.emit('filterMissingPermissions', { channel, guild: wrapper, filter: 'word', permissions: missing }); return; @@ -209,7 +210,7 @@ module.exports = class AutoModeration extends Observer { log += `\nFilter result: ${inspect(filterResult)}`; - if (!silent && channel.permissionsFor(this.client.user)?.has('SendMessages')) { + if (!silent && perms?.has('SendMessages')) { const res = await this.client.rateLimiter.limitSend(msg.channel, wrapper.format('W_FILTER_DELETE', { user: author.id }), undefined, 'wordFilter').catch(() => null); //const res = await msg.formattedRespond('W_FILTER_DELETE', { params: { user: author.id } }); //if (res) res.delete({ timeout: 10000 }).catch(catcher(240)); @@ -439,7 +440,8 @@ module.exports = class AutoModeration extends Observer { if (roles.some((r) => bypass.includes(r)) || ignore.includes(channel.id)) return; - const missing = channel.permissionsFor(this.client.user)?.missing('ManageMessages') || []; + const perms = channel.permissionsFor(this.client.user); + const missing = perms?.missing('ManageMessages') || []; if (missing.length) { this.client.emit('filterMissingPermissions', { channel, guild: wrapper, filter: 'link', permissions: missing }); return; @@ -516,7 +518,7 @@ module.exports = class AutoModeration extends Observer { msg.filtered = filterResult; filterResult.filter = 'link'; - if (!silent) { + if (!silent && perms?.has('SendMessages')) { const res = await this.client.rateLimiter.limitSend(msg.channel, wrapper.format('L_FILTER_DELETE', { user: author.id }), undefined, 'linkFilter'); //const res = await msg.formattedRespond(`L_FILTER_DELETE`, { params: { user: author.id } }); //if (res) res.delete({ timeout: 10000 }); @@ -566,7 +568,8 @@ module.exports = class AutoModeration extends Observer { if (roles.some((r) => bypass?.includes(r)) || ignore?.includes(channel.id)) return; - const missing = channel.permissionsFor(this.client.user)?.missing('ManageMessages') || []; + const perms = channel.permissionsFor(this.client.user); + const missing = perms?.missing('ManageMessages') || []; if (missing.length) { this.client.emit('filterMissingPermissions', { channel, guild: wrapper, filter: 'invite', permissions: missing }); return; @@ -594,7 +597,7 @@ module.exports = class AutoModeration extends Observer { filter: 'invite' }; if (!action) return this.client.rateLimiter.queueDelete(msg.channel, msg).catch(() => null); //msg.delete(); - if (!silent) { + if (!silent && perms?.has('SendMessages')) { const res = await this.client.rateLimiter.limitSend(msg.channel, wrapper.format('I_FILTER_DELETE', { user: author.id }), undefined, 'inviteFilter'); //if (res) res.delete({ timeout: 10000 }); setTimeout(() => { @@ -626,7 +629,8 @@ module.exports = class AutoModeration extends Observer { if (!enabled || roles.some((r) => bypass.includes(r)) || ignore.includes(channel.id)) return; - const missing = channel.permissionsFor(this.client.user)?.missing('ManageMessages') || []; + const perms = channel.permissionsFor(this.client.user); + const missing = perms?.missing('ManageMessages') || []; if (missing.length) { this.client.emit('filterMissingPermissions', { channel, guild: wrapper, filter: 'mention', permissions: missing }); return; @@ -646,7 +650,7 @@ module.exports = class AutoModeration extends Observer { } if (ids.length < limit) return; - if (!silent) { + if (!silent && perms?.has('SendMessages')) { const res = await this.client.rateLimiter.limitSend(channel, wrapper.format('M_FILTER_DELETE', { user: author.id }), undefined, 'mentionFilter'); setTimeout(() => { res.delete?.().catch(() => { /**/ }); @@ -678,4 +682,8 @@ module.exports = class AutoModeration extends Observer { } + async raidProtection(member) { + + } + }; \ No newline at end of file diff --git a/src/structure/components/observers/ErrorLog.js b/src/structure/components/observers/ErrorLog.js index e815e5a..570dd51 100644 --- a/src/structure/components/observers/ErrorLog.js +++ b/src/structure/components/observers/ErrorLog.js @@ -153,12 +153,17 @@ class ErrorLog extends Observer { async post(guild, embed, type) { const settings = await guild.settings(); const { errors } = settings; + + // TODO add types to error logging + // eslint-disable-next-line no-unused-vars const { channel: _channel, types } = errors; if (!_channel) return; - const channel = await guild.resolveChannel(_channel); - if (!channel || channel.permissionsFor(guild.me).missing('SendMessages', 'EmbedLinks')) return; - this.client.rateLimiter.limitSend(channel, { embeds: [embed] }, null, type); + const perms = channel.permissionsFor(guild.me); + + if (!channel || perms.missing('SendMessages').length) return; + if (!perms.missing('EmbedLinks').length) this.client.rateLimiter.limitSend(channel, { content: embed.description }); + else this.client.rateLimiter.limitSend(channel, { embeds: [embed] }, null, type); } }