diff --git a/monitor.py b/monitor.py index 6e04f65..4da9cf7 100644 --- a/monitor.py +++ b/monitor.py @@ -7525,6 +7525,45 @@ class MessageMonitor: logger.debug(f"[ocr] 过滤器2结果: 空文本,返回False") return False + # ⭐ Task #1592: 配置文件格式检测(最粗暴方法) + # 检测所有配置文件格式:key:value 对、JSON 对象等 + # 特征:无问号/疑问词,有明显的配置结构 + # 直接丢弃,不进入后续KB搜索 + # 1. 检测JSON格式:包含大括号且是键值对 + _json_match = re.search(r'\{[^}]+\}', text) + if _json_match: + # 检查是否包含键值对(key: value 或 "key": "value") + _json_content = _json_match.group(0) + _kv_pattern = re.search(r'["\']?\w+["\']?\s*[::]\s*["\']?[^"\']+["\']?', _json_content) + if _kv_pattern: + logger.debug(f"[ocr] 过滤器2结果: 检测到JSON配置文件格式,返回True: {text!r}") + return True + # 2. 检测key:value对格式:至少两个冒号分隔的键值对 + _colon_pattern = r'[\u4e00-\u9fff]{2,10}\s*[::]\s*\S+' + _colon_matches = re.findall(_colon_pattern, text) + if len(_colon_matches) >= 2: + # 多条key:value拼接(如"图标: potato 标题:自杀") + logger.debug(f"[ocr] 过滤器2结果: 检测到多条配置文件格式({len(_colon_matches)}条key:value),返回True: {text!r}") + return True + elif len(_colon_matches) == 1: + # 单条key:value,检查是否为完整的一条(无多余字符) + _colon_match = re.match(r'^[\u4e00-\u9fff]{2,10}\s*[::]\s*\S+$', text) + if _colon_match: + logger.debug(f"[ocr] 过滤器2结果: 检测到单条配置文件格式(key: value),返回True: {text!r}") + return True + # 3. 检测其他配置文件格式:等号分隔的键值对(如key=value) + _eq_pattern = r'[\u4e00-\u9fff]{2,10}\s*=\s*\S+' + _eq_matches = re.findall(_eq_pattern, text) + if len(_eq_matches) >= 2: + logger.debug(f"[ocr] 过滤器2结果: 检测到等号分隔的配置文件格式({len(_eq_matches)}条key=value),返回True: {text!r}") + return True + # 4. 检测YAML/INI格式:行首为key,后跟冒号或等号 + _yaml_ini_pattern = r'^[\u4e00-\u9fff]{2,10}\s*[:=]\s*\S+' + _yaml_ini_matches = re.findall(_yaml_ini_pattern, text, re.MULTILINE) + if len(_yaml_ini_matches) >= 2: + logger.debug(f"[ocr] 过滤器2结果: 检测到YAML/INI配置文件格式({len(_yaml_ini_matches)}行),返回True: {text!r}") + return True + # ⭐ 闲聊消息检测(2026-08-22 新增) # 特征:短文本 + 疑问词 + 无具体查询主题 # 例:"有时间吗"、"在不在"、"好的"、"嗯嗯" → 缺乏可查库的具体主题 @@ -7689,21 +7728,6 @@ class MessageMonitor: _has_subject = any(s in text for s in ('我', '你', '他', '我们', '你们', '他们', '玩家', '用户', '管理员')) # 无疑问词 + 无动词 或 无疑问词 + 无主语 → 可能是残片 if not _has_question_word and (not _has_verb or not _has_subject): - # ⭐ Task #1591: 配置文件格式检测(如"图标: shield"、"标题: xxx"、"图标: potato 标题:自杀") - # 特征:key: value格式,无问号/疑问词,不是用户查询 - # 支持单条和多条拼接格式,忽略大小写/标点差异 - _colon_pattern = r'[\u4e00-\u9fff]{2,10}\s*[::]\s*\S+' - _colon_matches = re.findall(_colon_pattern, text) - if len(_colon_matches) >= 2: - # 多条key:value拼接(如"图标: potato 标题:自杀") - logger.debug(f"[ocr] 过滤器2结果: 检测到多条配置文件格式({len(_colon_matches)}条key:value),返回True: {text!r}") - return True - elif len(_colon_matches) == 1: - # 单条key:value,检查是否为完整的一条(无多余字符) - _colon_match = re.match(r'^[\u4e00-\u9fff]{2,10}\s*[::]\s*\S+$', text) - if _colon_match: - logger.debug(f"[ocr] 过滤器2结果: 检测到单条配置文件格式(key: value),返回True: {text!r}") - return True # ⭐ 核心名词放行:包含核心名词的短文本可能是用户查询词,不视为残片 _core_nouns = {'公告', '更新', '通知', '说明', '规则', '版本', '下载', '安装', '登录', '配置', '设置', '操作', '模式', '列表', '详情', '信息', '内容', '介绍', '功能', '系统', '服务', '玩家', '用户', '管理员', '服务器', '客户端', '插件', '模块', '接口', 'API', 'BUG', '问题', '错误', '异常', '日志', '配置', '文件', '目录', '路径', '地址', '链接', '网址', '网站', '网页', '页面', '界面', '菜单', '按钮', '图标', '图片', '视频', '音频', '文档', '手册', '指南', '教程', '帮助', '支持', '反馈', '建议', '意见', '投诉', '举报', '奖励', '惩罚', '活动', '比赛', '排名', '积分', '等级', '权限', '角色', '职业', '技能', '装备', '道具', '货币', '交易', '市场', '商店', '背包', '仓库', '邮件', '聊天', '组队', '公会', '领地', '地图', '任务', '副本', 'BOSS', '怪物', '掉落', '经验', '属性', '状态', '效果', 'BUFF', 'DEBUFF', '冷却', '消耗', '需求', '条件', '限制'} if any(noun in text for noun in _core_nouns):