1
0
forked from bot/app

添加对主流框架的消息io支持

This commit is contained in:
2024-08-20 06:20:41 +08:00
parent 237789e0d4
commit 0c942d9806
26 changed files with 267 additions and 192 deletions

View File

@ -7,4 +7,27 @@ Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved
@Email : snowykami@outlook.com
@File : rule.py
@Software: PyCharm
"""
"""
from typing import Optional, TypeAlias, Callable, Coroutine
from liteyuki.message.event import Event
RuleHandler: TypeAlias = Callable[[Event], Coroutine[None, None, bool]]
"""规则函数签名"""
class Rule:
def __init__(self, handler: Optional[RuleHandler] = None):
self.handler = handler
def __or__(self, other: "Rule") -> "Rule":
return Rule(lambda event: self.handler(event) or other.handler(event))
def __and__(self, other: "Rule") -> "Rule":
return Rule(lambda event: self.handler(event) and other.handler(event))
async def __call__(self, event: Event) -> bool:
if self.handler is None:
return True
return await self.handler(event)