diff options
author | 2021-04-27 06:27:16 +0530 | |
---|---|---|
committer | 2021-10-11 12:05:39 +0530 | |
commit | 5ce51115f19f7ce13802701dc58d508ab5eb69f8 (patch) | |
tree | 5f2f018b2316245f65b21b438cec64dc1a85c4e6 | |
parent | Handle discord.errors.NotFound while deleting msg link webhook embeds (diff) |
Fix truncation bug
When you take a long message, just one word of 400 A's then the truncated wouldn't be able to handle it properly and just return the placeholder. This is a bug in the textwrap.shorten function.
To solve this, I went the long way to use slicing on the list.
This commit seems to have resolved the bug.
-rw-r--r-- | bot/exts/moderation/incidents.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/bot/exts/moderation/incidents.py b/bot/exts/moderation/incidents.py index 840327cb6..235f7a0f7 100644 --- a/bot/exts/moderation/incidents.py +++ b/bot/exts/moderation/incidents.py @@ -156,15 +156,16 @@ async def make_message_link_embed(ctx: Context, message_link: str) -> t.Optional log.exception(f"Failed to make message link embed for '{message_link}', raised exception: {e}") else: - text = message.content + text = message.content.lstrip() channel = message.channel - + shortened_text = text[:300] + (text[300:] and '...') + embed = discord.Embed( colour=discord.Colour.gold(), description=( f"**Author:** {format_user(message.author)}\n" f"**Channel:** {channel.mention} ({channel.category}/#{channel.name})\n" - f"**Content:** {textwrap.shorten(text.lstrip(), 300, placeholder='...')}\n" + f"**Content:** {shortened_text}\n" ) ) embed.set_footer(text=f"Message ID: {message.id}") |