aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/infini/handler.py
blob: 650762c679ec5acefecf1abca41b8ad13164459e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from abc import ABCMeta, abstractmethod
from .register import Handlers
from .event import MatcherEvent

__all__ = ["Result", "Handler"]


class Result:
    """规则包运行结果"""

    event: str
    status: bool
    kwargs: dict = {}

    def __init__(self, event: str, status: bool, **kwargs) -> None:
        self.event = event
        self.status = status
        self.kwargs = kwargs


class Handler(metaclass=ABCMeta):
    """规则包业务基类"""

    name: str
    priority: int = 0

    # def __init_subclass__(cls) -> None:
    #     handlers.regist(cls.name, cls())

    @abstractmethod
    def process(self, event: MatcherEvent) -> Result:
        raise NotImplementedError


handlers = Handlers()