From 78f6476ebd826c339a0a2359ff4ca1359ebeb6ec Mon Sep 17 00:00:00 2001 From: SengokuCola <1026294844@qq.com> Date: Mon, 2 Jun 2025 22:23:11 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E5=81=B7=E8=A1=A8=E6=83=85?= =?UTF-8?q?=E5=8C=85=E9=85=8D=E7=BD=AE=E7=94=9F=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chat/emoji_system/emoji_manager.py | 4 +- src/chat/utils/utils_image.py | 58 +++++++++++++------------- src/config/official_configs.py | 9 ---- template/bot_config_template.toml | 6 +-- 4 files changed, 33 insertions(+), 44 deletions(-) diff --git a/src/chat/emoji_system/emoji_manager.py b/src/chat/emoji_system/emoji_manager.py index df697155f..48a0cea61 100644 --- a/src/chat/emoji_system/emoji_manager.py +++ b/src/chat/emoji_system/emoji_manager.py @@ -602,9 +602,9 @@ class EmojiManager: continue # 检查是否需要处理表情包(数量超过最大值或不足) - if (self.emoji_num > self.emoji_num_max and global_config.emoji.do_replace) or ( + if global_config.emoji.steal_emoji and ((self.emoji_num > self.emoji_num_max and global_config.emoji.do_replace) or ( self.emoji_num < self.emoji_num_max - ): + )): try: # 获取目录下所有图片文件 files_to_process = [ diff --git a/src/chat/utils/utils_image.py b/src/chat/utils/utils_image.py index 9dcd644a9..6d5fdd4f4 100644 --- a/src/chat/utils/utils_image.py +++ b/src/chat/utils/utils_image.py @@ -202,37 +202,37 @@ class ImageManager: logger.debug(f"描述是{description}") # 根据配置决定是否保存图片 - if global_config.emoji.save_pic: - # 生成文件名和路径 - current_timestamp = time.time() - filename = f"{int(current_timestamp)}_{image_hash[:8]}.{image_format}" - image_dir = os.path.join(self.IMAGE_DIR, "image") - os.makedirs(image_dir, exist_ok=True) - file_path = os.path.join(image_dir, filename) + # 生成文件名和路径 + current_timestamp = time.time() + filename = f"{int(current_timestamp)}_{image_hash[:8]}.{image_format}" + image_dir = os.path.join(self.IMAGE_DIR, "image") + os.makedirs(image_dir, exist_ok=True) + file_path = os.path.join(image_dir, filename) + + try: + # 保存文件 + with open(file_path, "wb") as f: + f.write(image_bytes) + + # 保存到数据库 (Images表) try: - # 保存文件 - with open(file_path, "wb") as f: - f.write(image_bytes) - - # 保存到数据库 (Images表) - try: - img_obj = Images.get((Images.emoji_hash == image_hash) & (Images.type == "image")) - img_obj.path = file_path - img_obj.description = description - img_obj.timestamp = current_timestamp - img_obj.save() - except Images.DoesNotExist: - Images.create( - emoji_hash=image_hash, - path=file_path, - type="image", - description=description, - timestamp=current_timestamp, - ) - logger.trace(f"保存图片元数据: {file_path}") - except Exception as e: - logger.error(f"保存图片文件或元数据失败: {str(e)}") + img_obj = Images.get((Images.emoji_hash == image_hash) & (Images.type == "image")) + img_obj.path = file_path + img_obj.description = description + img_obj.timestamp = current_timestamp + img_obj.save() + except Images.DoesNotExist: + Images.create( + emoji_hash=image_hash, + path=file_path, + type="image", + description=description, + timestamp=current_timestamp, + ) + logger.trace(f"保存图片元数据: {file_path}") + except Exception as e: + logger.error(f"保存图片文件或元数据失败: {str(e)}") # 保存描述到数据库 (ImageDescriptions表) self._save_description_to_db(image_hash, description, "image") diff --git a/src/config/official_configs.py b/src/config/official_configs.py index 8ae3fe985..fe59ef7b9 100644 --- a/src/config/official_configs.py +++ b/src/config/official_configs.py @@ -205,15 +205,6 @@ class EmojiConfig(ConfigBase): check_interval: int = 120 """表情包检查间隔(分钟)""" - save_pic: bool = True - """是否保存图片""" - - save_emoji: bool = True - """是否保存表情包""" - - cache_emoji: bool = True - """是否缓存表情包""" - steal_emoji: bool = True """是否偷取表情包,让麦麦可以发送她保存的这些表情包""" diff --git a/template/bot_config_template.toml b/template/bot_config_template.toml index 9d69827c4..14db89843 100644 --- a/template/bot_config_template.toml +++ b/template/bot_config_template.toml @@ -1,5 +1,5 @@ [inner] -version = "2.9.1" +version = "2.10.0" #----以下是给开发人员阅读的,如果你只是部署了麦麦,不需要阅读---- #如果你想要修改配置文件,请在修改后将version的值进行变更 @@ -114,9 +114,7 @@ working_memory_processor = false # 是否启用工作记忆处理器,不稳定 max_reg_num = 40 # 表情包最大注册数量 do_replace = true # 开启则在达到最大数量时删除(替换)表情包,关闭则达到最大数量时不会继续收集表情包 check_interval = 120 # 检查表情包(注册,破损,删除)的时间间隔(分钟) -save_pic = true # 是否保存图片 -cache_emoji = true # 是否缓存表情包 -steal_emoji = true # 是否偷取表情包,让麦麦可以发送她保存的这些表情包 +steal_emoji = true # 是否偷取表情包,让麦麦可以将一些表情包据为己有 content_filtration = false # 是否启用表情包过滤,只有符合该要求的表情包才会被保存 filtration_prompt = "符合公序良俗" # 表情包过滤要求,只有符合该要求的表情包才会被保存