From 39dfb789e570a3ad6358bcf8788d254be783667b Mon Sep 17 00:00:00 2001 From: rambros Date: Sat, 21 Feb 2026 20:20:22 +0530 Subject: [PATCH] implement forwarded messages --- src/core/engine.py | 28 +++++++++++++++++++++++++--- src/fluxer_bot/writer.py | 21 ++++++++++++++++----- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/core/engine.py b/src/core/engine.py index 97ab85b..be204ce 100644 --- a/src/core/engine.py +++ b/src/core/engine.py @@ -193,7 +193,28 @@ class MigrationEngine: # Process attachments files = [] - for att in msg.attachments: + attachments_to_process = list(msg.attachments) + + # Check if this message is forwarded + # Discord flags: forwarded (is bit 28 / 0x10000000) + is_forwarded = False + if hasattr(msg.flags, 'forwarded'): + is_forwarded = msg.flags.forwarded + + # If forwarded, the content and attachments might be in message_snapshots (discord.py 2.5+) + content = msg.content + if is_forwarded: + logger.debug(f"Detected forwarded message: ID={msg.id}, Flags={msg.flags.value}") + if hasattr(msg, 'message_snapshots') and msg.message_snapshots: + # For now we handle the first snapshot + snapshot = msg.message_snapshots[0] + if not content: + content = snapshot.content + # Add snapshot attachments to the list to process + attachments_to_process.extend(snapshot.attachments) + logger.debug(f"Found forwarded snapshot content: {content[:50]}... and {len(snapshot.attachments)} attachments") + + for att in attachments_to_process: try: att_data = await self.discord_reader.download_attachment(att) files.append({"filename": att.filename, "data": att_data}) @@ -210,10 +231,11 @@ class MigrationEngine: channel_id=target_channel_id, author_name=msg.author.display_name, author_avatar_url=str(msg.author.display_avatar.url), - content=msg.content, + content=content, timestamp=msg.created_at.strftime("%Y-%m-%d %H:%M:%S"), files=files if files else None, - reply_to_message_id=reply_to_fluxer_id + reply_to_message_id=reply_to_fluxer_id, + is_forwarded=is_forwarded ) if fluxer_msg_id: diff --git a/src/fluxer_bot/writer.py b/src/fluxer_bot/writer.py index 559c5f5..37d2908 100644 --- a/src/fluxer_bot/writer.py +++ b/src/fluxer_bot/writer.py @@ -124,7 +124,7 @@ class FluxerWriter: assert self.client is not None return await self.client.get_guild_channels(self.community_id) - async def send_message(self, channel_id: str, author_name: str, content: str, timestamp: str, author_avatar_url: Optional[str] = None, files: Optional[List[Dict[str, Any]]] = None, reply_to_message_id: Optional[str] = None) -> Optional[str]: + async def send_message(self, channel_id: str, author_name: str, content: str, timestamp: str, author_avatar_url: Optional[str] = None, files: Optional[List[Dict[str, Any]]] = None, reply_to_message_id: Optional[str] = None, is_forwarded: bool = False) -> Optional[str]: """ Sends a message to the target channel. Uses a webhook to mimic the original author if possible. @@ -145,7 +145,14 @@ class FluxerWriter: # Prepare content with subtext timestamp # -# is Fluxer/Discord's subtext markdown: small, muted grey text prefix = f"-# {timestamp}\n" - final_content = prefix + content if content else prefix + if is_forwarded: + prefix += "-# -->*forwarded*\n" + + display_content = content + if is_forwarded and content: + display_content = f">>> {content}" + + final_content = prefix + display_content if display_content else prefix try: # Current limitation: fluxer.py execute_webhook doesn't support 'files' or 'message_reference' yet. @@ -161,8 +168,12 @@ class FluxerWriter: else: # Use bot direct message (supports files and message_reference) # We add the author name to the prefix since bot name won't match - bot_prefix = f"-# {timestamp} · {author_name}\n" - bot_content = bot_prefix + content if content else bot_prefix + bot_prefix = f"-# {timestamp}\n" + if is_forwarded: + bot_prefix += "-# -->*forwarded*\n" + bot_prefix += f"-# · {author_name}\n" + + final_bot_content = bot_prefix + display_content if display_content else bot_prefix message_reference = None if reply_to_message_id: @@ -170,7 +181,7 @@ class FluxerWriter: msg_data = await self.client.send_message( channel_id=channel_id, - content=bot_content, + content=final_bot_content, files=files, message_reference=message_reference )