2024-08-21 17:59:21 +08:00
|
|
|
---
|
|
|
|
title: liteyuki.message.on
|
|
|
|
---
|
2024-08-29 14:19:39 +08:00
|
|
|
### *func* `on_message(rule: Rule = empty_rule, priority: int = 0, block: bool = False) -> Matcher`
|
2024-08-21 17:59:21 +08:00
|
|
|
|
|
|
|
|
|
|
|
<details>
|
2024-08-29 14:19:39 +08:00
|
|
|
<summary> <b>源代码</b> </summary>
|
2024-08-21 17:59:21 +08:00
|
|
|
|
|
|
|
```python
|
2024-08-29 14:19:39 +08:00
|
|
|
def on_message(rule: Rule=empty_rule, priority: int=0, block: bool=False) -> Matcher:
|
2024-08-21 17:59:21 +08:00
|
|
|
matcher = Matcher(rule, priority, block)
|
|
|
|
for i, m in enumerate(_matcher_list):
|
|
|
|
if m.priority < matcher.priority:
|
|
|
|
_matcher_list.insert(i, matcher)
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
_matcher_list.append(matcher)
|
|
|
|
return matcher
|
|
|
|
```
|
|
|
|
</details>
|
|
|
|
|
2024-08-29 14:19:39 +08:00
|
|
|
### *func* `on_keywords(keywords: list[str] = empty_rule, rule = 0, priority: int = False) -> Matcher`
|
2024-08-21 17:59:21 +08:00
|
|
|
|
|
|
|
|
2024-08-29 14:19:39 +08:00
|
|
|
<details>
|
|
|
|
<summary> <b>源代码</b> </summary>
|
2024-08-21 17:59:21 +08:00
|
|
|
|
2024-08-29 14:19:39 +08:00
|
|
|
```python
|
|
|
|
def on_keywords(keywords: list[str], rule=empty_rule, priority: int=0, block: bool=False) -> Matcher:
|
2024-08-21 17:59:21 +08:00
|
|
|
|
2024-08-29 14:19:39 +08:00
|
|
|
@Rule
|
|
|
|
async def on_keywords_rule(event: MessageEvent):
|
|
|
|
return any((keyword in event.raw_message for keyword in keywords))
|
|
|
|
return on_message(on_keywords_rule & rule, priority, block)
|
|
|
|
```
|
|
|
|
</details>
|
2024-08-21 17:59:21 +08:00
|
|
|
|
2024-08-29 14:19:39 +08:00
|
|
|
### ***var*** `_matcher_list = []`
|
2024-08-21 17:59:21 +08:00
|
|
|
|
2024-08-29 14:19:39 +08:00
|
|
|
- **类型**: `list[Matcher]`
|
2024-08-21 17:59:21 +08:00
|
|
|
|
2024-08-29 14:19:39 +08:00
|
|
|
### ***var*** `_queue = Queue()`
|
2024-08-21 17:59:21 +08:00
|
|
|
|
2024-08-29 14:19:39 +08:00
|
|
|
- **类型**: `Queue`
|
2024-08-21 17:59:21 +08:00
|
|
|
|