LiteyukiBot/docs/dev/api/message/rule.md

99 lines
1.9 KiB
Markdown
Raw Normal View History

2024-08-21 09:59:21 +00:00
---
title: liteyuki.message.rule
---
2024-08-29 06:19:39 +00:00
### `@Rule`
### *async func* `empty_rule() -> bool`
2024-08-21 09:59:21 +00:00
2024-08-29 06:19:39 +00:00
<details>
<summary> <b>源代码</b> </summary>
```python
@Rule
async def empty_rule(event: MessageEvent) -> bool:
return True
```
</details>
### `@Rule`
### *async func* `is_su_rule() -> bool`
2024-08-21 09:59:21 +00:00
2024-08-29 06:19:39 +00:00
<details>
<summary> <b>源代码</b> </summary>
```python
@Rule
async def is_su_rule(event: MessageEvent) -> bool:
return str(event.user_id) in _superusers
```
</details>
### **class** `Rule`
### *method* `__init__(self, handler: RuleHandlerFunc)`
2024-08-21 09:59:21 +00:00
<details>
2024-08-29 06:19:39 +00:00
<summary> <b>源代码</b> </summary>
2024-08-21 09:59:21 +00:00
```python
2024-08-29 06:19:39 +00:00
def __init__(self, handler: RuleHandlerFunc):
2024-08-21 09:59:21 +00:00
self.handler = handler
```
</details>
2024-08-29 06:19:39 +00:00
### *method* `__or__(self, other: Rule) -> Rule`
<details>
<summary> <b>源代码</b> </summary>
```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)
```
</details>
### *method* `__and__(self, other: Rule) -> Rule`
<details>
<summary> <b>源代码</b> </summary>
```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)
```
</details>
### *async method* `__call__(self, event: MessageEvent) -> bool`
<details>
<summary> <b>源代码</b> </summary>
```python
async def __call__(self, event: MessageEvent) -> bool:
if self.handler is None:
return True
return await self.handler(event)
```
</details>
### ***var*** `_superusers = get_config('liteyuki.superusers', [])`
- **类型**: `list[str]`
### ***var*** `RuleHandlerFunc = Callable[[MessageEvent], Coroutine[None, None, bool]]`
- **类型**: `TypeAlias`
- **说明**: 规则函数签名