aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--src/infini/consts/templates.py15
-rw-r--r--src/infini/handler.py2
-rw-r--r--src/infini/matcher.py7
3 files changed, 10 insertions, 14 deletions
diff --git a/src/infini/consts/templates.py b/src/infini/consts/templates.py
index 10ec12b4..c3b979bd 100644
--- a/src/infini/consts/templates.py
+++ b/src/infini/consts/templates.py
@@ -1,16 +1,15 @@
RULE = """from infini import Handler, Result
+__handlers__ = ["HandlerRule"]
-class HandlerRule(Handler):
- \"\"\"自设规则包\"\"\"
- name = "MyRule"
- priority: int = 0
+class HandlerRule(Handler):
+ \"\"\"自设业务函数\"\"\"
- def __init__(self) -> None:
- \"\"\"初始化你的规则包\"\"\"
+ name = "MyRule" # 规则包名
+ priority: int = 0 # 规则包权重
- def process(self) -> Result:
+ def process(self, **kwargs) -> Result:
\"\"\"声明规则包检定方式\"\"\"
return Result("event1", True)
"""
@@ -28,6 +27,6 @@ class MyEvent(MessageEvent):
TEST = """from infini.matcher import matcher, MatcherEvent
def test():
- event = MatcherEvent("event1")
+ event = MatcherEvent("MyRule")
print(matcher.run(event))
"""
diff --git a/src/infini/handler.py b/src/infini/handler.py
index 922023e7..1edef9fa 100644
--- a/src/infini/handler.py
+++ b/src/infini/handler.py
@@ -34,7 +34,7 @@ class Handler:
handlers.regist(cls.name, cls())
@abstractmethod
- def process(self) -> Result:
+ def process(self, **kwargs) -> Result:
raise NotImplementedError
diff --git a/src/infini/matcher.py b/src/infini/matcher.py
index 078a39e8..1a6bfe45 100644
--- a/src/infini/matcher.py
+++ b/src/infini/matcher.py
@@ -1,8 +1,6 @@
from .event import Events, events
-from .handler import Handlers, Handler, Result, handlers
+from .handler import Handlers, Handler, handlers
from .exceptions import UnknownMatcherEvent
-from .typing import Callable
-from .logging import logger
class MatcherEvent:
@@ -38,8 +36,7 @@ class Matcher:
raise UnknownMatcherEvent(f"未知的规则包: {name}")
def run(self, event: MatcherEvent) -> str:
- logger.debug(f"开始处理事件: {event.name}...")
- result = self.match(event.name).process()
+ result = self.match(event.name).process(**event.kwargs)
return self.events.process(result.event, **event.kwargs)