diff options
| author | 2020-08-15 09:55:43 -0700 | |
|---|---|---|
| committer | 2020-08-15 09:55:43 -0700 | |
| commit | 7cd29c72c0c074680d63740b79b388da95a50de5 (patch) | |
| tree | f0309642e85eae3718f13cfdeeed0fad9591fd42 | |
| parent | Merge pull request #1102 from AtieP/patch-1 (diff) | |
Don't patch ctx.message.author in antispam
The modification propagated across all code that is using the same
`Message` object, including all other `on_message` listeners. This
caused weird bugs e.g. the filtering cog thinking the bot authored a
message that triggered a filter.
Patching only `ctx.author` means the implementation is more fragile.
Infraction code must ensure it only retrieves the author via
`ctx.author` and not through `ctx.message`.
Fixes #1005
Fixes BOT-7D
Diffstat (limited to '')
| -rw-r--r-- | bot/cogs/antispam.py | 1 | ||||
| -rw-r--r-- | bot/cogs/moderation/scheduler.py | 6 | ||||
| -rw-r--r-- | bot/cogs/moderation/utils.py | 2 | 
3 files changed, 5 insertions, 4 deletions
| diff --git a/bot/cogs/antispam.py b/bot/cogs/antispam.py index 0bcca578d..bc31cbd95 100644 --- a/bot/cogs/antispam.py +++ b/bot/cogs/antispam.py @@ -219,7 +219,6 @@ class AntiSpam(Cog):              # Get context and make sure the bot becomes the actor of infraction by patching the `author` attributes              context = await self.bot.get_context(msg)              context.author = self.bot.user -            context.message.author = self.bot.user              # Since we're going to invoke the tempmute command directly, we need to manually call the converter.              dt_remove_role_after = await self.expiration_date_converter.convert(context, f"{remove_role_after}S") diff --git a/bot/cogs/moderation/scheduler.py b/bot/cogs/moderation/scheduler.py index 75028d851..051f6c52c 100644 --- a/bot/cogs/moderation/scheduler.py +++ b/bot/cogs/moderation/scheduler.py @@ -161,6 +161,7 @@ class InfractionScheduler:                      self.schedule_expiration(infraction)              except discord.HTTPException as e:                  # Accordingly display that applying the infraction failed. +                # Don't use ctx.message.author; antispam only patches ctx.author.                  confirm_msg = ":x: failed to apply"                  expiry_msg = ""                  log_content = ctx.author.mention @@ -190,6 +191,7 @@ class InfractionScheduler:          await ctx.send(f"{dm_result}{confirm_msg}{infr_message}.")          # Send a log message to the mod log. +        # Don't use ctx.message.author for the actor; antispam only patches ctx.author.          log.trace(f"Sending apply mod log for infraction #{id_}.")          await self.mod_log.send_log_message(              icon_url=icon, @@ -198,7 +200,7 @@ class InfractionScheduler:              thumbnail=user.avatar_url_as(static_format="png"),              text=textwrap.dedent(f"""                  Member: {user.mention} (`{user.id}`) -                Actor: {ctx.message.author}{dm_log_text}{expiry_log_text} +                Actor: {ctx.author}{dm_log_text}{expiry_log_text}                  Reason: {reason}              """),              content=log_content, @@ -242,7 +244,7 @@ class InfractionScheduler:          log_text = await self.deactivate_infraction(response[0], send_log=False)          log_text["Member"] = f"{user.mention}(`{user.id}`)" -        log_text["Actor"] = str(ctx.message.author) +        log_text["Actor"] = str(ctx.author)          log_content = None          id_ = response[0]['id']          footer = f"ID: {id_}" diff --git a/bot/cogs/moderation/utils.py b/bot/cogs/moderation/utils.py index fb55287b6..f21272102 100644 --- a/bot/cogs/moderation/utils.py +++ b/bot/cogs/moderation/utils.py @@ -70,7 +70,7 @@ async def post_infraction(      log.trace(f"Posting {infr_type} infraction for {user} to the API.")      payload = { -        "actor": ctx.message.author.id, +        "actor": ctx.author.id,  # Don't use ctx.message.author; antispam only patches ctx.author.          "hidden": hidden,          "reason": reason,          "type": infr_type, | 
