diff --git a/src/chat/replyer/default_generator.py b/src/chat/replyer/default_generator.py index d43b94e9c..6ffea56d9 100644 --- a/src/chat/replyer/default_generator.py +++ b/src/chat/replyer/default_generator.py @@ -26,7 +26,6 @@ from src.chat.utils.memory_mappings import get_memory_type_chinese_label from src.chat.utils.prompt import Prompt, PromptParameters, global_prompt_manager from src.chat.utils.timer_calculator import Timer from src.chat.utils.utils import get_chat_type_and_target_info -from src.common.data_models.database_data_model import DatabaseMessages from src.common.logger import get_logger from src.config.config import global_config, model_config from src.individuality.individuality import get_individuality @@ -265,7 +264,7 @@ class DefaultReplyer: enable_tool: bool = True, from_plugin: bool = True, stream_id: str | None = None, - reply_message: DatabaseMessages | None = None, + reply_message: dict[str, Any] | None = None, ) -> tuple[bool, dict[str, Any] | None, str | None]: # sourcery skip: merge-nested-ifs """ @@ -1150,7 +1149,7 @@ class DefaultReplyer: extra_info: str = "", available_actions: dict[str, ActionInfo] | None = None, enable_tool: bool = True, - reply_message: DatabaseMessages | dict[str, Any] | None = None, + reply_message: dict[str, Any] | None = None, ) -> str: """ 构建回复器上下文 @@ -1169,11 +1168,6 @@ class DefaultReplyer: """ if available_actions is None: available_actions = {} - - # 确保 reply_message 是 DatabaseMessages 对象 - if isinstance(reply_message, dict): - reply_message = DatabaseMessages(**reply_message) - chat_stream = self.chat_stream chat_id = chat_stream.stream_id person_info_manager = get_person_info_manager() @@ -1198,10 +1192,10 @@ class DefaultReplyer: if reply_message is None: logger.warning("reply_message 为 None,无法构建prompt") return "" - platform = reply_message.chat_info.platform + platform = reply_message.get("chat_info_platform") person_id = person_info_manager.get_person_id( platform, # type: ignore - reply_message.user_info.user_id, # type: ignore + reply_message.get("user_id"), # type: ignore ) person_name = await person_info_manager.get_value(person_id, "person_name") @@ -1210,22 +1204,22 @@ class DefaultReplyer: # 尝试从reply_message获取用户名 await person_info_manager.first_knowing_some_one( platform, # type: ignore - reply_message.user_info.user_id, # type: ignore - reply_message.user_info.user_nickname or "", - reply_message.user_info.user_cardname or "", + reply_message.get("user_id"), # type: ignore + reply_message.get("user_nickname") or "", + reply_message.get("user_cardname") or "", ) # 检查是否是bot自己的名字,如果是则替换为"(你)" bot_user_id = str(global_config.bot.qq_account) current_user_id = await person_info_manager.get_value(person_id, "user_id") - current_platform = reply_message.chat_info.platform + current_platform = reply_message.get("chat_info_platform") if current_user_id == bot_user_id and current_platform == global_config.bot.platform: sender = f"{person_name}(你)" else: # 如果不是bot自己,直接使用person_name sender = person_name - target = reply_message.processed_plain_text + target = reply_message.get("processed_plain_text") # 最终的空值检查,确保sender和target不为None if sender is None: @@ -1572,7 +1566,7 @@ class DefaultReplyer: raw_reply: str, reason: str, reply_to: str, - reply_message: DatabaseMessages | None = None, + reply_message: dict[str, Any] | None = None, ) -> str: # sourcery skip: merge-else-if-into-elif, remove-redundant-if await self._async_init() chat_stream = self.chat_stream @@ -1580,8 +1574,8 @@ class DefaultReplyer: is_group_chat = self.is_group_chat if reply_message: - sender = reply_message.user_info.user_nickname or reply_message.user_info.user_cardname - target = reply_message.processed_plain_text + sender = reply_message.get("sender") + target = reply_message.get("target") else: sender, target = self._parse_reply_target(reply_to) diff --git a/src/plugins/built_in/affinity_flow_chatter/plan_filter.py b/src/plugins/built_in/affinity_flow_chatter/plan_filter.py index 95f3b4193..4f5e6568a 100644 --- a/src/plugins/built_in/affinity_flow_chatter/plan_filter.py +++ b/src/plugins/built_in/affinity_flow_chatter/plan_filter.py @@ -279,10 +279,7 @@ class ChatterPlanFilter: is_group_chat = plan.chat_type == ChatType.GROUP chat_context_description = "你现在正在一个群聊中" if not is_group_chat and plan.target_info: - if isinstance(plan.target_info, dict): - chat_target_name = plan.target_info.get("person_name") or plan.target_info.get("user_nickname") or "对方" - else: - chat_target_name = plan.target_info.person_name or plan.target_info.user_nickname or "对方" + chat_target_name = plan.target_info.person_name or plan.target_info.user_nickname or "对方" chat_context_description = f"你正在和 {chat_target_name} 私聊" action_options_block = await self._build_action_options(plan.available_actions) @@ -557,21 +554,21 @@ class ChatterPlanFilter: ): reasoning = f"LLM 返回了当前不可用的动作 '{action}'。原始理由: {reasoning}" action = "no_action" - from src.common.data_models.database_data_model import DatabaseMessages + #from src.common.data_models.database_data_model import DatabaseMessages - action_message_obj = None - if target_message_obj: - try: - action_message_obj = DatabaseMessages(**target_message_obj) - except Exception: - logger.warning("无法将目标消息转换为DatabaseMessages对象") + #action_message_obj = None + #if target_message_obj: + #try: + #action_message_obj = DatabaseMessages(**target_message_obj) + #except Exception: + #logger.warning("无法将目标消息转换为DatabaseMessages对象") parsed_actions.append( ActionPlannerInfo( action_type=action, reasoning=reasoning, action_data=action_data, - action_message=action_message_obj, + action_message=target_message_obj, available_actions=plan.available_actions, ) ) diff --git a/src/plugins/built_in/maizone_refactored/services/qzone_service.py b/src/plugins/built_in/maizone_refactored/services/qzone_service.py index 8b231496c..af71a281e 100644 --- a/src/plugins/built_in/maizone_refactored/services/qzone_service.py +++ b/src/plugins/built_in/maizone_refactored/services/qzone_service.py @@ -458,7 +458,7 @@ class QZoneService: raise RuntimeError(f"获取 cookie 失败: {data}") return data["data"] - except aiohttp.ClientError as e: # noqa: PERF203 + except aiohttp.ClientError as e: if attempt < max_retries - 1: logger.warning(f"无法连接到Napcat服务(尝试 {attempt + 1}/{max_retries}): {url},错误: {e!s}") await asyncio.sleep(retry_delay)