From cd50a15181589aa6d9f4a2e54f54746e8e0845fe Mon Sep 17 00:00:00 2001 From: SengokuCola <1026294844@qq.com> Date: Fri, 4 Apr 2025 00:55:25 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E8=87=AA=E5=8A=A8=E6=B8=85?= =?UTF-8?q?=E7=90=86=E7=BC=93=E5=AD=98=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelogs/changelog_dev.md | 2 ++ src/plugins/chat/emoji_manager.py | 31 +++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/changelogs/changelog_dev.md b/changelogs/changelog_dev.md index e99dc44cd..f945a237d 100644 --- a/changelogs/changelog_dev.md +++ b/changelogs/changelog_dev.md @@ -2,8 +2,10 @@ ## [test-0.6.0-snapshot-8] - 2025-4-3 - 修复了表情包的注册,获取和发送逻辑 +- 表情包增加存储上限 - 更改了回复引用的逻辑,从基于时间改为基于新消息 - 增加了调试信息 +- 自动清理缓存图片 ## [test-0.6.0-snapshot-7] - 2025-4-2 - 修改版本号命名:test-前缀为测试版,无前缀为正式版 diff --git a/src/plugins/chat/emoji_manager.py b/src/plugins/chat/emoji_manager.py index 6c41d9c78..5b3d34ec8 100644 --- a/src/plugins/chat/emoji_manager.py +++ b/src/plugins/chat/emoji_manager.py @@ -535,9 +535,36 @@ class EmojiManager: while True: self.check_emoji_file_full() self.check_emoji_file_integrity() + await self.delete_all_images() await asyncio.sleep(global_config.EMOJI_CHECK_INTERVAL * 60) - + + async def delete_all_images(self): + """删除 data/image 目录下的所有文件""" + try: + image_dir = os.path.join("data", "image") + if not os.path.exists(image_dir): + logger.warning(f"[警告] 目录不存在: {image_dir}") + return + + deleted_count = 0 + failed_count = 0 + + # 遍历目录下的所有文件 + for filename in os.listdir(image_dir): + file_path = os.path.join(image_dir, filename) + try: + if os.path.isfile(file_path): + os.remove(file_path) + deleted_count += 1 + logger.debug(f"[删除] 文件: {file_path}") + except Exception as e: + failed_count += 1 + logger.error(f"[错误] 删除文件失败 {file_path}: {str(e)}") + + logger.success(f"[清理] 已删除 {deleted_count} 个文件,失败 {failed_count} 个") + + except Exception as e: + logger.error(f"[错误] 删除图片目录失败: {str(e)}") # 创建全局单例 - emoji_manager = EmojiManager()