diff options
| author | 2018-12-29 13:58:03 -0500 | |
|---|---|---|
| committer | 2018-12-29 13:58:03 -0500 | |
| commit | 9698cf42a22e0637c1afc21dbf3c8282829ccff0 (patch) | |
| tree | f6e758b7910e403caa8a80614f70c69f632109de | |
| parent | Add optional return to modlog post coro (diff) | |
Add infraction posting for AntiSpam mutes
| -rw-r--r-- | bot/cogs/antispam.py | 28 | 
1 files changed, 16 insertions, 12 deletions
diff --git a/bot/cogs/antispam.py b/bot/cogs/antispam.py index d5b72718c..052fd48b2 100644 --- a/bot/cogs/antispam.py +++ b/bot/cogs/antispam.py @@ -15,6 +15,7 @@ from bot.constants import (      Colours, DEBUG_MODE, Event,      Guild as GuildConfig, Icons, Roles,  ) +from bot.utils.moderation import post_infraction  from bot.utils.time import humanize_delta @@ -133,7 +134,8 @@ class AntiSpam:                  mod_alert_message += f"{content}" -            await self.mod_log.send_log_message( +            # Return the mod log message Context that we can use to post the infraction +            mod_log_message = await self.mod_log.send_log_message(                  icon_url=Icons.filtering,                  colour=Colour(Colours.soft_red),                  title=f"Spam detected!", @@ -143,28 +145,30 @@ class AntiSpam:                  ping_everyone=AntiSpamConfig.ping_everyone              ) -            await member.add_roles(self.muted_role, reason=reason) +            # Post AntiSpam mute as a regular infraction so it can be reversed +            ctx = await self.bot.get_context(mod_log_message) +            response_object = await post_infraction(ctx, member, type="mute", reason=reason, duration=remove_role_after) +            if response_object is None: +                return  # Appropriate error(s) are already raised by post_infraction + +            self.mod_log.ignore(Event.member_update, member.id) +            await member.add_roles(self._muted_role, reason=reason) + +            loop = asyncio.get_event_loop() +            infraction_object = response_object["infraction"] +            self.schedule_task(loop, infraction_object["id"], infraction_object) +              description = textwrap.dedent(f"""                  **Channel**: {msg.channel.mention}                  **User**: {msg.author.mention} (`{msg.author.id}`)                  **Reason**: {reason}                  Role will be removed after {human_duration}.              """) -              await self.mod_log.send_log_message(                  icon_url=Icons.user_mute, colour=Colour(Colours.soft_red),                  title="User muted", text=description              ) -            await asyncio.sleep(remove_role_after) -            await member.remove_roles(self.muted_role, reason="AntiSpam mute expired") - -            await self.mod_log.send_log_message( -                icon_url=Icons.user_mute, colour=Colour(Colours.soft_green), -                title="User unmuted", -                text=f"Was muted by `AntiSpam` cog for {human_duration}." -            ) -      async def maybe_delete_messages(self, channel: TextChannel, messages: List[Message]):          # Is deletion of offending messages actually enabled?          if AntiSpamConfig.clean_offending:  |