diff options
| author | 2021-12-29 15:08:58 +0000 | |
|---|---|---|
| committer | 2022-01-01 16:18:32 +0000 | |
| commit | 8c46657aefeea118e90ada3ec9a61ba9c4734162 (patch) | |
| tree | 9e8a3f269b6ead9a1d6fbfe8f4347ab94a5784f7 | |
| parent | Include message counts in all channels (#2016) (diff) | |
Incident archive improvements
Diffstat (limited to '')
| -rw-r--r-- | bot/exts/moderation/incidents.py | 22 | 
1 files changed, 16 insertions, 6 deletions
| diff --git a/bot/exts/moderation/incidents.py b/bot/exts/moderation/incidents.py index 77dfad255..bd9e5b88e 100644 --- a/bot/exts/moderation/incidents.py +++ b/bot/exts/moderation/incidents.py @@ -1,6 +1,5 @@  import asyncio  import re -from datetime import datetime  from enum import Enum  from typing import Optional @@ -13,6 +12,7 @@ from bot.constants import Channels, Colours, Emojis, Guild, Roles, Webhooks  from bot.log import get_logger  from bot.utils import scheduling  from bot.utils.messages import format_user, sub_clyde +from bot.utils.time import TimestampFormats, discord_timestamp  log = get_logger(__name__) @@ -25,9 +25,9 @@ CRAWL_LIMIT = 50  CRAWL_SLEEP = 2  DISCORD_MESSAGE_LINK_RE = re.compile( -    r"(https?:\/\/(?:(ptb|canary|www)\.)?discord(?:app)?\.com\/channels\/" +    r"(https?://(?:(ptb|canary|www)\.)?discord(?:app)?\.com/channels/"      r"[0-9]{15,20}" -    r"\/[0-9]{15,20}\/[0-9]{15,20})" +    r"/[0-9]{15,20}/[0-9]{15,20})"  ) @@ -97,9 +97,19 @@ async def make_embed(incident: discord.Message, outcome: Signal, actioned_by: di          colour = Colours.soft_red          footer = f"Rejected by {actioned_by}" +    day_timestamp = discord_timestamp(incident.created_at, TimestampFormats.DATE) +    time_timestamp = discord_timestamp(incident.created_at, TimestampFormats.TIME) +    relative_timestamp = discord_timestamp(incident.created_at, TimestampFormats.RELATIVE) +    reported_on_msg = f"__*Reported {day_timestamp} at {time_timestamp} ({relative_timestamp}).*__" + +    # If the description will be too long (>4096 total characters), truncate the incident content +    if len(incident.content) > (allowed_content_chars := 4096-len(reported_on_msg)-2):  # -2 for the newlines +        description = incident.content[:allowed_content_chars-3] + f"...\n\n{reported_on_msg}" +    else: +        description = incident.content + f"\n\n{reported_on_msg}" +      embed = discord.Embed( -        description=incident.content, -        timestamp=datetime.utcnow(), +        description=description,          colour=colour,      )      embed.set_footer(text=footer, icon_url=actioned_by.display_avatar.url) @@ -380,7 +390,7 @@ class Incidents(Cog):              webhook = await self.bot.fetch_webhook(Webhooks.incidents_archive)              await webhook.send(                  embed=embed, -                username=sub_clyde(incident.author.name), +                username=sub_clyde(incident.author.display_name),                  avatar_url=incident.author.display_avatar.url,                  file=attachment_file,              ) | 
