[Mod] Account for duplicated mentions (#4359)

* 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>
This commit is contained in:
Sharky 2020-09-27 19:27:53 -06:00 committed by GitHub
parent 284080ec83
commit 3699c246df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 5 deletions

View File

@ -45,7 +45,11 @@ class Events(MixinMeta):
guild, author = message.guild, message.author guild, author = message.guild, message.author
mention_spam = await self.config.guild(guild).mention_spam.all() 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 mention_spam["ban"]:
if len(mentions) >= mention_spam["ban"]: if len(mentions) >= mention_spam["ban"]:
try: try:

View File

@ -49,7 +49,7 @@ class Mod(
default_global_settings = {"version": ""} default_global_settings = {"version": ""}
default_guild_settings = { default_guild_settings = {
"mention_spam": {"ban": None, "kick": None, "warn": None}, "mention_spam": {"ban": None, "kick": None, "warn": None, "strict": False},
"delete_repeats": -1, "delete_repeats": -1,
"ignored": False, "ignored": False,
"respect_hierarchy": True, "respect_hierarchy": True,

View File

@ -28,6 +28,7 @@ class ModSettings(MixinMeta):
warn_mention_spam = data["mention_spam"]["warn"] warn_mention_spam = data["mention_spam"]["warn"]
kick_mention_spam = data["mention_spam"]["kick"] kick_mention_spam = data["mention_spam"]["kick"]
ban_mention_spam = data["mention_spam"]["ban"] ban_mention_spam = data["mention_spam"]["ban"]
strict_mention_spam = data["mention_spam"]["strict"]
respect_hierarchy = data["respect_hierarchy"] respect_hierarchy = data["respect_hierarchy"]
delete_delay = data["delete_delay"] delete_delay = data["delete_delay"]
reinvite_on_unban = data["reinvite_on_unban"] reinvite_on_unban = data["reinvite_on_unban"]
@ -54,6 +55,11 @@ class ModSettings(MixinMeta):
if ban_mention_spam if ban_mention_spam
else _("No") 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( msg += _("Respects hierarchy: {yes_or_no}\n").format(
yes_or_no=_("Yes") if respect_hierarchy else _("No") yes_or_no=_("Yes") if respect_hierarchy else _("No")
) )
@ -106,6 +112,34 @@ class ModSettings(MixinMeta):
Manage the automoderation settings for mentionspam. 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") @mentionspam.command(name="warn")
@commands.guild_only() @commands.guild_only()
async def mentionspam_warn(self, ctx: commands.Context, max_mentions: int): async def mentionspam_warn(self, ctx: commands.Context, max_mentions: int):
@ -141,7 +175,7 @@ class ModSettings(MixinMeta):
await ctx.send( await ctx.send(
_( _(
"Autowarn for mention spam enabled. " "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}" "in a single message will be autowarned.\n{mismatch_message}"
).format(max_mentions=max_mentions, mismatch_message=mismatch_message) ).format(max_mentions=max_mentions, mismatch_message=mismatch_message)
) )
@ -181,7 +215,7 @@ class ModSettings(MixinMeta):
await ctx.send( await ctx.send(
_( _(
"Autokick for mention spam enabled. " "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}" "in a single message will be autokicked.\n{mismatch_message}"
).format(max_mentions=max_mentions, mismatch_message=mismatch_message) ).format(max_mentions=max_mentions, mismatch_message=mismatch_message)
) )
@ -220,7 +254,7 @@ class ModSettings(MixinMeta):
await ctx.send( await ctx.send(
_( _(
"Autoban for mention spam enabled. " "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}" "in a single message will be autobanned.\n{mismatch_message}"
).format(max_mentions=max_mentions, mismatch_message=mismatch_message) ).format(max_mentions=max_mentions, mismatch_message=mismatch_message)
) )