import{_ as i,c as a,a7 as e,o as n}from"./chunks/framework.Z6UMW4JZ.js";const c=JSON.parse('{"title":"liteyuki.session.matcher","description":"","frontmatter":{"title":"liteyuki.session.matcher"},"headers":[],"relativePath":"dev/api/session/matcher.md","filePath":"zh/dev/api/session/matcher.md","lastUpdated":null}'),t={name:"dev/api/session/matcher.md"};function l(h,s,r,p,k,o){return n(),a("div",null,s[0]||(s[0]=[e(`
liteyuki.session.matcher
Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved
@Time : 2024/8/19 下午10:51 @Author : snowykami @Email : snowykami@outlook.com @File : matcher.py @Software: PyCharm
Matcher
__init__(self, rule: Rule, priority: int, block: bool)
说明: 匹配器
参数:
- rule: 规则
- priority: 优先级 >= 0
- block: 是否阻断后续优先级更低的匹配器
def __init__(self, rule: Rule, priority: int, block: bool):
self.rule = rule
self.priority = priority
self.block = block
self.handlers: list[EventHandler] = []
handle(self) -> Callable[[EventHandler], EventHandler]
说明: 添加处理函数,装饰器
返回: 装饰器 handler
def handle(self) -> Callable[[EventHandler], EventHandler]:
def decorator(handler: EventHandler) -> EventHandler:
self.handlers.append(handler)
return handler
return decorator
run(self, event: MessageEvent) -> None
说明: 运行处理函数
参数:
- event:
async def run(self, event: MessageEvent) -> None:
if not await self.rule(event):
return
for handler in self.handlers:
try:
await handler(event)
except Exception:
traceback.print_exc()