Skip to content

Commit b0e03b0

Browse files
authored
fix: show forwarded message in logviewer.
Signed-off-by: lorenzo132 <[email protected]>
1 parent 09069ff commit b0e03b0

File tree

1 file changed

+43
-33
lines changed

1 file changed

+43
-33
lines changed

core/utils.py

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -658,39 +658,49 @@ def extract_forwarded_content(message) -> typing.Optional[str]:
658658

659659
try:
660660
# Handle multi-forward (message_snapshots)
661-
if hasattr(message, "flags") and getattr(message.flags, "has_snapshot", False):
662-
if hasattr(message, "message_snapshots") and message.message_snapshots:
663-
forwarded_parts = []
664-
for snap in message.message_snapshots:
665-
author = getattr(snap, "author", None)
666-
author_name = getattr(author, "name", "Unknown") if author else "Unknown"
667-
snap_content = getattr(snap, "content", "")
668-
669-
if snap_content:
670-
# Truncate very long messages to prevent spam
671-
if len(snap_content) > 500:
672-
snap_content = snap_content[:497] + "..."
673-
forwarded_parts.append(f"**{author_name}:** {snap_content}")
674-
elif getattr(snap, "embeds", None):
675-
for embed in snap.embeds:
676-
if hasattr(embed, "description") and embed.description:
677-
embed_desc = embed.description
678-
if len(embed_desc) > 300:
679-
embed_desc = embed_desc[:297] + "..."
680-
forwarded_parts.append(f"**{author_name}:** {embed_desc}")
681-
break
682-
elif getattr(snap, "attachments", None):
683-
attachment_info = ", ".join(
684-
[getattr(a, "filename", "Unknown") for a in snap.attachments[:3]]
685-
)
686-
if len(snap.attachments) > 3:
687-
attachment_info += f" (+{len(snap.attachments) - 3} more)"
688-
forwarded_parts.append(f"**{author_name}:** [Attachments: {attachment_info}]")
689-
else:
690-
forwarded_parts.append(f"**{author_name}:** [No content]")
691-
692-
if forwarded_parts:
693-
return "\n".join(forwarded_parts)
661+
# Check directly for snapshots as flags.has_snapshot can be unreliable in some versions
662+
if getattr(message, "message_snapshots", None):
663+
forwarded_parts = []
664+
for snap in message.message_snapshots:
665+
author = getattr(snap, "author", None)
666+
# If author is missing, we can try to rely on the container message context or just omit.
667+
# Since we can't reliably get the original author from snapshot in this state, we focus on content.
668+
669+
snap_content = getattr(snap, "content", "")
670+
671+
formatted_part = "📨 **Forwarded Message**\n"
672+
673+
if snap_content:
674+
if len(snap_content) > 500:
675+
snap_content = snap_content[:497] + "..."
676+
formatted_part += "\n".join([f"{line}" for line in snap_content.splitlines()]) + "\n"
677+
678+
if getattr(snap, "embeds", None):
679+
for embed in snap.embeds:
680+
if hasattr(embed, "description") and embed.description:
681+
embed_desc = embed.description
682+
if len(embed_desc) > 300:
683+
embed_desc = embed_desc[:297] + "..."
684+
formatted_part += (
685+
"\n".join([f"> {line}" for line in embed_desc.splitlines()]) + "\n"
686+
)
687+
break # One embed preview is usually enough
688+
689+
if getattr(snap, "attachments", None):
690+
attachment_info = ", ".join(
691+
[getattr(a, "filename", "Unknown") for a in snap.attachments[:3]]
692+
)
693+
if len(snap.attachments) > 3:
694+
attachment_info += f" (+{len(snap.attachments) - 3} more)"
695+
formatted_part += f"[Attachments: {attachment_info}]\n"
696+
697+
# Add source link to the container message since snapshot doesn't have its own public link
698+
formatted_part += f"\n**Source:** {message.jump_url}"
699+
700+
forwarded_parts.append(formatted_part)
701+
702+
if forwarded_parts:
703+
return "\n".join(forwarded_parts)
694704

695705
# Handle single-message forward
696706
elif getattr(message, "type", None) == getattr(discord.MessageType, "forward", None):

0 commit comments

Comments
 (0)