diff options
| -rw-r--r-- | bot/exts/moderation/incidents.py | 74 | 
1 files changed, 53 insertions, 21 deletions
| diff --git a/bot/exts/moderation/incidents.py b/bot/exts/moderation/incidents.py index be6708b83..6a2c8c4b0 100644 --- a/bot/exts/moderation/incidents.py +++ b/bot/exts/moderation/incidents.py @@ -26,9 +26,9 @@ CRAWL_LIMIT = 50  CRAWL_SLEEP = 2  DISCORD_MESSAGE_LINK_RE = re.compile( -    r'(https?:\/\/(?:(ptb|canary|www)\.)?discord(?:app)?\.com\/channels\/' -    r'[0-9]{15,21}' -    r'\/[0-9]{15,21}\/[0-9]{15,21})' +    r"(https?:\/\/(?:(ptb|canary|www)\.)?discord(?:app)?\.com\/channels\/" +    r"[0-9]{15,21}" +    r"\/[0-9]{15,21}\/[0-9]{15,21})"  ) @@ -72,7 +72,11 @@ async def download_file(attachment: discord.Attachment) -> t.Optional[discord.Fi          log.exception("Failed to download attachment") -async def make_embed(incident: discord.Message, outcome: Signal, actioned_by: discord.Member) -> FileEmbed: +async def make_embed( +    incident: discord.Message, +    outcome: Signal, +    actioned_by: discord.Member +) -> FileEmbed:      """      Create an embed representation of `incident` for the #incidents-archive channel. @@ -110,9 +114,13 @@ async def make_embed(incident: discord.Message, outcome: Signal, actioned_by: di          file = await download_file(attachment)          if file is not None: -            embed.set_image(url=f"attachment://{attachment.filename}")  # Embed displays the attached file +            embed.set_image( +                url=f"attachment://{attachment.filename}" +            )  # Embed displays the attached file          else: -            embed.set_author(name="[Failed to relay attachment]", url=attachment.proxy_url)  # Embed links the file +            embed.set_author( +                name="[Failed to relay attachment]", url=attachment.proxy_url +            )  # Embed links the file      else:          file = None @@ -182,7 +190,9 @@ async def add_signals(incident: discord.Message) -> None:      existing_reacts = own_reactions(incident)      for signal_emoji in Signal: -        if signal_emoji.value in existing_reacts:  # This would not raise, but it is a superfluous API call +        if ( +            signal_emoji.value in existing_reacts +        ):  # This would not raise, but it is a superfluous API call              log.trace(f"Skipping emoji as it's already been placed: {signal_emoji}")          else:              log.trace(f"Adding reaction: {signal_emoji}") @@ -270,7 +280,12 @@ class Incidents(Cog):          log.debug("Crawl task finished!") -    async def archive(self, incident: discord.Message, outcome: Signal, actioned_by: discord.Member) -> bool: +    async def archive( +        self, +        incident: discord.Message, +        outcome: Signal, +        actioned_by: discord.Member +    ) -> bool:          """          Relay an embed representation of `incident` to the #incidents-archive channel. @@ -291,7 +306,9 @@ class Incidents(Cog):          not all information was relayed, return False. This signals that the original          message is not safe to be deleted, as we will lose some information.          """ -        log.info(f"Archiving incident: {incident.id} (outcome: {outcome}, actioned by: {actioned_by})") +        log.info( +            f"Archiving incident: {incident.id} (outcome: {outcome}, actioned by: {actioned_by})" +        )          embed, attachment_file = await make_embed(incident, outcome, actioned_by)          try: @@ -316,7 +333,9 @@ class Incidents(Cog):          If `timeout` passes, this will raise `asyncio.TimeoutError`, signaling that we haven't          been able to confirm that the message was deleted.          """ -        log.trace(f"Confirmation task will wait {timeout=} seconds for {incident.id=} to be deleted") +        log.trace( +            f"Confirmation task will wait {timeout=} seconds for {incident.id=} to be deleted" +        )          def check(payload: discord.RawReactionActionEvent) -> bool:              return payload.message_id == incident.id @@ -324,7 +343,12 @@ class Incidents(Cog):          coroutine = self.bot.wait_for(event="raw_message_delete", check=check, timeout=timeout)          return scheduling.create_task(coroutine, event_loop=self.bot.loop) -    async def process_event(self, reaction: str, incident: discord.Message, member: discord.Member) -> None: +    async def process_event( +        self, +        reaction: str, +        incident: discord.Message, +        member: discord.Member +    ) -> None:          """          Process a `reaction_add` event in #incidents. @@ -366,7 +390,9 @@ class Incidents(Cog):          relay_successful = await self.archive(incident, signal, actioned_by=member)          if not relay_successful: -            log.trace("Original message will not be deleted as we failed to relay it to the archive") +            log.trace( +                "Original message will not be deleted as we failed to relay it to the archive" +            )              return          timeout = 5  # Seconds @@ -390,7 +416,7 @@ class Incidents(Cog):          webhook_msg_ids = await self.message_link_embeds_cache.get(incident.id)          if webhook_msg_ids: -            webhook_msg_ids = webhook_msg_ids.split(',') +            webhook_msg_ids = webhook_msg_ids.split(",")              webhook = await self.bot.fetch_webhook(Webhooks.incidents)              for x, msg in enumerate(webhook_msg_ids): @@ -458,7 +484,9 @@ class Incidents(Cog):          if payload.channel_id != Channels.incidents or payload.member.bot:              return -        log.trace(f"Received reaction add event in #incidents, waiting for crawler: {self.crawl_task.done()=}") +        log.trace( +            f"Received reaction add event in #incidents, waiting for crawler: {self.crawl_task.done()=}" +        )          await self.crawl_task          log.trace(f"Acquiring event lock: {self.event_lock.locked()=}") @@ -493,14 +521,16 @@ class Incidents(Cog):                  await self.send_webhooks(webhook_embed_list, message, webhook) -            log.trace(f"Skipping discord message link detection on {message.id}: message doesn't qualify.") +            log.trace( +                f"Skipping discord message link detection on {message.id}: message doesn't qualify." +            )              await add_signals(message)      async def send_webhooks( -            self, -            webhook_embed_list: t.List, -            message: discord.Message, -            webhook: discord.Webhook +        self, +        webhook_embed_list: t.List, +        message: discord.Message, +        webhook: discord.Webhook      ) -> t.List[int]:          """          Send Message Link Embeds to #incidents channel. @@ -518,7 +548,7 @@ class Incidents(Cog):                      embeds=[x for x in embed if x is not None],                      username=sub_clyde(message.author.name),                      avatar_url=message.author.avatar_url, -                    wait=True +                    wait=True,                  )                  webhook_msg_ids.append(webhook_msg.id)                  log.trace(f"Message Link Embed {x + 1}/{len(webhook_embed_list)} Sent Succesfully") @@ -527,7 +557,9 @@ class Incidents(Cog):              log.exception(f"Failed to send message link embeds {message.id} to #incidents")          else: -            await self.message_link_embeds_cache.set(message.id, ','.join(map(str, webhook_msg_ids))) +            await self.message_link_embeds_cache.set( +                message.id, ",".join(map(str, webhook_msg_ids)) +            )              log.trace("Message Link Embeds Sent successfully!")          return webhook_msg_ids | 
