implement forwarded messages
This commit is contained in:
parent
7442f3c0a0
commit
39dfb789e5
2 changed files with 41 additions and 8 deletions
|
|
@ -193,7 +193,28 @@ class MigrationEngine:
|
||||||
|
|
||||||
# Process attachments
|
# Process attachments
|
||||||
files = []
|
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:
|
try:
|
||||||
att_data = await self.discord_reader.download_attachment(att)
|
att_data = await self.discord_reader.download_attachment(att)
|
||||||
files.append({"filename": att.filename, "data": att_data})
|
files.append({"filename": att.filename, "data": att_data})
|
||||||
|
|
@ -210,10 +231,11 @@ class MigrationEngine:
|
||||||
channel_id=target_channel_id,
|
channel_id=target_channel_id,
|
||||||
author_name=msg.author.display_name,
|
author_name=msg.author.display_name,
|
||||||
author_avatar_url=str(msg.author.display_avatar.url),
|
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"),
|
timestamp=msg.created_at.strftime("%Y-%m-%d %H:%M:%S"),
|
||||||
files=files if files else None,
|
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:
|
if fluxer_msg_id:
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ class FluxerWriter:
|
||||||
assert self.client is not None
|
assert self.client is not None
|
||||||
return await self.client.get_guild_channels(self.community_id)
|
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.
|
Sends a message to the target channel.
|
||||||
Uses a webhook to mimic the original author if possible.
|
Uses a webhook to mimic the original author if possible.
|
||||||
|
|
@ -145,7 +145,14 @@ class FluxerWriter:
|
||||||
# Prepare content with subtext timestamp
|
# Prepare content with subtext timestamp
|
||||||
# -# is Fluxer/Discord's subtext markdown: small, muted grey text
|
# -# is Fluxer/Discord's subtext markdown: small, muted grey text
|
||||||
prefix = f"-# {timestamp}\n"
|
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:
|
try:
|
||||||
# Current limitation: fluxer.py execute_webhook doesn't support 'files' or 'message_reference' yet.
|
# Current limitation: fluxer.py execute_webhook doesn't support 'files' or 'message_reference' yet.
|
||||||
|
|
@ -161,8 +168,12 @@ class FluxerWriter:
|
||||||
else:
|
else:
|
||||||
# Use bot direct message (supports files and message_reference)
|
# Use bot direct message (supports files and message_reference)
|
||||||
# We add the author name to the prefix since bot name won't match
|
# We add the author name to the prefix since bot name won't match
|
||||||
bot_prefix = f"-# {timestamp} · {author_name}\n"
|
bot_prefix = f"-# {timestamp}\n"
|
||||||
bot_content = bot_prefix + content if content else bot_prefix
|
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
|
message_reference = None
|
||||||
if reply_to_message_id:
|
if reply_to_message_id:
|
||||||
|
|
@ -170,7 +181,7 @@ class FluxerWriter:
|
||||||
|
|
||||||
msg_data = await self.client.send_message(
|
msg_data = await self.client.send_message(
|
||||||
channel_id=channel_id,
|
channel_id=channel_id,
|
||||||
content=bot_content,
|
content=final_bot_content,
|
||||||
files=files,
|
files=files,
|
||||||
message_reference=message_reference
|
message_reference=message_reference
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue