diff options
author | 2019-09-14 20:17:43 +0200 | |
---|---|---|
committer | 2019-09-14 20:22:32 +0200 | |
commit | 6dec487d58c936be9f224b2b2b2e871cc67f34d2 (patch) | |
tree | fc262661da6fee03725fd5c5ee1a60c00c79ad29 | |
parent | Fix tag command invocation in aliases (diff) |
Improve handling of long deleted messsages
The `modlog` cog failed on long messages with attachments, since the
inclusion of attachment metadata would bring the length of the embed
description to go over the character limit of 2048.
To fix this, I moved the addition of the attachment metadata to earlier
in the code so it is taken into account for the character limit.
In addition to this, I changed the truncation behavior. Instead of just
truncating the message if it's too long, we now truncate and upload the
full message to the `deleted messages` endpoint so the full message is
still available. A link to the log will be included in the message-log
embed.
-rw-r--r-- | bot/cogs/modlog.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/bot/cogs/modlog.py b/bot/cogs/modlog.py index 9f0c88424..808ba667b 100644 --- a/bot/cogs/modlog.py +++ b/bot/cogs/modlog.py @@ -528,19 +528,22 @@ class ModLog: "\n" ) + if message.attachments: + # Prepend the message metadata with the number of attachments + response = f"**Attachments:** {len(message.attachments)}\n" + response + # Shorten the message content if necessary content = message.clean_content remaining_chars = 2040 - len(response) if len(content) > remaining_chars: - content = content[:remaining_chars] + "..." + botlog_url = await self.upload_log(messages=[message], actor_id=message.author.id) + ending = f"\n\nMessage truncated, [full message here]({botlog_url})." + truncation_point = remaining_chars - len(ending) + content = f"{content[:truncation_point]}...{ending}" response += f"{content}" - if message.attachments: - # Prepend the message metadata with the number of attachments - response = f"**Attachments:** {len(message.attachments)}\n" + response - await self.send_log_message( Icons.message_delete, Colours.soft_red, "Message deleted", |