From 6dec487d58c936be9f224b2b2b2e871cc67f34d2 Mon Sep 17 00:00:00 2001 From: Sebastiaan Zeeff <33516116+SebastiaanZ@users.noreply.github.com> Date: Sat, 14 Sep 2019 20:17:43 +0200 Subject: 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. --- bot/cogs/modlog.py | 13 ++++++++----- 1 file 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", -- cgit v1.2.3