From c85ae1d48d8e6afa253613c31f1c9718da673a8b Mon Sep 17 00:00:00 2001 From: Navy Date: Tue, 22 Jun 2021 19:44:38 +0300 Subject: [PATCH 1/4] block repeat infraction executions for the same user --- .../client/components/observers/Automoderation.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/structure/client/components/observers/Automoderation.js b/structure/client/components/observers/Automoderation.js index 7ef1a0c..18ca420 100644 --- a/structure/client/components/observers/Automoderation.js +++ b/structure/client/components/observers/Automoderation.js @@ -45,12 +45,19 @@ module.exports = class AutoModeration extends Observer { ]; this.whitelist = new BinaryTree(this.client, FilterPresets.whitelist); + this.executing = {}; } async _moderate(action, guild, channel, member, reason, filterResult) { + + // Prevent simultaneous execution of the same filter on the same user when spamming + if (!this.executing[filterResult.filter]) this.executing[filterResult.filter] = []; + if (this.executing[filterResult.filter].includes(member.id)) return; + this.executing[filterResult.filter].push(member.id); + const InfractionClass = CONSTANTS.Infractions[action.type]; - return this.client.moderationManager._handleTarget(InfractionClass, member, { + const result = await this.client.moderationManager._handleTarget(InfractionClass, member, { guild, channel, executor: guild.me, @@ -63,7 +70,10 @@ module.exports = class AutoModeration extends Observer { data: { automoderation: filterResult } - }); + }).catch(this.client.logger.error.bind(this.client.logger)); + + await Util.wait(5000); + this.executing[filterResult.filter].splice(this.executing[filterResult.filter].indexOf(member.id), 1); } @@ -399,6 +409,7 @@ module.exports = class AutoModeration extends Observer { this.client.rateLimiter.queueDelete(msg.channel, msg); //msg.delete(); + filterResult.filter = 'link'; this._moderate(action, guild, channel, member, msg.format('L_FILTER_ACTION', { domain: filterResult.match }), filterResult, message); } else this.client.rateLimiter.queueDelete(msg.channel, msg); //msg.delete(); From 4934b8fad9589a6956429c312dd0bbcb3dd52155 Mon Sep 17 00:00:00 2001 From: Navy Date: Wed, 23 Jun 2021 11:49:59 +0300 Subject: [PATCH 2/4] improvements to regex filter --- structure/client/components/observers/Automoderation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/structure/client/components/observers/Automoderation.js b/structure/client/components/observers/Automoderation.js index 18ca420..9ddf8ee 100644 --- a/structure/client/components/observers/Automoderation.js +++ b/structure/client/components/observers/Automoderation.js @@ -116,7 +116,7 @@ module.exports = class AutoModeration extends Observer { // _matcher: locally used variable for which word in the list triggered it | // type: which detection type matched it let filterResult = { filter: 'word', match: null, matched: false, matcher: null, _matcher: null, preset: false }; - const words = content.toLowerCase().split(' ').filter((elem) => elem.length); + const words = content.toLowerCase().replace(/[,?.!]/gu, '').split(' ').filter((elem) => elem.length); // Remove any potential bypass characters //const _words = words.map((word) => word.replace(/[.'*_?+"#%&=-]/gu, '')); From 6c92c3c00a3d8987ef728e64792b178bb14c4105 Mon Sep 17 00:00:00 2001 From: Navy Date: Wed, 23 Jun 2021 11:51:34 +0300 Subject: [PATCH 3/4] pre work for future stuff --- .../components/commands/information/Guild.js | 37 ++---------- .../components/commands/utility/Lookup.js | 5 +- .../settings/moderation/WordWatcher.js | 59 ++++++++++++++++--- 3 files changed, 58 insertions(+), 43 deletions(-) diff --git a/structure/client/components/commands/information/Guild.js b/structure/client/components/commands/information/Guild.js index 12fcb49..0fa1f99 100644 --- a/structure/client/components/commands/information/Guild.js +++ b/structure/client/components/commands/information/Guild.js @@ -17,9 +17,11 @@ class GuildCommand extends Command { } - async execute(message) { + async execute(message, { params }) { - const guild = await message.guild.fetch(); + let guild = null; + //if(params[0]) guild = await this.client.fetchGuildPreview(params[0]); + guild = await message.guild.fetch(); let vc = 0, tc = 0, @@ -108,37 +110,6 @@ class GuildCommand extends Command { }); return message.embed(embed); - - // return message.embed({ - // description: message.format('C_GUILD_TEMPLATE', { - // createdAt, - // description, - // maxMembers, - // approxPresences: guild.approximatePresenceCount, - // maxPresences: guild.maximumPresences, - // totalChannels, - // vc, - // tc, - // cat, - // news, - // owner: guild.owner.id, - // id: guild.id, - // name: guild.name, - // region: guild.region, - // members: guild.memberCount, - // boosters: guild.premiumSubscriptionCount, - // tier: guild.premiumTier, - // shard: guild.shardID, - // roleCount: guild.roles.cache.size, - // emojiCount: guild.emojis.cache.filter((e) => !e.animated).size, - // gifEmojiCount: guild.emojis.cache.filter((e) => e.animated).size, - // emojiTotal: 50 + 50 * guild.premiumTier, - // features: guild.features.length ? guild.features.join(', ') : message.format('C_GUILD_NOFEAT') - // }), - // thumbnail: { - // url: guild.iconURL() - // } - // }); } diff --git a/structure/client/components/commands/utility/Lookup.js b/structure/client/components/commands/utility/Lookup.js index a404126..3a4fb5f 100644 --- a/structure/client/components/commands/utility/Lookup.js +++ b/structure/client/components/commands/utility/Lookup.js @@ -14,6 +14,7 @@ class LookupCommand extends Command { "SvJgtEj", "discord.gg/SvJgtEj" ], + aliases: [], restricted: true //For now // throttling: { // usages: 1, @@ -32,13 +33,11 @@ class LookupCommand extends Command { try { invite = await this.client.fetchInvite(params); } catch(e) { - return message.respond(message.format('C_LOOKUP_FAILEDMATCH'), { + return message.respond(message.format('C_LOOKUP_FAILED'), { emoji: 'failure' }); } - console.log(invite); - const fields = []; if(invite.inviter) { diff --git a/structure/client/components/settings/moderation/WordWatcher.js b/structure/client/components/settings/moderation/WordWatcher.js index 8bb3935..1aab36c 100644 --- a/structure/client/components/settings/moderation/WordWatcher.js +++ b/structure/client/components/settings/moderation/WordWatcher.js @@ -1,7 +1,15 @@ -const { Setting } = require('../../../../interfaces/'); +const { FilterSetting } = require('../../../../interfaces/'); const { Util } = require('../../../../../util'); +const emojis = { + WARN: '<:note:744490065354293258>', + MUTE: '<:muted:853709118988353556>', + KICK: '๐Ÿ‘ข', + BAN: '๐Ÿ”จ', + SOFTBAN: '๐Ÿงน', + DELETE: '<:failure:723595130912637018>' +}; -module.exports = class WordWatcher extends Setting { +module.exports = class WordWatcher extends FilterSetting { constructor(client) { @@ -12,14 +20,15 @@ module.exports = class WordWatcher extends Setting { resolve: 'GUILD', usage: '