fix custom emojis in migrated messages
This commit is contained in:
parent
9f3a5c65fb
commit
9a60759b7c
3 changed files with 52 additions and 8 deletions
|
|
@ -7,7 +7,7 @@ from src.core.base import MigrationContext
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def clean_mentions(content: str, guild, user_mentions=None, role_mentions=None, role_map=None) -> str:
|
||||
def clean_mentions(content: str, guild, user_mentions=None, role_mentions=None, role_map=None, emoji_map=None) -> str:
|
||||
if not content or not guild:
|
||||
return content
|
||||
|
||||
|
|
@ -57,9 +57,22 @@ def clean_mentions(content: str, guild, user_mentions=None, role_mentions=None,
|
|||
channel = guild.get_channel(cid)
|
||||
return f"#{channel.name}" if channel else match.group(0)
|
||||
|
||||
def replace_emoji(match):
|
||||
animated = match.group(1) == "a"
|
||||
name = match.group(2)
|
||||
eid = match.group(3)
|
||||
|
||||
if emoji_map and eid in emoji_map:
|
||||
target_eid = emoji_map[eid]
|
||||
prefix = "a" if animated else ""
|
||||
return f"<{prefix}:{name}:{target_eid}>"
|
||||
|
||||
return f":{name}:"
|
||||
|
||||
content = re.sub(r'<@!?([0-9]+)>', replace_user, content)
|
||||
content = re.sub(r'<@&([0-9]+)>', replace_role, content)
|
||||
content = re.sub(r'<#([0-9]+)>', replace_channel, content)
|
||||
content = re.sub(r'<(a?):([^:]+):([0-9]+)>', replace_emoji, content)
|
||||
content = content.replace("@everyone", "`@everyone`").replace("@here", "`@here`")
|
||||
return content
|
||||
|
||||
|
|
@ -160,7 +173,15 @@ async def migrate_messages(
|
|||
continue
|
||||
else:
|
||||
# Use custom clean_mentions with msg mentions for accuracy
|
||||
content = clean_mentions(msg.content, msg.guild, msg.mentions, msg.role_mentions, context.discord_reader.role_map)
|
||||
# Use custom clean_mentions with msg mentions for accuracy
|
||||
content = clean_mentions(
|
||||
msg.content,
|
||||
msg.guild,
|
||||
msg.mentions,
|
||||
msg.role_mentions,
|
||||
context.discord_reader.role_map,
|
||||
context.state.emoji_map
|
||||
)
|
||||
|
||||
# Process attachments
|
||||
files = []
|
||||
|
|
@ -187,7 +208,8 @@ async def migrate_messages(
|
|||
msg.guild,
|
||||
snapshot.mentions if hasattr(snapshot, 'mentions') else None,
|
||||
snapshot.role_mentions if hasattr(snapshot, 'role_mentions') else None,
|
||||
context.discord_reader.role_map
|
||||
context.discord_reader.role_map,
|
||||
context.state.emoji_map
|
||||
)
|
||||
# Add snapshot attachments to the list to process
|
||||
attachments_to_process.extend(snapshot.attachments)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ from src.core.base import MigrationContext
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def clean_mentions(content: str, guild, user_mentions=None, role_mentions=None, role_map=None) -> str:
|
||||
def clean_mentions(content: str, guild, user_mentions=None, role_mentions=None, role_map=None, emoji_map=None) -> str:
|
||||
if not content or not guild:
|
||||
return content
|
||||
|
||||
|
|
@ -57,9 +57,22 @@ def clean_mentions(content: str, guild, user_mentions=None, role_mentions=None,
|
|||
channel = guild.get_channel(cid)
|
||||
return f"#{channel.name}" if channel else match.group(0)
|
||||
|
||||
def replace_emoji(match):
|
||||
animated = match.group(1) == "a"
|
||||
name = match.group(2)
|
||||
eid = match.group(3)
|
||||
|
||||
if emoji_map and eid in emoji_map:
|
||||
target_eid = emoji_map[eid]
|
||||
prefix = "a" if animated else ""
|
||||
#return f"<{prefix}:{name}:{target_eid}>" name not require for stoat
|
||||
return f":{target_eid}:"
|
||||
return f":{name}:"
|
||||
|
||||
content = re.sub(r'<@!?([0-9]+)>', replace_user, content)
|
||||
content = re.sub(r'<@&([0-9]+)>', replace_role, content)
|
||||
content = re.sub(r'<#([0-9]+)>', replace_channel, content)
|
||||
content = re.sub(r'<(a?):([^:]+):([0-9]+)>', replace_emoji, content)
|
||||
content = content.replace("@everyone", "`@everyone`").replace("@here", "`@here`")
|
||||
return content
|
||||
|
||||
|
|
@ -168,7 +181,15 @@ async def migrate_messages(
|
|||
continue
|
||||
else:
|
||||
# Use custom clean_mentions with msg mentions for accuracy
|
||||
content = clean_mentions(msg.content, msg.guild, msg.mentions, msg.role_mentions, context.discord_reader.role_map)
|
||||
# Use custom clean_mentions with msg mentions for accuracy
|
||||
content = clean_mentions(
|
||||
msg.content,
|
||||
msg.guild,
|
||||
msg.mentions,
|
||||
msg.role_mentions,
|
||||
context.discord_reader.role_map,
|
||||
context.state.emoji_map
|
||||
)
|
||||
|
||||
# Process attachments
|
||||
files = []
|
||||
|
|
@ -191,7 +212,8 @@ async def migrate_messages(
|
|||
msg.guild,
|
||||
snapshot.mentions if hasattr(snapshot, 'mentions') else None,
|
||||
snapshot.role_mentions if hasattr(snapshot, 'role_mentions') else None,
|
||||
context.discord_reader.role_map
|
||||
context.discord_reader.role_map,
|
||||
context.state.emoji_map
|
||||
)
|
||||
attachments_to_process.extend(snapshot.attachments)
|
||||
logger.debug(f"Found forwarded snapshot content: {content[:50]}... and {len(snapshot.attachments)} attachments")
|
||||
|
|
|
|||
|
|
@ -798,7 +798,7 @@ class ShuttlePane(Container):
|
|||
modal.set_status(f"Fetching {platform_name} channels...")
|
||||
|
||||
full_f = await self.engine.writer.get_channels()
|
||||
f_channels = [c for c in full_f if c.get("name") not in ["reaper_logs", "ReaperFiles-logs"] and c.get("type") not in [2, 4]]
|
||||
f_channels = [c for c in full_f if str(c.get("name")).lower() not in ["reaper-logs", "reaper_logs", "reaperfiles-logs"] and c.get("type") not in [2, 4]]
|
||||
|
||||
if not f_channels:
|
||||
modal.write(f"[yellow]No channels found in {platform_name} community.[/yellow]")
|
||||
|
|
@ -1145,7 +1145,7 @@ class ShuttlePane(Container):
|
|||
try:
|
||||
if "dz_del_channels" in selections or "dz_reset_perms" in selections:
|
||||
channels_raw = await writer.get_channels()
|
||||
protected = ["ReaperFiles-logs", "reaper_logs"]
|
||||
protected = ["reaperfiles-logs", "reaper_logs", "reaper-logs"]
|
||||
channel_names = [
|
||||
c.get("name", "Unknown") for c in channels_raw
|
||||
if c.get("type") != 4 and str(c.get("name", "")).lower() not in protected
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue