import{_ as s,c as i,o as a,a4 as n}from"./chunks/framework.BZiUP1E-.js";const y=JSON.parse('{"title":"liteyuki.message.matcher","description":"","frontmatter":{"title":"liteyuki.message.matcher"},"headers":[],"relativePath":"en/dev/api/message/matcher.md","filePath":"en/dev/api/message/matcher.md","lastUpdated":1725101868000}'),e={name:"en/dev/api/message/matcher.md"},t=n(`

liteyuki.message.matcher

Description: 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

class Matcher

func __init__(self, rule: Rule, priority: int, block: bool)

Description: 匹配器

Arguments:

Source code or View on GitHub
python
def __init__(self, rule: Rule, priority: int, block: bool):
    """
        匹配器
        Args:
            rule: 规则
            priority: 优先级 >= 0
            block: 是否阻断后续优先级更低的匹配器
        """
    self.rule = rule
    self.priority = priority
    self.block = block
    self.handlers: list[EventHandler] = []

func handle(self) -> Callable[[EventHandler], EventHandler]

Description: 添加处理函数,装饰器

Return: 装饰器 handler

Source code or View on GitHub
python
def handle(self) -> Callable[[EventHandler], EventHandler]:
    """
        添加处理函数,装饰器
        Returns:
            装饰器 handler
        """

    def decorator(handler: EventHandler) -> EventHandler:
        self.handlers.append(handler)
        return handler
    return decorator

async func run(self, event: MessageEvent) -> None

Description: 运行处理函数

Arguments:

Source code or View on GitHub
python
async def run(self, event: MessageEvent) -> None:
    """
        运行处理函数
        Args:
            event:
        Returns:
        """
    if not await self.rule(event):
        return
    for handler in self.handlers:
        try:
            await handler(event)
        except Exception:
            traceback.print_exc()
`,18),l=[t];function h(p,k,r,o,d,c){return a(),i("div",null,l)}const u=s(e,[["render",h]]);export{y as __pageData,u as default};