增强Markdown过滤器检测中文编号列表和代码块内容,防止Bot自言自语

This commit is contained in:
youpaishidifu
2026-08-21 10:01:36 +08:00
parent 6155fd018c
commit 80bc8519c1
+17
View File
@@ -6529,6 +6529,13 @@ class MessageMonitor:
if re.match(r'^#{1,6}(?:\s|\[|[\u4e00-\u9fff])', text):
logger.debug(f"[ocr] 过滤器3结果: 检测到Markdown标题语法,返回True")
return True
# 中文编号列表:第X步 / 步骤X(Bot md 回复常见,用户日常不打)
if re.match(r'^第[一二三四五六七八九十百千万零\d]+步', text):
logger.debug(f"[ocr] 过滤器3结果: 检测到中文编号列表,返回True")
return True
if re.match(r'^步骤[::]', text):
logger.debug(f"[ocr] 过滤器3结果: 检测到步骤说明,返回True")
return True
# 行首列表项:短文本也检测(- 玩家义务 / * 注意)
# 必须放 len<10 之前,否则 "- 玩家应尊重他"(8c) 漏网
if re.match(r'^[\-\*]\s', text):
@@ -6577,6 +6584,16 @@ class MessageMonitor:
# 用户日常对话从不打 *...*, 只可能是 bot md 回复
if '**' in text:
return True
# 代码块内容检测:包含多个编程关键字(Bot md 回复常见,用户日常不打)
code_keywords = ['import', 'def', 'class', 'function', 'return', 'print', 'if', 'for', 'while']
code_keyword_count = sum(1 for kw in code_keywords if re.search(r'\b' + kw + r'\b', text))
if code_keyword_count >= 2:
logger.debug(f"[ocr] 过滤器3结果: 检测到代码块内容({code_keyword_count}个编程关键字),返回True")
return True
# 文件扩展名检测(Bot md 回复中常引用文件)
if re.search(r'\S+\.(txt|json|yml|yaml|md|py|js|ts|html|css|xml|java|c|cpp|h|rs|go|sh|bat|cmd)\b', text):
logger.debug(f"[ocr] 过滤器3结果: 检测到文件扩展名,返回True")
return True
if len(text) < 10:
logger.debug(f"[ocr] 过滤器3结果: 短文本(<10)无Markdown特征,返回False")
return False