pull/65/head
foxplaying 2025-10-19 18:18:01 +08:00 committed by GitHub
parent 74031f234a
commit 6abfc75f55
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 23 additions and 23 deletions

View File

@ -401,7 +401,7 @@ class NoticeHandler:
user_name = user_qq_info.get("nickname") if user_qq_info and user_qq_info.get("nickname") else "QQ用户" user_name = user_qq_info.get("nickname") if user_qq_info and user_qq_info.get("nickname") else "QQ用户"
user_cardname = user_qq_info.get("card") if user_qq_info else None user_cardname = user_qq_info.get("card") if user_qq_info else None
target_name = target_qq_info.get("nickname") if target_qq_info and target_qq_info.get("nickname") else "未知目标" target_name = target_qq_info.get("nickname") if target_qq_info and target_qq_info.get("nickname") else "QQ用户"
# 解析 raw_info 文本 # 解析 raw_info 文本
text_str = "" text_str = ""
@ -420,34 +420,34 @@ class NoticeHandler:
text_str = "" text_str = ""
# 智能识别动作 (仅允许 X了X 三字结构) # 智能识别动作 (仅允许 X了X 三字结构)
action_match = re.search(r"[\u4e00-\u9fa5]{1,3}了[\u4e00-\u9fa5]{1,3}", text_str) match_list = re.findall(r"[\u4e00-\u9fa5]了[\u4e00-\u9fa5]", text_str)
action = "拍了拍"
has_action = False has_action = False
if action_match: if match_list:
candidate = action_match.group(0) action = match_list[0] # 取第一个 X了X
# 严格限定为 X了X 三字结构 has_action = True
if re.match(r"^[\u4e00-\u9fa5]了[\u4e00-\u9fa5]$", candidate): else:
action = candidate action = "拍了拍" # 默认 fallback
has_action = True
else:
has_action = False
# 去除动作部分文本 # 若存在动作,从原文中移除它(防止重复)
if has_action: if has_action:
text_str = text_str.replace(action, "").strip() text_str = text_str.replace(action, "", 1).strip()
# --------------------- # 提取描述性后缀(动作之后的内容)
# 提取描述性后缀 suffix = text_str.strip() if text_str else ""
# ---------------------
suffix = "" # 检查句式是否已经反转(例如 “A: A...”)
if text_str: prefix_wrong = False
suffix = text_str if re.match(rf"^{re.escape(user_name)}[:]", suffix) or suffix.startswith(user_name):
prefix_wrong = True
# ---------------------
# 生成标准格式句子 # 生成标准格式句子
# --------------------- if prefix_wrong:
text_str = f"{action} {target_name}{(' ' + suffix) if suffix else ''}".strip() text_str = f"{action} {target_name}{(' ' + suffix) if suffix else ''}"
text_str = text_str.replace(" ", " ") else:
# 正常句式
text_str = f"{action} {target_name}{(' ' + suffix) if suffix else ''}"
text_str = text_str.replace(" ", " ").strip()
# 构造消息段和用户信息 # 构造消息段和用户信息
seg_data: Seg = Seg(type="text", data=text_str) seg_data: Seg = Seg(type="text", data=text_str)