跳至主要內容

liteyuki.message.rule

远野千束小于 1 分钟

@Rule

async func empty_rule() -> bool

源代码
@Rule
async def empty_rule(event: MessageEvent) -> bool:
    return True

@Rule

async func is_su_rule() -> bool

源代码
@Rule
async def is_su_rule(event: MessageEvent) -> bool:
    return str(event.user_id) in _superusers

class Rule

method __init__(self, handler: RuleHandlerFunc)

源代码
def __init__(self, handler: RuleHandlerFunc):
    self.handler = handler

method __or__(self, other: Rule) -> Rule

源代码
def __or__(self, other: 'Rule') -> 'Rule':

    async def combined_handler(event: MessageEvent) -> bool:
        return await self.handler(event) or await other.handler(event)
    return Rule(combined_handler)

method __and__(self, other: Rule) -> Rule

源代码
def __and__(self, other: 'Rule') -> 'Rule':

    async def combined_handler(event: MessageEvent) -> bool:
        return await self.handler(event) and await other.handler(event)
    return Rule(combined_handler)

async method __call__(self, event: MessageEvent) -> bool

源代码
async def __call__(self, event: MessageEvent) -> bool:
    if self.handler is None:
        return True
    return await self.handler(event)

var RuleHandlerFunc = Callable[[MessageEvent], Coroutine[None, None, bool]]

  • 类型: TypeAlias

  • 说明: 规则函数签名