feat(poke): 优化戳一戳功能,优先使用 user_id 定位用户

之前的戳一戳功能仅依赖 `user_name` 来查找用户,这在某些情况下可能导致识别不准确或失败。

本次更新对计划执行器 (`PlanExecutor`) 进行了增强,使其在处理 `poke_user` 动作时,能直接从目标消息中提取 `user_id`。`PokeAction` 插件现在会优先使用这个更可靠的 `user_id`。如果 `user_id` 不存在,则回退到使用 `user_name` 作为备用方案。

这显著提高了戳一戳功能的准确性和稳定性。
This commit is contained in:
tt-P607
2025-09-22 22:52:28 +08:00
parent d13b83f10c
commit 56b42defdd
2 changed files with 46 additions and 15 deletions

View File

@@ -4,6 +4,7 @@ PlanExecutor: 接收 Plan 对象并执行其中的所有动作。
"""
import asyncio
import re
import time
from typing import Dict, List
@@ -216,12 +217,35 @@ class PlanExecutor:
try:
logger.info(f"执行其他动作: {action_info.action_type} (原因: {action_info.reasoning})")
action_data = action_info.action_data or {}
# 针对 poke_user 动作,特殊处理
if action_info.action_type == "poke_user":
target_message = action_info.action_message
if target_message:
# 优先直接获取 user_id这才是最可靠的信息
user_id = target_message.get("user_id")
if user_id:
action_data["user_id"] = user_id
logger.info(f"检测到戳一戳动作目标用户ID: {user_id}")
else:
# 如果没有 user_id再尝试用 user_nickname 作为备用方案
user_name = target_message.get("user_nickname")
if user_name:
action_data["user_name"] = user_name
logger.info(f"检测到戳一戳动作,目标用户: {user_name}")
else:
logger.warning("无法从戳一戳消息中获取用户ID或昵称。")
# 传递原始消息ID以支持引用
action_data["target_message_id"] = target_message.get("message_id")
# 构建动作参数
action_params = {
"chat_id": plan.chat_id,
"target_message": action_info.action_message,
"reasoning": action_info.reasoning,
"action_data": action_info.action_data or {},
"action_data": action_data,
}
# 通过动作管理器执行动作