fix(chatter): 修复私聊场景下目标信息类型不匹配问题

在 affinity_flow_chatter 插件中,处理私聊上下文时,`plan.target_info` 可能是一个字典(dict)类型,而不是预期的对象类型。这会导致在访问 `plan.target_info.person_name` 等属性时引发 `AttributeError`。

本次提交通过增加类型检查来处理这种情况,确保无论是对象还是字典类型的 `target_info` 都能被正确解析,从而增强了代码的健壮性并修复了潜在的运行时错误。
This commit is contained in:
minecraft1024a
2025-10-12 13:48:05 +08:00
committed by Windpicker-owo
parent 74e6d1ec39
commit 804af4d8be
2 changed files with 5 additions and 2 deletions

View File

@@ -279,7 +279,10 @@ class ChatterPlanFilter:
is_group_chat = plan.chat_type == ChatType.GROUP is_group_chat = plan.chat_type == ChatType.GROUP
chat_context_description = "你现在正在一个群聊中" chat_context_description = "你现在正在一个群聊中"
if not is_group_chat and plan.target_info: if not is_group_chat and plan.target_info:
chat_target_name = plan.target_info.person_name or plan.target_info.user_nickname or "对方" 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_context_description = f"你正在和 {chat_target_name} 私聊" chat_context_description = f"你正在和 {chat_target_name} 私聊"
action_options_block = await self._build_action_options(plan.available_actions) action_options_block = await self._build_action_options(plan.available_actions)

View File

@@ -458,7 +458,7 @@ class QZoneService:
raise RuntimeError(f"获取 cookie 失败: {data}") raise RuntimeError(f"获取 cookie 失败: {data}")
return data["data"] return data["data"]
except aiohttp.ClientError as e: except aiohttp.ClientError as e: # noqa: PERF203
if attempt < max_retries - 1: if attempt < max_retries - 1:
logger.warning(f"无法连接到Napcat服务(尝试 {attempt + 1}/{max_retries}): {url},错误: {e!s}") logger.warning(f"无法连接到Napcat服务(尝试 {attempt + 1}/{max_retries}): {url},错误: {e!s}")
await asyncio.sleep(retry_delay) await asyncio.sleep(retry_delay)