fix sticker local_hash error
This commit is contained in:
parent
73d52d2183
commit
514a2e551c
3 changed files with 17 additions and 9 deletions
|
|
@ -530,12 +530,13 @@ class BackupEmoji:
|
|||
class BackupSticker:
|
||||
"""Minimal stand-in for discord.GuildSticker."""
|
||||
|
||||
__slots__ = ("id", "name", "url", "format", "_backup_root", "_file_path")
|
||||
__slots__ = ("id", "name", "url", "format", "_backup_root", "_file_path", "local_hash")
|
||||
|
||||
def __init__(self, data: dict, backup_root: Path | None = None, media_pool: dict | None = None):
|
||||
if not isinstance(data, dict):
|
||||
self.id = 0
|
||||
self.name = "Sticker"
|
||||
self.local_hash = None
|
||||
return
|
||||
self.id = parse_snowflake(data.get("id") or data.get("sticker_id", 0)) or 0
|
||||
self.name = data.get("name", "Sticker")
|
||||
|
|
@ -550,14 +551,14 @@ class BackupSticker:
|
|||
self._backup_root = backup_root
|
||||
|
||||
# 1. Check if it's a CAS-based sticker (from message_stickers table)
|
||||
local_hash = data.get("local_hash")
|
||||
if local_hash and backup_root:
|
||||
self.local_hash = data.get("local_hash")
|
||||
if self.local_hash and backup_root:
|
||||
ext = ".png"
|
||||
if self.format == StickerFormatType.lottie: ext = ".json"
|
||||
elif self.format == StickerFormatType.apng: ext = ".png"
|
||||
elif self.format == StickerFormatType.gif: ext = ".gif"
|
||||
|
||||
self._file_path = backup_root / "attachments" / f"{local_hash}{ext}"
|
||||
self._file_path = backup_root / "attachments" / f"{self.local_hash}{ext}"
|
||||
# 2. Check if it's a server asset sticker (legacy or manual save)
|
||||
elif data.get("filename") and backup_root:
|
||||
self._file_path = backup_root / "server_assets" / data["filename"]
|
||||
|
|
|
|||
|
|
@ -842,7 +842,7 @@ async def migrate_global_messages(
|
|||
sticker_url = sticker.url
|
||||
|
||||
# Check for uploaded media pool logic first
|
||||
s_hash = sticker.local_hash
|
||||
s_hash = getattr(sticker, "local_hash", None)
|
||||
sticker_file = None
|
||||
s_media = db_media.get(s_hash) if db_media and s_hash else None
|
||||
if s_media:
|
||||
|
|
|
|||
|
|
@ -826,8 +826,8 @@ async def migrate_global_messages(
|
|||
content = msg.content or ""
|
||||
|
||||
for sticker in msg.stickers:
|
||||
sticker_name = sticker.name
|
||||
s_hash = sticker.local_hash
|
||||
sticker_name = getattr(sticker, "name", "unknown")
|
||||
s_hash = getattr(sticker, "local_hash", None)
|
||||
sticker_file = None
|
||||
s_media = db_media.get(s_hash) if db_media and s_hash else None
|
||||
if s_media:
|
||||
|
|
@ -837,8 +837,15 @@ async def migrate_global_messages(
|
|||
|
||||
content += f"\n[Sticker: {sticker_name}]"
|
||||
if sticker_file:
|
||||
files.append(sticker_file)
|
||||
file_names.append(f"sticker_{sticker_name}.png")
|
||||
try:
|
||||
with open(sticker_file, "rb") as f:
|
||||
files.append({
|
||||
"filename": f"sticker_{sticker_name}.png",
|
||||
"data": f.read(),
|
||||
"content_type": "image/png"
|
||||
})
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to read sticker file {sticker_file}: {e}")
|
||||
|
||||
content = clean_mentions(
|
||||
content=content,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue