Skip to main content

liteyuki.message.rule

SnowyKamiAbout 1 min

liteyuki.message.rule

Description: Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved

@Time : 2024/8/19 下午10:55 @Author : snowykami @Email : snowykami@outlook.com @File : rule.py @Software: PyCharm

var RuleHandlerFunc

  • Description: 规则函数签名

  • Type: TypeAlias

  • Default: Callable[[MessageEvent], Coroutine[None, None, bool]]

class Rule

def __init__(self, handler: RuleHandlerFunc)

Source code or View on GitHub
def __init__(self, handler: RuleHandlerFunc):
    self.handler = handler

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

Source code or View on GitHub
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)

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

Source code or View on GitHub
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 def __call__(self, event: MessageEvent) -> bool

Source code or View on GitHub
async def __call__(self, event: MessageEvent) -> bool:
    if self.handler is None:
        return True
    return await self.handler(event)

@Rule

async def empty_rule(event: MessageEvent) -> bool

Source code or View on GitHub
@Rule
async def empty_rule(event: MessageEvent) -> bool:
    return True

@Rule

async def is_su_rule(event: MessageEvent) -> bool

Source code or View on GitHub
@Rule
async def is_su_rule(event: MessageEvent) -> bool:
    return str(event.user_id) in _superusers