From 9f7e4b5d0a4aa6d9536a6eb1471a110d716e2566 Mon Sep 17 00:00:00 2001 From: pine Date: Mon, 14 Apr 2025 20:51:18 +0800 Subject: feat: :art: refactor log parsing logic with simplified rules and priority-based matching --- test/example_rule.json | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'test') diff --git a/test/example_rule.json b/test/example_rule.json index 750789a..73abe3f 100644 --- a/test/example_rule.json +++ b/test/example_rule.json @@ -1,6 +1,6 @@ { + // 匹配日志元数据,提取 id、QQ 账号和时间。例如:墨勒托.DW(1571806261) 2025-01-27 19:58:15 "metadata": { - // 匹配日志元数据,提取 id、QQ 账号和时间。例如:墨勒托.DW(1571806261) 2025-01-27 19:58:15 "type": "metadata", "patterns": [ "^(\\S+)\\((\\d+)\\)\\s+(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2})" @@ -10,37 +10,47 @@ "content": [ { "type": "action", - "patterns": ["^#s*((?:(?![“”\"(【】]).)+)"], // 排除后续特殊符号 + "match_type": "prefix", + "priority": 1001, // 优先级,数字越小优先级越高,范围为1-5000 + "patterns": ["^#(.+)"], "groups": ["action_content"] }, { "type": "speech", + "match_type": "enclosed", + "priority": 101, "patterns": [ - "[“](.+?)[”]", // 中文引号 - "\"(.*?)\"", // 英文引号 - "”(.+?)“" // 混合引号 + "[“”\"](.+?)[“”\"]" // 匹配各种引号 ], "groups": ["speech_content"] }, { "type": "ooc_speech", + "match_type": "enclosed", + "priority": 103, "patterns": [ - // "((.*?))", // 英文括号 - "((.*?))", // 中文括号 - // "((.*)", // 未闭合英文括号 - "((.*)" // 未闭合中文括号 + "[\\((](.+?)[\\))]" // 匹配各种括号 ], "groups": ["ooc_content"] }, { - // 匹配掷骰指令,以 . 或 。开头但是不匹配连续的指令前缀。例如:匹配".ra智力",不匹配"。。。" + "type": "suffix_ooc_speech", + "match_type": "suffix", + "priority": 2001, + "patterns": ["(.+)b$"], + "groups": ["suffix_ooc_speech"] + }, + { "type": "dice_order", - "patterns": ["^(?:[\\.。]([^.。].+))"], + "match_type": "prefix", + "priority": 1, + "patterns": ["^[.。](.+)"], "groups": ["dice_command"] }, { - // 匹配角色心理活动。例如:【这里好可怕】 "type": "thought", + "match_type": "enclosed", + "priority": 102, "patterns": ["【(.+)】"], "groups": ["thought_content"] } -- cgit v1.2.3-70-g09d2