修复QQ系统消息时间戳污染问题
1. 添加QQ系统消息过滤规则:邀请加入、退出、撤回等 2. 时间戳分割时跳过系统消息,防止旧时间戳继承到后续真实消息 3. QQ系统消息不更新继承时间戳,防止旧时间戳污染
This commit is contained in:
+42
-7
@@ -3087,6 +3087,11 @@ class MessageMonitor:
|
||||
expanded = []
|
||||
_inherited_ts = None # 跨行继承:上一行的时间戳,供当前行无时间戳时使用
|
||||
self._inherited_ts_from_past = False # 跨行继承:上一行时间戳是否来自过去日期前缀
|
||||
# ⭐ QQ系统消息模式:跳过这些消息的时间戳继承,防止旧时间戳覆盖真实用户消息
|
||||
_QQ_SYSTEM_MSG_RE = re.compile(
|
||||
r'(?:邀请.*加入了|加入了本群|加入了群聊|退出了群聊|被管理员移出群|'
|
||||
r'撤回了一条消息|修改了群名称|成为了管理员|取消了管理员|被禁言|被解除禁言|全体禁言|解除全体禁言)'
|
||||
)
|
||||
for i, rl in enumerate(ocr_lines):
|
||||
# ⚠️ 急停检查:stage splitting 逐行处理,每行都检查,保证急停响应 ≤1行处理时间
|
||||
if not self._running:
|
||||
@@ -3098,6 +3103,10 @@ class MessageMonitor:
|
||||
rl = rl.replace(':', ':')
|
||||
logger.debug(f"[ocr] stage[{i}] clean: len={len(rl)} -> {rl[:120]!r}")
|
||||
rl = re.sub(r'\s+', ' ', rl)
|
||||
# ⭐ 检测是否为QQ系统消息:如果是,跳过时间戳继承,防止旧时间戳污染后续真实消息
|
||||
_is_qq_system_msg = bool(_QQ_SYSTEM_MSG_RE.search(rl))
|
||||
if _is_qq_system_msg:
|
||||
logger.info(f"[ocr] stage[{i}] 检测到QQ系统消息,跳过时间戳继承: {rl[:60]!r}")
|
||||
# 移除中文日期前缀(昨天、前天、星期X等),只保留数字时间
|
||||
# ⭐ 检测是否含有"昨天"等过去日期前缀:若有,后续时间戳年龄检查跳过未来时间拦截
|
||||
_had_past_date_prefix = bool(re.search(r'(昨天|前天|大前天|\d+天前)', rl))
|
||||
@@ -3110,7 +3119,8 @@ class MessageMonitor:
|
||||
logger.debug(f"[ocr] stage[{i}] split -> {len(parts)} parts: "
|
||||
f"{[p[:60] for p in parts if p.strip()]}")
|
||||
buf = ''
|
||||
last_ts = _inherited_ts # 继承前一行的时间戳
|
||||
# ⭐ QQ系统消息不继承时间戳,也不更新继承时间戳,防止旧时间戳污染
|
||||
last_ts = None if _is_qq_system_msg else _inherited_ts
|
||||
# ⭐ 继承的过去日期标记:若前一阶段有"昨天"等过去前缀,继承的时间戳也跳过未来检查
|
||||
_inherited_past = _had_past_date_prefix or getattr(self, '_inherited_ts_from_past', False)
|
||||
for part in parts:
|
||||
@@ -3199,13 +3209,17 @@ class MessageMonitor:
|
||||
split_msgs = self._split_merged_ocr_text(msg)
|
||||
for sm in split_msgs:
|
||||
expanded.append(sm)
|
||||
# 更新跨行继承时间戳
|
||||
if last_ts:
|
||||
_inherited_ts = last_ts
|
||||
# ⭐ 若本阶段有过去日期前缀,继承的时间戳也标记为来自过去日期
|
||||
self._inherited_ts_from_past = _had_past_date_prefix
|
||||
# ⭐ QQ系统消息不更新继承时间戳,防止旧时间戳污染后续真实消息
|
||||
if not _is_qq_system_msg:
|
||||
# 更新跨行继承时间戳
|
||||
if last_ts:
|
||||
_inherited_ts = last_ts
|
||||
# ⭐ 若本阶段有过去日期前缀,继承的时间戳也标记为来自过去日期
|
||||
self._inherited_ts_from_past = _had_past_date_prefix
|
||||
else:
|
||||
self._inherited_ts_from_past = False
|
||||
else:
|
||||
self._inherited_ts_from_past = False
|
||||
logger.debug(f"[ocr] stage[{i}] QQ系统消息不更新继承时间戳: {rl[:60]!r}")
|
||||
|
||||
# —— 逐行过滤 ——
|
||||
# ⚠️ 急停检查:stage splitting 完成后,逐行过滤前再查一次
|
||||
@@ -5273,6 +5287,27 @@ class MessageMonitor:
|
||||
logger.debug(f"[ocr] 过滤器2结果: 检测到混合文字乱码({_upper_groups}组大写字母分散),"
|
||||
f"返回True: {text[:60]!r}")
|
||||
return True
|
||||
# ⭐ QQ系统消息过滤:群聊系统通知(邀请加入、退出等)
|
||||
# 如"你邀请xx加入了本群"、"xx邀请了xx加入了群聊"、"xx加入了群聊"
|
||||
_QQ_SYSTEM_MSG_PATTERNS = (
|
||||
r'邀请.*加入了',
|
||||
r'加入了本群',
|
||||
r'加入了群聊',
|
||||
r'退出了群聊',
|
||||
r'被管理员移出群',
|
||||
r'撤回了一条消息',
|
||||
r'修改了群名称',
|
||||
r'成为了管理员',
|
||||
r'取消了管理员',
|
||||
r'被禁言',
|
||||
r'被解除禁言',
|
||||
r'全体禁言',
|
||||
r'解除全体禁言',
|
||||
)
|
||||
for pattern in _QQ_SYSTEM_MSG_PATTERNS:
|
||||
if re.search(pattern, text):
|
||||
logger.debug(f"[ocr] 过滤器2结果: 检测到QQ系统消息,返回True: {text[:60]!r}")
|
||||
return True
|
||||
# ⭐ Task #1457: 360安全弹窗内容过滤(防误触发查库+回复)
|
||||
# 360安全卫士/杀毒弹窗常被OCR识别为用户消息,如"这是敲诈病毒,会勒索您的钱财"
|
||||
# 以下关键词覆盖360常见报毒/安全警告弹窗
|
||||
|
||||
Reference in New Issue
Block a user