From acb59e5d8db52817e654a788ccf4960ee7e60ff4 Mon Sep 17 00:00:00 2001 From: KawaiiYusora Date: Wed, 12 Mar 2025 23:07:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=BC=BA=E5=A4=B1hash?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E7=9A=84=E8=AE=B0=E5=BD=95=20=E6=8A=9B?= =?UTF-8?q?=E5=87=BAFile=20not=20found?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/chat/emoji_manager.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/plugins/chat/emoji_manager.py b/src/plugins/chat/emoji_manager.py index 0933644ec..2fa2a268d 100644 --- a/src/plugins/chat/emoji_manager.py +++ b/src/plugins/chat/emoji_manager.py @@ -346,11 +346,6 @@ class EmojiManager: removed_count += 1 continue - if "hash" not in emoji: - logger.warning(f"发现缺失记录(缺少hash字段),ID: {emoji.get('_id', 'unknown')}") - hash = hashlib.md5(open(emoji["path"], "rb").read()).hexdigest() - db.emoji.update_one({"_id": emoji["_id"]}, {"$set": {"hash": hash}}) - # 检查文件是否存在 if not os.path.exists(emoji["path"]): logger.warning(f"表情包文件已被删除: {emoji['path']}") @@ -361,6 +356,12 @@ class EmojiManager: removed_count += 1 else: logger.error(f"删除数据库记录失败: {emoji['_id']}") + continue + + if "hash" not in emoji: + logger.warning(f"发现缺失记录(缺少hash字段),ID: {emoji.get('_id', 'unknown')}") + hash = hashlib.md5(open(emoji["path"], "rb").read()).hexdigest() + db.emoji.update_one({"_id": emoji["_id"]}, {"$set": {"hash": hash}}) except Exception as item_error: logger.error(f"处理表情包记录时出错: {str(item_error)}") continue