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

47 lines
1.1 KiB
Markdown
Raw Normal View History

2024-08-21 09:59:21 +00:00
---
title: liteyuki.message.on
---
2024-08-29 06:19:39 +00:00
### *func* `on_message(rule: Rule = empty_rule, priority: int = 0, block: bool = False) -> Matcher`
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 on_message(rule: Rule=empty_rule, priority: int=0, block: bool=False) -> Matcher:
2024-08-21 09:59:21 +00: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 06:19:39 +00:00
### *func* `on_keywords(keywords: list[str] = empty_rule, rule = 0, priority: int = False) -> Matcher`
2024-08-21 09:59:21 +00:00
2024-08-29 06:19:39 +00:00
<details>
<summary> <b>源代码</b> </summary>
2024-08-21 09:59:21 +00:00
2024-08-29 06:19:39 +00:00
```python
def on_keywords(keywords: list[str], rule=empty_rule, priority: int=0, block: bool=False) -> Matcher:
2024-08-21 09:59:21 +00:00
2024-08-29 06:19:39 +00: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 09:59:21 +00:00
2024-08-29 06:19:39 +00:00
### ***var*** `_matcher_list = []`
2024-08-21 09:59:21 +00:00
2024-08-29 06:19:39 +00:00
- **类型**: `list[Matcher]`
2024-08-21 09:59:21 +00:00
2024-08-29 06:19:39 +00:00
### ***var*** `_queue = Queue()`
2024-08-21 09:59:21 +00:00
2024-08-29 06:19:39 +00:00
- **类型**: `Queue`
2024-08-21 09:59:21 +00:00