diff --git a/src/chat/focus_chat/planners/action_manager.py b/src/chat/focus_chat/planners/action_manager.py index dc5343733..fc6f567e2 100644 --- a/src/chat/focus_chat/planners/action_manager.py +++ b/src/chat/focus_chat/planners/action_manager.py @@ -135,11 +135,11 @@ class ActionManager: cycle_timers: dict, thinking_id: str, observations: List[Observation], - expressor: DefaultExpressor, - replyer: DefaultReplyer, chat_stream: ChatStream, log_prefix: str, shutting_down: bool = False, + expressor: DefaultExpressor = None, + replyer: DefaultReplyer = None, ) -> Optional[BaseAction]: """ 创建动作处理器实例 diff --git a/src/chat/focus_chat/planners/actions/plugin_action.py b/src/chat/focus_chat/planners/actions/plugin_action.py index b450e9bb4..f68aa5834 100644 --- a/src/chat/focus_chat/planners/actions/plugin_action.py +++ b/src/chat/focus_chat/planners/actions/plugin_action.py @@ -182,26 +182,33 @@ class PluginAction(BaseAction): Returns: bool: 是否发送成功 """ - try: - expressor = self._services.get("expressor") - chat_stream = self._services.get("chat_stream") + expressor = self._services.get("expressor") + chat_stream = self._services.get("chat_stream") - if not expressor or not chat_stream: - logger.error(f"{self.log_prefix} 无法发送消息:缺少必要的内部服务") - return False + if not expressor or not chat_stream: + logger.error(f"{self.log_prefix} 无法发送消息:缺少必要的内部服务") + return False - # 构造简化的动作数据 - reply_data = {"text": text, "target": target or "", "emojis": []} + # 构造简化的动作数据 + reply_data = {"text": text, "target": target or "", "emojis": []} - # 获取锚定消息(如果有) - observations = self._services.get("observations", []) + # 获取锚定消息(如果有) + observations = self._services.get("observations", []) + + # 查找 ChattingObservation 实例 + chatting_observation = None + for obs in observations: + if isinstance(obs, ChattingObservation): + chatting_observation = obs + break - chatting_observation: ChattingObservation = next( - obs for obs in observations if isinstance(obs, ChattingObservation) + if not chatting_observation: + logger.warning(f"{self.log_prefix} 未找到 ChattingObservation 实例,创建占位符") + anchor_message = await create_empty_anchor_message( + chat_stream.platform, chat_stream.group_info, chat_stream ) + else: anchor_message = chatting_observation.search_message_by_text(reply_data["target"]) - - # 如果没有找到锚点消息,创建一个占位符 if not anchor_message: logger.info(f"{self.log_prefix} 未找到锚点消息,创建占位符") anchor_message = await create_empty_anchor_message( @@ -210,19 +217,16 @@ class PluginAction(BaseAction): else: anchor_message.update_chat_stream(chat_stream) - # 调用内部方法发送消息 - success, _ = await expressor.deal_reply( - cycle_timers=self.cycle_timers, - action_data=reply_data, - anchor_message=anchor_message, - reasoning=self.reasoning, - thinking_id=self.thinking_id, - ) + # 调用内部方法发送消息 + success, _ = await expressor.deal_reply( + cycle_timers=self.cycle_timers, + action_data=reply_data, + anchor_message=anchor_message, + reasoning=self.reasoning, + thinking_id=self.thinking_id, + ) - return success - except Exception as e: - logger.error(f"{self.log_prefix} 发送消息时出错: {e}") - return False + return success def get_chat_type(self) -> str: """获取当前聊天类型 diff --git a/src/chat/normal_chat/normal_chat.py b/src/chat/normal_chat/normal_chat.py index 840672a1c..c88c70ddb 100644 --- a/src/chat/normal_chat/normal_chat.py +++ b/src/chat/normal_chat/normal_chat.py @@ -24,6 +24,7 @@ from src.chat.focus_chat.planners.action_manager import ActionManager from src.chat.normal_chat.normal_chat_planner import NormalChatPlanner from src.chat.normal_chat.normal_chat_action_modifier import NormalChatActionModifier from src.chat.normal_chat.normal_chat_expressor import NormalChatExpressor +from src.chat.focus_chat.replyer.default_replyer import DefaultReplyer logger = get_logger("normal_chat") @@ -77,6 +78,9 @@ class NormalChat: # 初始化Normal Chat专用表达器 self.expressor = NormalChatExpressor(self.chat_stream, self.stream_name) + self.replyer = DefaultReplyer(chat_id=self.stream_id) + + self.replyer.chat_stream = self.chat_stream self._initialized = True logger.debug(f"[{self.stream_name}] NormalChat 初始化完成 (异步部分)。") @@ -653,6 +657,7 @@ class NormalChat: thinking_id=thinking_id, observations=[], # normal_chat不使用observations expressor=self.expressor, # 使用normal_chat专用的expressor + replyer=self.replyer, chat_stream=self.chat_stream, log_prefix=self.stream_name, shutting_down=self._disabled, diff --git a/src/chat/utils/utils_image.py b/src/chat/utils/utils_image.py index 0e1113aff..19bbfe2c4 100644 --- a/src/chat/utils/utils_image.py +++ b/src/chat/utils/utils_image.py @@ -128,38 +128,38 @@ class ImageManager: return f"[表情包,含义看起来是:{cached_description}]" # 根据配置决定是否保存图片 - if global_config.emoji.save_emoji: - # 生成文件名和路径 - logger.debug(f"保存表情包: {image_hash}") - current_timestamp = time.time() - filename = f"{int(current_timestamp)}_{image_hash[:8]}.{image_format}" - emoji_dir = os.path.join(self.IMAGE_DIR, "emoji") - os.makedirs(emoji_dir, exist_ok=True) - file_path = os.path.join(emoji_dir, filename) + # if global_config.emoji.save_emoji: + # 生成文件名和路径 + logger.debug(f"保存表情包: {image_hash}") + current_timestamp = time.time() + filename = f"{int(current_timestamp)}_{image_hash[:8]}.{image_format}" + emoji_dir = os.path.join(self.IMAGE_DIR, "emoji") + os.makedirs(emoji_dir, exist_ok=True) + file_path = os.path.join(emoji_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 == "emoji")) - 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="emoji", - description=description, - timestamp=current_timestamp, - ) - # logger.debug(f"保存表情包元数据: {file_path}") - except Exception as e: - logger.error(f"保存表情包文件或元数据失败: {str(e)}") + img_obj = Images.get((Images.emoji_hash == image_hash) & (Images.type == "emoji")) + 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="emoji", + description=description, + timestamp=current_timestamp, + ) + # logger.debug(f"保存表情包元数据: {file_path}") + except Exception as e: + logger.error(f"保存表情包文件或元数据失败: {str(e)}") # 保存描述到数据库 (ImageDescriptions表) self._save_description_to_db(image_hash, description, "emoji") diff --git a/src/plugins/test_plugin/actions/mute_action.py b/src/plugins/test_plugin/actions/mute_action.py index afd31eaae..4069bf8a6 100644 --- a/src/plugins/test_plugin/actions/mute_action.py +++ b/src/plugins/test_plugin/actions/mute_action.py @@ -22,7 +22,7 @@ class MuteAction(PluginAction): "当有人发了擦边,或者色情内容时使用", "当有人要求禁言自己时使用", ] - default = False # 默认动作,是否手动添加到使用集 + default = True # 默认动作,是否手动添加到使用集 associated_types = ["command", "text"] # associated_types = ["text"] diff --git a/template/bot_config_template.toml b/template/bot_config_template.toml index bc1844c1b..9334405d4 100644 --- a/template/bot_config_template.toml +++ b/template/bot_config_template.toml @@ -1,5 +1,5 @@ [inner] -version = "2.10.0" +version = "2.11.0" #----以下是给开发人员阅读的,如果你只是部署了麦麦,不需要阅读---- #如果你想要修改配置文件,请在修改后将version的值进行变更