1
0
forked from bot/app

⬇️ 更新文档样式

This commit is contained in:
2024-08-29 14:19:39 +08:00
parent 3a3ef4d6ae
commit f12b6854b7
70 changed files with 3676 additions and 3257 deletions

View File

@ -1,7 +1,3 @@
---
title: liteyuki.message
index: true
icon: laptop-code
category: API
---

View File

@ -1,47 +1,19 @@
---
title: liteyuki.message.event
order: 1
icon: laptop-code
category: API
---
### ***class*** `MessageEvent`
### **class** `MessageEvent`
### *method* `__init__(self, bot_id: str, message: list[dict[str, Any]] | str, message_type: str, raw_message: str, session_id: str, user_id: str, session_type: str, receive_channel: str, data: Optional[dict[str, Any]] = None)`
###   ***def*** `__init__(self, bot_id: str, message: list[dict[str, Any]] | str, message_type: str, raw_message: str, session_id: str, session_type: str, receive_channel: str, data: Optional[dict[str, Any]]) -> None`
**说明**: 轻雪抽象消息事件
 轻雪抽象消息事件
Args:
bot_id: 机器人ID
message: 消息,消息段数组[{type: str, data: dict[str, Any]}]
raw_message: 原始消息(通常为纯文本的格式)
message_type: 消息类型(private, group, other)
session_id: 会话ID(私聊通常为用户ID群聊通常为群ID)
session_type: 会话类型(private, group)
receive_channel: 接收频道(用于回复消息)
data: 附加数据
<details>
<summary>源代码</summary>
<summary> <b>源代码</b> </summary>
```python
def __init__(self, bot_id: str, message: list[dict[str, Any]] | str, message_type: str, raw_message: str, session_id: str, session_type: str, receive_channel: str, data: Optional[dict[str, Any]]=None):
def __init__(self, bot_id: str, message: list[dict[str, Any]] | str, message_type: str, raw_message: str, session_id: str, user_id: str, session_type: str, receive_channel: str, data: Optional[dict[str, Any]]=None):
"""
轻雪抽象消息事件
Args:
@ -66,22 +38,23 @@ def __init__(self, bot_id: str, message: list[dict[str, Any]] | str, message_typ
self.raw_message = raw_message
self.session_id = session_id
self.session_type = session_type
self.user_id = user_id
self.receive_channel = receive_channel
```
</details>
### &emsp; ***def*** `reply(self, message: str | dict[str, Any]) -> None`
### *method* `reply(self, message: str | dict[str, Any])`
&emsp;回复消息
Args:
message:
**说明**: 回复消息
**参数**:
> - message:
Returns:
<details>
<summary>源代码</summary>
<summary> <b>源代码</b> </summary>
```python
def reply(self, message: str | dict[str, Any]):
@ -96,11 +69,3 @@ def reply(self, message: str | dict[str, Any]):
```
</details>
### ***var*** `reply_event = MessageEvent(message_type=self.session_type, message=message, raw_message='', data={'message': message}, bot_id=self.bot_id, session_id=self.session_id, session_type=self.session_type, receive_channel='_')`
### ***var*** `data = {}`

View File

@ -1,28 +1,21 @@
---
title: liteyuki.message.matcher
order: 1
icon: laptop-code
category: API
---
### ***class*** `Matcher`
### **class** `Matcher`
### *method* `__init__(self, rule: Rule, priority: int, block: bool)`
### &emsp; ***def*** `__init__(self, rule: Rule, priority: int, block: bool) -> None`
**说明**: 匹配器
&emsp;匹配器
**参数**:
> - rule: 规则
> - priority: 优先级 >= 0
> - block: 是否阻断后续优先级更低的匹配器
Args:
rule: 规则
priority: 优先级 >= 0
block: 是否阻断后续优先级更低的匹配器
<details>
<summary>源代码</summary>
<summary> <b>源代码</b> </summary>
```python
def __init__(self, rule: Rule, priority: int, block: bool):
@ -40,32 +33,65 @@ def __init__(self, rule: Rule, priority: int, block: bool):
```
</details>
### &emsp; ***def*** `handle(self, handler: EventHandler) -> EventHandler`
### *method* `handle(self) -> Callable[[EventHandler], EventHandler]`
&emsp;添加处理函数,装饰器
Args:
handler:
**说明**: 添加处理函数,装饰器
Returns:
**返回**: 装饰器 handler
EventHandler
<details>
<summary>源代码</summary>
<summary> <b>源代码</b> </summary>
```python
def handle(self, handler: EventHandler) -> EventHandler:
def handle(self) -> Callable[[EventHandler], EventHandler]:
"""
添加处理函数,装饰器
Args:
handler:
Returns:
EventHandler
装饰器 handler
"""
self.handlers.append(handler)
return handler
def decorator(handler: EventHandler) -> EventHandler:
self.handlers.append(handler)
return handler
return decorator
```
</details>
### *async method* `run(self, event: MessageEvent) -> None`
**说明**: 运行处理函数
**参数**:
> - event:
<details>
<summary> <b>源代码</b> </summary>
```python
async def run(self, event: MessageEvent) -> None:
"""
运行处理函数
Args:
event:
Returns:
"""
if not await self.rule(event):
return
for handler in self.handlers:
try:
await handler(event)
except Exception:
traceback.print_exc()
```
</details>
### ***var*** `EventHandler = Callable[[MessageEvent], Coroutine[None, None, Any]]`
- **类型**: `TypeAlias`

View File

@ -1,19 +1,14 @@
---
title: liteyuki.message.on
order: 1
icon: laptop-code
category: API
---
### ***def*** `on_message(rule: Rule, priority: int, block: bool) -> Matcher`
### *func* `on_message(rule: Rule = empty_rule, priority: int = 0, block: bool = False) -> Matcher`
<details>
<summary>源代码</summary>
<summary> <b>源代码</b> </summary>
```python
def on_message(rule: Rule=Rule(), priority: int=0, block: bool=True) -> Matcher:
def on_message(rule: Rule=empty_rule, priority: int=0, block: bool=False) -> Matcher:
matcher = Matcher(rule, priority, block)
for i, m in enumerate(_matcher_list):
if m.priority < matcher.priority:
@ -25,15 +20,27 @@ def on_message(rule: Rule=Rule(), priority: int=0, block: bool=True) -> Matcher:
```
</details>
### ***var*** `current_priority = -1`
### *func* `on_keywords(keywords: list[str] = empty_rule, rule = 0, priority: int = False) -> Matcher`
<details>
<summary> <b>源代码</b> </summary>
### ***var*** `matcher = Matcher(rule, priority, block)`
```python
def on_keywords(keywords: list[str], rule=empty_rule, priority: int=0, block: bool=False) -> Matcher:
@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>
### ***var*** `_matcher_list = []`
### ***var*** `current_priority = matcher.priority`
- **类型**: `list[Matcher]`
### ***var*** `_queue = Queue()`
- **类型**: `Queue`

View File

@ -1,24 +1,98 @@
---
title: liteyuki.message.rule
order: 1
icon: laptop-code
category: API
---
### `@Rule`
### *async func* `empty_rule() -> bool`
### ***class*** `Rule`
### &emsp; ***def*** `__init__(self, handler: Optional[RuleHandler]) -> None`
&emsp;
<details>
<summary>源代码</summary>
<summary> <b>源代码</b> </summary>
```python
def __init__(self, handler: Optional[RuleHandler]=None):
@Rule
async def empty_rule(event: MessageEvent) -> bool:
return True
```
</details>
### `@Rule`
### *async func* `is_su_rule() -> bool`
<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)`
<details>
<summary> <b>源代码</b> </summary>
```python
def __init__(self, handler: RuleHandlerFunc):
self.handler = handler
```
</details>
### *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`
- **说明**: 规则函数签名

View File

@ -1,7 +1,3 @@
---
title: liteyuki.message.session
order: 1
icon: laptop-code
category: API
---