简体中文 English 繁體中文 日本語 Русский
本文为静态镜像,内容以交互版为准 在交互式文档中心打开 →

ErisPulse.Core.text_match 模块


模块概述

ErisPulse 统一文本/条目匹配工具

为全系统(scope 控制面 / message 装饰器 / wait_reply / adapter.on / activate_on) 提供同一套匹配条目语法,避免各处各自实现、语义漂移:

约定:

提示

  1. compile_entry_matcher(entry) 把单条目编译为 fn(text) -> bool
  2. compile_entry_list(entries) 把条目列表编译为"任一命中"匹配器
  3. compile_text_matcher(pattern, regex) 给装饰器用(glob 与 regex 须都命中)
  4. extract_text(event) 提取事件纯文本(alt_message 优先)

函数列表

_compile_regex(pattern: str)

内部方法 编译正则(带 LRU 缓存)。非法正则返回哨兵对象,调用方视为"不匹配"。


is_entry_pattern(entry: str)

判断条目是否包含模式语法(glob 或 re: 前缀)

无模式字符的纯字符串走精确快路径。


compile_entry_matcher(entry: str)

编译单个匹配条目为判定函数

三种语法:


compile_entry_list(entries: list[str] | None)

编译条目列表为"任一命中即 True"的判定函数


compile_text_matcher(pattern: str | None, regex: str | None)

编译文本匹配条件函数(glob pattern 与 regex 须都命中才返回 True)

供 message 装饰器 / wait_reply / adapter.on 使用: 接收事件对象并内部提取文本,再按 pattern / regex 判定。


extract_text(event: Any)

提取事件对象的纯文本内容(供文本匹配使用)

优先取 alt_message(适配器提供的纯文本回退);否则拼接 message 段中 type == "text" 的文本。提取失败返回空字符串。


entry_matches(entry: str, text: str)

单次便捷匹配(无需预编译)