修复emoji

This commit is contained in:
Bakadax
2025-04-29 17:50:20 +08:00
parent 136296d5eb
commit 95828d143d

View File

@@ -360,6 +360,7 @@ class EmojiManager:
return return
total_count = len(self.emoji_objects) total_count = len(self.emoji_objects)
self.emoji_num = total_count
removed_count = 0 removed_count = 0
# 使用列表复制进行遍历,因为我们会在遍历过程中修改列表 # 使用列表复制进行遍历,因为我们会在遍历过程中修改列表
for emoji in self.emoji_objects[:]: for emoji in self.emoji_objects[:]:
@@ -376,10 +377,22 @@ class EmojiManager:
removed_count += 1 removed_count += 1
continue continue
if emoji.description == None:
logger.warning(f"[检查] 表情包文件已被删除: {emoji.path}")
# 执行表情包对象的删除方法
await emoji.delete()
# 从列表中移除该对象
self.emoji_objects.remove(emoji)
# 更新计数
self.emoji_num -= 1
removed_count += 1
continue
except Exception as item_error: except Exception as item_error:
logger.error(f"[错误] 处理表情包记录时出错: {str(item_error)}") logger.error(f"[错误] 处理表情包记录时出错: {str(item_error)}")
continue continue
await self.clean_unused_emojis(EMOJI_REGISTED_DIR, self.emoji_objects)
# 输出清理结果 # 输出清理结果
if removed_count > 0: if removed_count > 0:
logger.success(f"[清理] 已清理 {removed_count} 个失效的表情包记录") logger.success(f"[清理] 已清理 {removed_count} 个失效的表情包记录")
@@ -706,7 +719,7 @@ class EmojiManager:
prompt = f''' prompt = f'''
这是一个表情包,请对这个表情包进行审核,标准如下: 这是一个表情包,请对这个表情包进行审核,标准如下:
1. 必须符合"{global_config.EMOJI_CHECK_PROMPT}"的要求 1. 必须符合"{global_config.EMOJI_CHECK_PROMPT}"的要求
2. 不能是色情、暴力、等违法违规内容,必须符合公序良俗 2. 不能是暴力、等违法违规内容
3. 不能是任何形式的截图,聊天记录或视频截图 3. 不能是任何形式的截图,聊天记录或视频截图
4. 不要出现5个以上文字 4. 不要出现5个以上文字
请回答这个表情包是否满足上述要求,是则回答是,否则回答否,不要出现任何其他内容 请回答这个表情包是否满足上述要求,是则回答是,否则回答否,不要出现任何其他内容
@@ -749,7 +762,7 @@ class EmojiManager:
await new_emoji.initialize_hash_format() await new_emoji.initialize_hash_format()
emoji_base64 = image_path_to_base64(os.path.join(EMOJI_DIR, filename)) emoji_base64 = image_path_to_base64(os.path.join(EMOJI_DIR, filename))
description, emotions = await self.build_emoji_description(emoji_base64) description, emotions = await self.build_emoji_description(emoji_base64)
if description == "": if description == "" or description == None :
return False return False
new_emoji.description = description new_emoji.description = description
new_emoji.emotion = emotions new_emoji.emotion = emotions
@@ -817,6 +830,27 @@ class EmojiManager:
logger.success("[清理] 临时文件清理完成") logger.success("[清理] 临时文件清理完成")
async def clean_unused_emojis(self, emoji_dir, emoji_objects):
"""清理未使用的表情包文件
遍历指定文件夹中的所有文件删除未在emoji_objects列表中的文件
"""
# 获取所有表情包路径
emoji_paths = {emoji.path for emoji in emoji_objects}
# 遍历文件夹中的所有文件
for file_name in os.listdir(emoji_dir):
file_path = os.path.join(emoji_dir, file_name)
# 检查文件是否在表情包路径列表中
if file_path not in emoji_paths:
try:
# 删除未在表情包列表中的文件
os.remove(file_path)
logger.info(f"[清理] 删除未使用的表情包文件: {file_path}")
except Exception as e:
logger.error(f"[错误] 删除文件时出错: {str(e)}")
# 创建全局单例 # 创建全局单例
emoji_manager = EmojiManager() emoji_manager = EmojiManager()