修复[OCR过滤]:改进配置碎片检测和系统消息检测
- 问题:配置碎片检测误判用户消息为配置,系统消息检测不支持QQ自定义撤回消息 - 根因:单条配置文件格式检测正则匹配太宽松,系统消息检测正则只匹配固定格式 - 修复: 1. Task #1671: 改进配置碎片检测,添加用户消息特征检查(@提及、疑问词、查询意图词、长度>20字) 2. Task #1672: 更新系统消息检测逻辑,支持QQ自定义撤回消息(如'A撤回了一条消息,你猜猜撤回了什么') - 测试:验证修复后配置碎片检测和系统消息检测均正常工作
This commit is contained in:
+30
-4
@@ -7502,10 +7502,14 @@ class MessageMonitor:
|
|||||||
if cleaned_text.startswith(p):
|
if cleaned_text.startswith(p):
|
||||||
return True
|
return True
|
||||||
# QQ系统消息残片:撤回了一条消息、你撤回了, 条消息等
|
# QQ系统消息残片:撤回了一条消息、你撤回了, 条消息等
|
||||||
if re.match(r'^(?:你|对方|他|她|管理员)\s*撤回了\s*,?\s*\d*\s*条?\s*消息', cleaned_text):
|
# ⭐ Task #1672: 支持QQ自定义撤回消息(如"A撤回了一条消息,你猜猜撤回了什么")
|
||||||
|
if re.match(r'^(?:你|对方|他|她|管理员)\s*撤回了', cleaned_text):
|
||||||
return True
|
return True
|
||||||
if re.match(r'^撤回了一条消息', cleaned_text):
|
if re.match(r'^撤回了一条消息', cleaned_text):
|
||||||
return True
|
return True
|
||||||
|
# 匹配"A撤回了一条消息"后面跟自定义文本的模式
|
||||||
|
if re.match(r'^.*?撤回了一条消息.*$', cleaned_text):
|
||||||
|
return True
|
||||||
# 纯时间格式(不含消息内容)
|
# 纯时间格式(不含消息内容)
|
||||||
if re.match(r'^\d{1,2}:\d{2}', cleaned_text):
|
if re.match(r'^\d{1,2}:\d{2}', cleaned_text):
|
||||||
return True
|
return True
|
||||||
@@ -8346,7 +8350,10 @@ class MessageMonitor:
|
|||||||
cleaned_seg = re.sub(r'(?:\d{4}[/-]\d{1,2}[/-]\d{1,2})?\s*\d{1,2}[;:.]\d{2}[;:.]?\d{0,2}', '', stripped_seg).strip()
|
cleaned_seg = re.sub(r'(?:\d{4}[/-]\d{1,2}[/-]\d{1,2})?\s*\d{1,2}[;:.]\d{2}[;:.]?\d{0,2}', '', stripped_seg).strip()
|
||||||
|
|
||||||
# 检查是否为系统消息(只检查开头)
|
# 检查是否为系统消息(只检查开头)
|
||||||
if cleaned_seg and re.match(r'^(?:你|对方|他|她|管理员)\s*撤回了|撤回了一条消息|你撤回了', cleaned_seg):
|
# ⭐ Task #1672: 支持QQ自定义撤回消息(如"A撤回了一条消息,你猜猜撤回了什么")
|
||||||
|
if cleaned_seg and (re.match(r'^(?:你|对方|他|她|管理员)\s*撤回了', cleaned_seg) or
|
||||||
|
re.match(r'^撤回了一条消息', cleaned_seg) or
|
||||||
|
re.match(r'^.*?撤回了一条消息.*$', cleaned_seg)):
|
||||||
is_noise = True
|
is_noise = True
|
||||||
logger.debug(f"[{platform}] 预分割: 段[{i}] 检测到系统消息,丢弃: {stripped_seg[:60]!r}")
|
logger.debug(f"[{platform}] 预分割: 段[{i}] 检测到系统消息,丢弃: {stripped_seg[:60]!r}")
|
||||||
# 检查是否为配置碎片
|
# 检查是否为配置碎片
|
||||||
@@ -8470,8 +8477,27 @@ class MessageMonitor:
|
|||||||
# 单条key:value,检查是否为完整的一条(无多余字符)
|
# 单条key:value,检查是否为完整的一条(无多余字符)
|
||||||
_colon_match = re.match(r'^[\u4e00-\u9fff]{2,10}\s*[::]\s*\S+$', text)
|
_colon_match = re.match(r'^[\u4e00-\u9fff]{2,10}\s*[::]\s*\S+$', text)
|
||||||
if _colon_match:
|
if _colon_match:
|
||||||
logger.debug(f"[ocr] 过滤器2结果: 检测到单条配置文件格式(key: value),返回True: {text!r}")
|
# ⭐ Task #1671: 检查用户消息特征,避免误判正常用户消息
|
||||||
return True
|
# 如"使用第三方作弊软件:脚本。外挂。模拟器。群控设备等非正常手段批量注册或刷取数据"
|
||||||
|
_has_user_msg_feature = False
|
||||||
|
# 特征1: @提及(用户@他人或@机器人)
|
||||||
|
if '@' in text and re.search(r'@\w+', text):
|
||||||
|
_has_user_msg_feature = True
|
||||||
|
# 特征2: 疑问词(吗呢多少怎么如何哪什么几)
|
||||||
|
if any(q in text for q in ['?', '?', '吗', '呢', '多少', '怎么', '如何', '哪', '什么', '几']):
|
||||||
|
_has_user_msg_feature = True
|
||||||
|
# 特征3: 明确的查询意图词(查/问/看/有/在哪/如何/怎么)
|
||||||
|
if re.search(r'[查问看].*(?:插件|功能|命令|模式|系统|公告|信息)', text):
|
||||||
|
_has_user_msg_feature = True
|
||||||
|
# 特征4: 长度超过20字的中文文本(可能是用户消息而非配置)
|
||||||
|
if len(text) > 20:
|
||||||
|
_has_user_msg_feature = True
|
||||||
|
if _has_user_msg_feature:
|
||||||
|
# 包含用户消息特征,不丢弃,继续后续检查
|
||||||
|
logger.debug(f"[ocr] 过滤器2结果: 检测到单条key:value但含用户消息特征,继续检查: {text[:80]!r}")
|
||||||
|
else:
|
||||||
|
logger.debug(f"[ocr] 过滤器2结果: 检测到单条配置文件格式(key: value),返回True: {text!r}")
|
||||||
|
return True
|
||||||
# 3. 检测其他配置文件格式:等号分隔的键值对(如key=value)
|
# 3. 检测其他配置文件格式:等号分隔的键值对(如key=value)
|
||||||
_eq_pattern = r'[\u4e00-\u9fff]{2,10}\s*=\s*\S+'
|
_eq_pattern = r'[\u4e00-\u9fff]{2,10}\s*=\s*\S+'
|
||||||
_eq_matches = re.findall(_eq_pattern, text)
|
_eq_matches = re.findall(_eq_pattern, text)
|
||||||
|
|||||||
Reference in New Issue
Block a user