From a60e6728fd4a5cbacd145fab5fbe83b5883dabc5 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Mon, 4 Jul 2022 18:06:39 +0300 Subject: [PATCH] check if a message is already filtered --- .../components/observers/Automoderation.js | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/structure/components/observers/Automoderation.js b/src/structure/components/observers/Automoderation.js index 036d3d0..8c85b03 100644 --- a/src/structure/components/observers/Automoderation.js +++ b/src/structure/components/observers/Automoderation.js @@ -122,7 +122,7 @@ module.exports = class AutoModeration extends Observer { async filterWords(message, edited) { const { guild, author, channel, guildWrapper: wrapper } = message; - if (!guild || author.bot) return; + if (!guild || author.bot || message.filtered) return; const member = message.member || await guild.members.fetch(author.id).catch(() => null); const settings = await wrapper.settings(); @@ -419,7 +419,7 @@ module.exports = class AutoModeration extends Observer { async filterLinks(message, edited) { const { guild, author, channel, guildWrapper: wrapper } = message; - if (!guild || author.bot) return; + if (!guild || author.bot || message.filtered) return; const member = message.member || await guild.members.fetch(author.id).catch(() => null); const { resolver } = this.client; @@ -449,10 +449,12 @@ module.exports = class AutoModeration extends Observer { for (const match of matches) { const { domain } = match.match(this.regex.linkReg).groups; + // Invites are filtered separately + if (domain.toLowerCase() === 'discord.gg') continue; log += `\nMatched link ${match}: `; const predicate = (dom) => { - return dom.includes(domain) || domain.includes(dom); + return dom.toLowerCase().includes(domain) || domain.includes(dom.toLowerCase()); }; if (blacklist.some(predicate)) { @@ -506,7 +508,7 @@ module.exports = class AutoModeration extends Observer { }, 10000); } - this.client.rateLimiter.queueDelete(msg.channel, msg); + this.client.rateLimiter.queueDelete(msg.channel, msg).catch(() => null); if (actions.length) { @@ -534,7 +536,7 @@ module.exports = class AutoModeration extends Observer { async filterInvites(message, edited) { const { guild, author, channel, guildWrapper: wrapper } = message; - if (!guild || author.bot) return; + if (!guild || author.bot || message.filtered) return; const member = message.member || await guild.members.fetch(author.id).catch(() => null); const settings = await wrapper.settings(); @@ -561,7 +563,7 @@ module.exports = class AutoModeration extends Observer { const result = await wrapper.checkInvite(match.groups.code); const invite = await this.client.fetchInvite(match.groups.code); if (whitelist.includes(invite.guild.id)) return; - + if (!result) { // Doesn't resolve to the origin server let action = null; @@ -572,7 +574,7 @@ module.exports = class AutoModeration extends Observer { matcher: 'invites', filter: 'invite' }; - if (!action) return this.client.rateLimiter.queueDelete(msg.channel, msg); //msg.delete(); + if (!action) return this.client.rateLimiter.queueDelete(msg.channel, msg).catch(() => null); //msg.delete(); if (!silent) { 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 }); @@ -592,7 +594,7 @@ module.exports = class AutoModeration extends Observer { async filterMentions(message) { const { guild, author, channel, guildWrapper: wrapper } = message; - if (!guild || author.bot) return; + if (!guild || author.bot || message.filtered) return; const member = message.member || await guild.members.fetch(author.id).catch(() => null); const settings = await wrapper.settings(); @@ -629,7 +631,7 @@ module.exports = class AutoModeration extends Observer { }, 10000); } - this.client.rateLimiter.queueDelete(channel, message); + this.client.rateLimiter.queueDelete(channel, message).catch(() => null); const filterResult = { filter: 'mention', amount: ids.length