From 3699c246dfdc474765bfa2314c3e0630db155806 Mon Sep 17 00:00:00 2001 From: Sharky <42697462+SharkyTheKing@users.noreply.github.com> Date: Sun, 27 Sep 2020 19:27:53 -0600 Subject: [PATCH] [Mod] Account for duplicated mentions (#4359) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Account for duplicated mentions * Spelling fix + Wording change * Requested changes *hopefully* * forgot to formattttttttttttttttttttttt * Improve the consistency with existing commands in inconsistent `[p]modset` group * What was the point of defining `guild` if you didn't end up using it, Jack!? * I hate you, web editor ಠ益ಠ * You could have just copy-pasted this Jack, seriously... Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> --- redbot/cogs/mod/events.py | 6 +++++- redbot/cogs/mod/mod.py | 2 +- redbot/cogs/mod/settings.py | 40 ++++++++++++++++++++++++++++++++++--- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/redbot/cogs/mod/events.py b/redbot/cogs/mod/events.py index c88472bf1..a3a6ca8c4 100644 --- a/redbot/cogs/mod/events.py +++ b/redbot/cogs/mod/events.py @@ -45,7 +45,11 @@ class Events(MixinMeta): guild, author = message.guild, message.author mention_spam = await self.config.guild(guild).mention_spam.all() - mentions = set(message.mentions) + if mention_spam["strict"]: # if strict is enabled + mentions = message.raw_mentions + else: # if not enabled + mentions = set(message.mentions) + if mention_spam["ban"]: if len(mentions) >= mention_spam["ban"]: try: diff --git a/redbot/cogs/mod/mod.py b/redbot/cogs/mod/mod.py index 986cef5f9..fd207b452 100644 --- a/redbot/cogs/mod/mod.py +++ b/redbot/cogs/mod/mod.py @@ -49,7 +49,7 @@ class Mod( default_global_settings = {"version": ""} default_guild_settings = { - "mention_spam": {"ban": None, "kick": None, "warn": None}, + "mention_spam": {"ban": None, "kick": None, "warn": None, "strict": False}, "delete_repeats": -1, "ignored": False, "respect_hierarchy": True, diff --git a/redbot/cogs/mod/settings.py b/redbot/cogs/mod/settings.py index 373315729..c559ac1c3 100644 --- a/redbot/cogs/mod/settings.py +++ b/redbot/cogs/mod/settings.py @@ -28,6 +28,7 @@ class ModSettings(MixinMeta): warn_mention_spam = data["mention_spam"]["warn"] kick_mention_spam = data["mention_spam"]["kick"] ban_mention_spam = data["mention_spam"]["ban"] + strict_mention_spam = data["mention_spam"]["strict"] respect_hierarchy = data["respect_hierarchy"] delete_delay = data["delete_delay"] reinvite_on_unban = data["reinvite_on_unban"] @@ -54,6 +55,11 @@ class ModSettings(MixinMeta): if ban_mention_spam else _("No") ) + msg += ( + _("Mention Spam Strict: All mentions will count including duplicates\n") + if strict_mention_spam + else _("Mention Spam Strict: Only unique mentions will count\n") + ) msg += _("Respects hierarchy: {yes_or_no}\n").format( yes_or_no=_("Yes") if respect_hierarchy else _("No") ) @@ -106,6 +112,34 @@ class ModSettings(MixinMeta): Manage the automoderation settings for mentionspam. """ + @mentionspam.command(name="strict") + @commands.guild_only() + async def mentionspam_strict(self, ctx: commands.Context, enabled: bool = None): + """ + Setting to account for duplicate mentions. + + If enabled all mentions will count including duplicated mentions. + If disabled only unique mentions will count. + + Use this command without any parameter to see current setting. + """ + guild = ctx.guild + if enabled is None: + state = await self.config.guild(guild).mention_spam.strict() + if state: + msg = _("Mention spam currently accounts for multiple mentions of the same user.") + else: + msg = _("Mention spam currently only accounts for mentions of different users.") + await ctx.send(msg) + return + + if enabled: + msg = _("Mention spam will now account for multiple mentions of the same user.") + else: + msg = _("Mention spam will only account for mentions of different users.") + await self.config.guild(guild).mention_spam.strict.set(enabled) + await ctx.send(msg) + @mentionspam.command(name="warn") @commands.guild_only() async def mentionspam_warn(self, ctx: commands.Context, max_mentions: int): @@ -141,7 +175,7 @@ class ModSettings(MixinMeta): await ctx.send( _( "Autowarn for mention spam enabled. " - "Anyone mentioning {max_mentions} or more different people " + "Anyone mentioning {max_mentions} or more people " "in a single message will be autowarned.\n{mismatch_message}" ).format(max_mentions=max_mentions, mismatch_message=mismatch_message) ) @@ -181,7 +215,7 @@ class ModSettings(MixinMeta): await ctx.send( _( "Autokick for mention spam enabled. " - "Anyone mentioning {max_mentions} or more different people " + "Anyone mentioning {max_mentions} or more people " "in a single message will be autokicked.\n{mismatch_message}" ).format(max_mentions=max_mentions, mismatch_message=mismatch_message) ) @@ -220,7 +254,7 @@ class ModSettings(MixinMeta): await ctx.send( _( "Autoban for mention spam enabled. " - "Anyone mentioning {max_mentions} or more different people " + "Anyone mentioning {max_mentions} or more people " "in a single message will be autobanned.\n{mismatch_message}" ).format(max_mentions=max_mentions, mismatch_message=mismatch_message) )