From 21a28904809f7800c5968f1b19387e815cc92b8c Mon Sep 17 00:00:00 2001 From: youpaishidifu Date: Sun, 16 Aug 2026 18:26:58 +0800 Subject: [PATCH] =?UTF-8?q?fix(monitor):=20=E6=B7=BB=E5=8A=A0=E7=AD=96?= =?UTF-8?q?=E7=95=A54-=E5=A4=B4=E9=83=A8=E5=89=A5=E7=A6=BB=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbot=E5=9B=9E=E5=A4=8D=E6=8B=BC=E5=9C=A8?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E5=89=8D=E9=9D=A2=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题:OCR把bot回复拼在用户消息前面("小帽子"),导致: - 查询变成:bot回复+用户消息 - 例:'官方下载 bbsmc分流 那我知道咱们服务器有哪些公告信息呀?' - 下载意图检查提前匹配(query含'下载'),错误路由到下载地址 修复:在 _strip_bot_reply_fragments() 添加策略4: 1. 定位中文疑问词(那/请问/想知道/怎么/哪里/什么等) 2. 分割头部(问句前)和尾部(问句及之后) 3. 归一化比较头部与已知bot回复 4. 匹配成功则剥离头部,只保留用户消息 测试验证: 输入: '官方下载 bbsmc分流 那我知道咱们服务器有哪些公告信息呀?' 输出: '那我知道咱们服务器有哪些公告信息呀?' ✓ commit 5d9e8f3 (2026-08-16) --- monitor.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/monitor.py b/monitor.py index e1fbd03..a413901 100644 --- a/monitor.py +++ b/monitor.py @@ -4794,6 +4794,44 @@ class MessageMonitor: ) stripped_bot = True break + # 策略4:头部剥离——OCR把bot回复拼在用户消息前面("小帽子"问题) + # 例:"官方下载 bbsmc分流 那我知道咱们服务器有哪些公告信息呀?" + # → "那我知道咱们服务器有哪些公告信息呀?" + # 修复:定位中文疑问词(那/请问/想知道等),剥离问句前的bot回复头部 + if not stripped_bot: + # 常见中文疑问词/短语,用于定位用户消息的起始位置 + _question_markers = [ + '那我知道', '那请问', '请问', '想知道', '想问', + '怎么', '哪里', '什么', '哪些', '哪个', + ] + _q_start = len(ts) + for _marker in _question_markers: + _pos = ts.find(_marker) + if _pos >= 0 and _pos < _q_start: + _q_start = _pos + # 如果没找到疑问词,回退到找问号 + if _q_start == len(ts): + _q_mark = max(ts.find('?'), ts.find('?')) + if _q_mark >= 0: + _q_start = _q_mark + + _head = ts[:_q_start].strip() + _tail = ts[_q_start:] + if _head and len(_head) >= 3 and _tail: + # 检查头部是否匹配已知的bot回复 + for _r in replied: + if len(_r) < 5: + continue + _head_norm = re.sub(r'[\s\W_]+', '', _head) + _r_norm = re.sub(r'[\s\W_]+', '', _r) + if _head_norm and _r_norm and (_head_norm == _r_norm or _head_norm in _r_norm): + ts = _tail + stripped_bot = True + logger.debug( + f"[qq] 头部匹配剥离bot回复: {ts!r} <- " + f"{_head!r} (匹配bot reply: {_r[:30]!r})" + ) + break if stripped_bot: ts = re.sub(r'\s+', ' ', ts).strip().strip(',').strip() return ts