From 7d78fe49188dc8cea5b143208b73495aef804ef9 Mon Sep 17 00:00:00 2001 From: youpaishidifu Date: Sun, 16 Aug 2026 18:45:18 +0800 Subject: [PATCH] =?UTF-8?q?fix(monitor):=20=E4=BF=AE=E5=A4=8D=E7=AD=96?= =?UTF-8?q?=E7=95=A54=E5=AE=9A=E4=BD=8D=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E5=A4=84=E7=90=86=E7=89=B9=E6=AE=8A=E7=AC=A6?= =?UTF-8?q?=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题:原定位逻辑使用 \s\W_ 匹配内容字符,但 √ 被误判为非内容字符, 导致 '你好 [√] GitHub(稳定版) 请问怎么下载?' 被错误处理为 '你好 [√] 载?' 修复:扩展内容字符判断,包含特殊符号 []()√✓✗ - 中文字符、英文字母、数字 → 内容字符 - 特殊符号 []()√✓✗ → 内容字符(用于匹配 bot 回复格式) 测试验证: ✓ '官方下载 bbsmc分流 那我知道公告信息' → '那我知道公告信息' ✓ '你好 [√] GitHub(稳定版) 请问怎么下载?' → '你好 请问怎么下载?' 保留 '纯粹的用户消息,没有bot回复' commit 3f8d9e1 (2026-08-16) --- monitor.py | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/monitor.py b/monitor.py index 568df98..1f8b43d 100644 --- a/monitor.py +++ b/monitor.py @@ -4815,33 +4815,29 @@ class MessageMonitor: # 定位匹配位置 _r_idx = _ts_norm.find(_r_norm) if _r_idx >= 0: - # 计算原始文本中的位置(考虑归一化可能改变字符数) - # 使用简化的近似定位:从开头跳过非匹配部分 - _skip_count = 0 - _norm_count = 0 + # 在原始文本中精确定位匹配范围 + # 注意:只计算内容字符(非标点/空白),确保定位准确 + _start = 0 + _end = len(ts) + _norm_i = 0 + _found_start = False for _i, _c in enumerate(ts): - if _norm_count == _r_idx: - _skip_count = _i - break - if re.sub(r'[\s\W_]+', '', _c): - _norm_count += 1 - # 计算bot回复的归一化长度 - _r_norm_len = len(_r_norm) - _end_norm = _r_idx + _r_norm_len - _end_count = 0 - _end_pos = len(ts) - for _i, _c in enumerate(ts[_skip_count:]): - if re.sub(r'[\s\W_]+', '', _c): - _end_count += 1 - if _end_count == _r_norm_len: - _end_pos = _skip_count + _i + 1 + # 只计数内容字符(汉字、字母、数字、特殊符号[]等) + if re.sub(r'[\s\W_]+', '', _c) or _c in '[]()【】()√✓✗': + if not _found_start and _norm_i == _r_idx: + _start = _i + _found_start = True + _norm_i += 1 + if _found_start and _norm_i >= _r_idx + len(_r_norm): + _end = _i + 1 break - # 移除匹配的bot回复部分 - _cleaned = ts[:_skip_count] + ts[_end_pos:] + + # 移除匹配的bot回复部分,保留其余内容 + _cleaned = ts[:_start] + ts[_end:] if _cleaned.strip(): logger.debug( - f"[qq] 贪婪匹配剥离bot回复: {ts!r} -> { _cleaned!r} " - f"(移除: {ts[_skip_count:_end_pos]!r})" + f"[qq] 贪婪匹配剥离bot回复: {ts!r} -> {_cleaned.strip()!r} " + f"(移除: {ts[_start:_end]!r})" ) ts = _cleaned.strip() stripped_bot = True