Skip to content

# liteyuki.message.rule ​

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` ​

- 说明: 规则函数签名

- 类型: `TypeAlias`

- 默认值: `Callable[[MessageEvent], Coroutine[None, None, bool]]`

### class `Rule` ​

#### func `__init__(self, handler: RuleHandlerFunc)` ​

源代码 或 在GitHub上查看
python

    def __init__(self, handler: RuleHandlerFunc):
        self.handler = handler

#### func `__or__(self, other: Rule) -> Rule` ​

源代码 或 在GitHub上查看
python

    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)

#### func `__and__(self, other: Rule) -> Rule` ​

源代码 或 在GitHub上查看
python

    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 func `__call__(self, event: MessageEvent) -> bool` ​

源代码 或 在GitHub上查看
python

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

`@Rule`

### async func `empty_rule(event: MessageEvent) -> bool` ​

源代码 或 在GitHub上查看
python

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

`@Rule`

### async func `is_su_rule(event: MessageEvent) -> bool` ​

源代码 或 在GitHub上查看
python

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