use avatar urls for backup_migrate also
This commit is contained in:
parent
3863f80232
commit
b2eccf90fd
4 changed files with 23 additions and 4 deletions
|
|
@ -221,7 +221,8 @@ class BackupMember:
|
||||||
|
|
||||||
__slots__ = ("id", "name", "display_name", "bot", "color",
|
__slots__ = ("id", "name", "display_name", "bot", "color",
|
||||||
"roles", "avatar", "guild_permissions", "discriminator",
|
"roles", "avatar", "guild_permissions", "discriminator",
|
||||||
"global_name", "created_at", "joined_at", "status", "activity", "system")
|
"global_name", "created_at", "joined_at", "status", "activity", "system",
|
||||||
|
"_avatar_url")
|
||||||
|
|
||||||
def __init__(self, data: dict, role_objects: list | None = None,
|
def __init__(self, data: dict, role_objects: list | None = None,
|
||||||
avatar_base: Path | None = None):
|
avatar_base: Path | None = None):
|
||||||
|
|
@ -241,6 +242,10 @@ class BackupMember:
|
||||||
self.status = type("Status", (), {"value": "offline"})()
|
self.status = type("Status", (), {"value": "offline"})()
|
||||||
self.activity = None
|
self.activity = None
|
||||||
|
|
||||||
|
# CDN URL from Discord (saved during backup)
|
||||||
|
self._avatar_url = data.get("userAvatarUrl")
|
||||||
|
|
||||||
|
# Local file asset (for reading bytes)
|
||||||
avatar_rel = data.get("userAvatar")
|
avatar_rel = data.get("userAvatar")
|
||||||
if avatar_rel and avatar_base:
|
if avatar_rel and avatar_base:
|
||||||
self.avatar = BackupAsset(avatar_base / avatar_rel)
|
self.avatar = BackupAsset(avatar_base / avatar_rel)
|
||||||
|
|
@ -257,6 +262,11 @@ class BackupMember:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def display_avatar(self) -> BackupAsset:
|
def display_avatar(self) -> BackupAsset:
|
||||||
|
"""Returns an asset with the CDN URL if available, otherwise the local file asset."""
|
||||||
|
if self._avatar_url:
|
||||||
|
asset = BackupAsset(None)
|
||||||
|
asset.url = self._avatar_url
|
||||||
|
return asset
|
||||||
return self.avatar
|
return self.avatar
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
|
|
|
||||||
|
|
@ -523,7 +523,8 @@ class DiscordExporter:
|
||||||
"userColor": str(author.color) if hasattr(author, "color") else None,
|
"userColor": str(author.color) if hasattr(author, "color") else None,
|
||||||
"userIsBot": author.bot,
|
"userIsBot": author.bot,
|
||||||
"userRoles": roles,
|
"userRoles": roles,
|
||||||
"userAvatar": f"user_avatars/{user_id}.png" if author.avatar else None
|
"userAvatar": f"user_avatars/{user_id}.png" if author.avatar else None,
|
||||||
|
"userAvatarUrl": str(author.display_avatar.url) if author.avatar else None
|
||||||
}
|
}
|
||||||
|
|
||||||
reactions = []
|
reactions = []
|
||||||
|
|
|
||||||
|
|
@ -208,10 +208,14 @@ async def migrate_messages(
|
||||||
else:
|
else:
|
||||||
logger.debug(f"Reply target Discord ID {msg.reference.message_id} not found in current session map.")
|
logger.debug(f"Reply target Discord ID {msg.reference.message_id} not found in current session map.")
|
||||||
|
|
||||||
|
avatar_url = str(msg.author.display_avatar.url) if msg.author.display_avatar.url else None
|
||||||
|
if avatar_url and not avatar_url.startswith("http"):
|
||||||
|
avatar_url = None
|
||||||
|
|
||||||
fluxer_msg_id = await context.fluxer_writer.send_message(
|
fluxer_msg_id = await context.fluxer_writer.send_message(
|
||||||
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=avatar_url,
|
||||||
content=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,
|
||||||
|
|
|
||||||
|
|
@ -213,10 +213,14 @@ async def migrate_messages(
|
||||||
else:
|
else:
|
||||||
logger.debug(f"Reply target Discord ID {msg.reference.message_id} not found in current session map.")
|
logger.debug(f"Reply target Discord ID {msg.reference.message_id} not found in current session map.")
|
||||||
|
|
||||||
|
avatar_url = str(msg.author.display_avatar.url) if msg.author.display_avatar.url else None
|
||||||
|
if avatar_url and not avatar_url.startswith("http"):
|
||||||
|
avatar_url = None
|
||||||
|
|
||||||
stoat_msg_id = await context.stoat_writer.send_message(
|
stoat_msg_id = await context.stoat_writer.send_message(
|
||||||
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=avatar_url,
|
||||||
content=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,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue