diff options
| author | 2019-01-11 07:38:08 +0100 | |
|---|---|---|
| committer | 2019-01-11 07:38:08 +0100 | |
| commit | 163fb3fed0cf8a802f71f747900ded091d60c2dc (patch) | |
| tree | 0b322d39707a454231a27c45dd81c76f2c4acb33 | |
| parent | Merge pull request #259 from python-discord/SebastiaanZ/embed-detection-filter (diff) | |
| parent | Merge branch 'master' into antispam-mute-infr (diff) | |
Merge pull request #232 from python-discord/antispam-mute-infr
Utilizes a temporary mute infraction rather than having the mute be totally contained by the AntiSpam coro, preventing non-administrators from removing the muted role in the event of a false-positive.
| -rw-r--r-- | bot/cogs/antispam.py | 35 | ||||
| -rw-r--r-- | bot/cogs/modlog.py | 5 | 
2 files changed, 9 insertions, 31 deletions
diff --git a/bot/cogs/antispam.py b/bot/cogs/antispam.py index d5b72718c..800700a50 100644 --- a/bot/cogs/antispam.py +++ b/bot/cogs/antispam.py @@ -1,21 +1,18 @@ -import asyncio  import logging -import textwrap  from datetime import datetime, timedelta  from typing import List -from dateutil.relativedelta import relativedelta  from discord import Colour, Member, Message, Object, TextChannel  from discord.ext.commands import Bot  from bot import rules +from bot.cogs.moderation import Moderation  from bot.cogs.modlog import ModLog  from bot.constants import (      AntiSpam as AntiSpamConfig, Channels,      Colours, DEBUG_MODE, Event,      Guild as GuildConfig, Icons, Roles,  ) -from bot.utils.time import humanize_delta  log = logging.getLogger(__name__) @@ -44,7 +41,7 @@ WHITELISTED_ROLES = (Roles.owner, Roles.admin, Roles.moderator, Roles.helpers)  class AntiSpam:      def __init__(self, bot: Bot):          self.bot = bot -        self.muted_role = None +        self._muted_role = Object(Roles.muted)      @property      def mod_log(self) -> ModLog: @@ -110,8 +107,6 @@ class AntiSpam:          # Sanity check to ensure we're not lagging behind          if self.muted_role not in member.roles:              remove_role_after = AntiSpamConfig.punishment['remove_after'] -            duration_delta = relativedelta(seconds=remove_role_after) -            human_duration = humanize_delta(duration_delta)              mod_alert_message = (                  f"**Triggered by:** {member.display_name}#{member.discriminator} (`{member.id}`)\n" @@ -133,7 +128,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_ctx = await self.mod_log.send_log_message(                  icon_url=Icons.filtering,                  colour=Colour(Colours.soft_red),                  title=f"Spam detected!", @@ -143,27 +139,8 @@ class AntiSpam:                  ping_everyone=AntiSpamConfig.ping_everyone              ) -            await member.add_roles(self.muted_role, reason=reason) -            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}." -            ) +            # Run a tempmute +            await mod_log_ctx.invoke(Moderation.tempmute, member, f"{remove_role_after}S", reason=reason)      async def maybe_delete_messages(self, channel: TextChannel, messages: List[Message]):          # Is deletion of offending messages actually enabled? diff --git a/bot/cogs/modlog.py b/bot/cogs/modlog.py index c96838a54..06f81cb36 100644 --- a/bot/cogs/modlog.py +++ b/bot/cogs/modlog.py @@ -126,14 +126,15 @@ class ModLog:                  content = "@everyone"          channel = self.bot.get_channel(channel_id) - -        await channel.send(content=content, embed=embed, files=files) +        log_message = await channel.send(content=content, embed=embed, files=files)          if additional_embeds:              await channel.send("With the following embed(s):")              for additional_embed in additional_embeds:                  await channel.send(embed=additional_embed) +        return await self.bot.get_context(log_message)  # Optionally return for use with antispam +      async def on_guild_channel_create(self, channel: GUILD_CHANNEL):          if channel.guild.id != GuildConstant.id:              return  |