fix(msgbot): 修复历史消息漏放导致自言自语 + user_messages未入库
- 修复 _ocr_text_has_fresh_timestamp:无日期+时间戳全部过期(>300s) 时由误放行改为丢弃。 原"OCR时间戳不准确"假设会让QQ窗口中12:08/12:24等历史老消息被当作新消息,触发自言自语。 - 在"无日期+新鲜时间戳"与"无日期+无时间戳中文"两条放行路径补上 record_user_message, 修复 user_messages 表长期为空、跨轮去重失效的问题。
This commit is contained in:
+10
-3
@@ -6602,12 +6602,17 @@ class MessageMonitor:
|
||||
try:
|
||||
if not self._is_timestamp_old(ts, 300):
|
||||
logger.debug(f"[ocr] 过滤器1结果: 无日期+新鲜时间戳{ts}(≤300s),放行")
|
||||
# ⭐ 2026-08-29 修复:放行前记录用户消息,避免 user_messages 空表
|
||||
self._msg_history.record_user_message(platform, stripped)
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
# 时间戳过期但无日期:仍放行给DB查重(可能是当天消息,OCR时间戳不准确)
|
||||
logger.debug(f"[ocr] 过滤器1结果: 无日期+时间戳过期,但放行给DB查重")
|
||||
return True
|
||||
# ⭐ 2026-08-29 修复:无日期+时间戳全部过期 → 必须丢弃,不可放行
|
||||
# QQ聊天窗口中历史消息(如12:08/12:24)不带日期,但时间戳准确且已过期(>300s)。
|
||||
# 原"OCR时间戳不准确"的假设会让这些老消息被当成新消息 → 触发自言自语。
|
||||
# OCR对数字时间戳识别可靠,过期即代表消息老旧,无日期时一律丢弃。
|
||||
logger.debug(f"[ocr] 过滤器1结果: 无日期+时间戳过期(全部>300s),丢弃历史消息: {text[:80]!r}")
|
||||
return False
|
||||
# 无时间戳:需要检查噪声和中文字符(UI噪声应丢弃)
|
||||
logger.debug(f"[ocr] 无日期+无时间戳,检查噪声和中文字符")
|
||||
# 清理 bot markdown 加粗残留
|
||||
@@ -6630,6 +6635,8 @@ class MessageMonitor:
|
||||
return False
|
||||
# 放行给下游DB查重
|
||||
logger.debug(f"[ocr] 过滤器1结果: 无日期+无时间戳+中文消息,放行给下游DB查重")
|
||||
# ⭐ 2026-08-29 修复:放行前记录用户消息,避免 user_messages 空表
|
||||
self._msg_history.record_user_message(platform, stripped)
|
||||
return True
|
||||
if not timestamps:
|
||||
# ⭐ 无可见时间戳:检查噪声文本
|
||||
|
||||
Reference in New Issue
Block a user