fix: 行合并逻辑防止bot回复污染用户消息 (Task #1555)
This commit is contained in:
+16
-1
@@ -3283,16 +3283,31 @@ class MessageMonitor:
|
||||
# ⭐ Task #1510: _SENT_END 补 ASCII `?`。OCR 对问句常输出半角 `?`(非全角 `?`),
|
||||
# 导致「游戏专用PHP有哪两种登录模式?」这类问句行不与下一行合并,
|
||||
# 防止多条用户消息被 `,` 黏成一行、共享同一陈旧继承时间戳被整体误杀。
|
||||
# ⭐ Task #1555: 防止跨消息边界合并。当前行是已知bot回复时,不与其后行合并,
|
||||
# 避免 "用户问句 + bot旧回复 + 用户新问句" 被合成一条污染消息。
|
||||
_SENT_END = re.compile(r'[。!??…~))」』\]呀啊呢吧嘛]$')
|
||||
_TS_START = re.compile(r'^(?:\d{1,2}[.;:]\d{2}|(?:昨天|前天|大前天|今天|明天|星期[一二三四五六日天]|\d+天前)\s*\d)')
|
||||
# 收集已知bot回复用于行合并判断
|
||||
_known_bot_replies = set()
|
||||
for _r in self._replied_texts:
|
||||
if _r and len(_r) >= 3:
|
||||
_known_bot_replies.add(self._norm_frag(_r))
|
||||
merged_lines = []
|
||||
for rl in ocr_lines:
|
||||
# 当前行含疑问特征(裸@末尾或问号)→ 不合并,防止用户问句被黏进bot回复
|
||||
if rl.endswith('@') or re.search(r'[??]', rl):
|
||||
merged_lines.append(rl)
|
||||
continue
|
||||
# ⭐ Task #1555: 若当前行是已知bot回复内容,不合并到下一行
|
||||
# 防止 "用户问句 + bot回复" 合并后污染消息
|
||||
_is_bot_reply_line = False
|
||||
if _known_bot_replies and len(rl) >= 3:
|
||||
_norm_rl = self._norm_frag(rl)
|
||||
if _norm_rl and _norm_rl in _known_bot_replies:
|
||||
_is_bot_reply_line = True
|
||||
if merged_lines and not _SENT_END.search(merged_lines[-1]) \
|
||||
and not _TS_START.match(rl) and not _TS_START.match(merged_lines[-1]):
|
||||
and not _TS_START.match(rl) and not _TS_START.match(merged_lines[-1]) \
|
||||
and not _is_bot_reply_line:
|
||||
merged_lines[-1] = merged_lines[-1] + ',' + rl
|
||||
else:
|
||||
merged_lines.append(rl)
|
||||
|
||||
Reference in New Issue
Block a user