mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-07-17 03:20:54 +00:00
📝 Docs: 升级新版 NonePress 主题 (#2375)
This commit is contained in:
@ -4,14 +4,13 @@ description: 使用平台接口,完成更多功能
|
||||
|
||||
options:
|
||||
menu:
|
||||
weight: 50
|
||||
category: appendices
|
||||
- category: appendices
|
||||
weight: 50
|
||||
---
|
||||
|
||||
# 使用平台接口
|
||||
|
||||
import Messenger from "@site/src/components/Messenger";
|
||||
import MarkdownText from "!!raw-loader!./assets/console-markdown.txt";
|
||||
import Messenger from "@/components/Messenger";
|
||||
|
||||
在 NoneBot 中,除了使用事件响应器操作发送文本消息外,我们还可以直接通过使用协议适配器提供的方法来使用平台特定的接口,完成发送特殊消息、获取信息等其他平台提供的功能。同时,在部分无法使用事件响应器的情况中,例如[定时任务](../best-practice/scheduler.md),我们也可以使用平台接口来完成需要的功能。
|
||||
|
||||
@ -19,7 +18,7 @@ import MarkdownText from "!!raw-loader!./assets/console-markdown.txt";
|
||||
|
||||
在之前的章节中,我们介绍了如何向用户发送文本消息以及[如何处理平台消息](../tutorial/message.md),现在我们来向用户发送平台特殊消息。
|
||||
|
||||
:::warning 注意
|
||||
:::caution 注意
|
||||
在以下的示例中,我们将使用 `Console` 协议适配器来演示如何发送平台消息。在实际使用中,你需要确保你使用的**消息序列类型**与你所要发送的**平台类型**一致。
|
||||
:::
|
||||
|
||||
@ -49,7 +48,11 @@ async def got_location(location: str = ArgPlainText()):
|
||||
{ position: "right", msg: "/天气" },
|
||||
{ position: "left", msg: "❓请输入地名" },
|
||||
{ position: "right", msg: "北京" },
|
||||
{ position: "left", msg: MarkdownText },
|
||||
{
|
||||
position: "left",
|
||||
monospace: true,
|
||||
msg: "┏━━━━━━━━━━━━━━━━┓\n┃ 北京 ┃\n┗━━━━━━━━━━━━━━━━┛\n• 今天\n⛅ 多云 20℃~24℃",
|
||||
},
|
||||
]}
|
||||
/>
|
||||
|
||||
@ -100,7 +103,7 @@ result = await bot.get_user_info(user_id=12345678)
|
||||
result = await bot.call_api("get_user_info", user_id=12345678)
|
||||
```
|
||||
|
||||
:::warning 注意
|
||||
:::caution 注意
|
||||
实际可以使用的 API 以及参数取决于平台提供的接口以及协议适配器的实现,请参考协议适配器以及平台文档。
|
||||
:::
|
||||
|
||||
|
@ -1,6 +0,0 @@
|
||||
┏━━━━━━━━━━━━━━━━┓
|
||||
┃ 北京 ┃
|
||||
┗━━━━━━━━━━━━━━━━┛
|
||||
|
||||
• 今天
|
||||
⛅ 多云 20℃~24℃
|
@ -4,8 +4,8 @@ description: 读取用户配置来控制插件行为
|
||||
|
||||
options:
|
||||
menu:
|
||||
weight: 10
|
||||
category: appendices
|
||||
- category: appendices
|
||||
weight: 10
|
||||
---
|
||||
|
||||
# 配置
|
||||
@ -62,7 +62,7 @@ export CUSTOM_CONFIG="config in environment variables"
|
||||
|
||||
那最终 NoneBot 所读取的内容为环境变量中的内容,即 `config in environment variables`。
|
||||
|
||||
:::warning 注意
|
||||
:::caution 注意
|
||||
NoneBot 不会自发读取未被定义的配置项的环境变量,如果需要读取某一环境变量需要在 dotenv 配置文件中进行声明。
|
||||
:::
|
||||
|
||||
|
@ -4,8 +4,8 @@ description: 记录与控制日志
|
||||
|
||||
options:
|
||||
menu:
|
||||
weight: 70
|
||||
category: appendices
|
||||
- category: appendices
|
||||
weight: 70
|
||||
---
|
||||
|
||||
# 日志
|
||||
|
@ -4,8 +4,8 @@ description: 根据事件类型进行不同的处理
|
||||
|
||||
options:
|
||||
menu:
|
||||
weight: 80
|
||||
category: appendices
|
||||
- category: appendices
|
||||
weight: 80
|
||||
---
|
||||
|
||||
# 事件类型与重载
|
||||
@ -28,7 +28,7 @@ async def got_location(event: MessageEvent, location: str = ArgPlainText()):
|
||||
|
||||
在上面的代码中,我们获取了 `Console` 协议适配器的消息事件提供的发送时间 `time` 属性。
|
||||
|
||||
:::warning 注意
|
||||
:::caution 注意
|
||||
如果**基类**就能满足你的需求,那么就**不要修改**事件参数类型注解,这样可以使你的代码更加**通用**,可以在更多平台上运行。如何根据不同平台事件类型进行不同的处理,我们将在[重载](#重载)一节中介绍。
|
||||
:::
|
||||
|
||||
@ -63,7 +63,7 @@ async def handle_onebot(bot: OneBot):
|
||||
await bot.send_group_message(group_id=123123, message="OneBot")
|
||||
```
|
||||
|
||||
:::warning 注意
|
||||
:::caution 注意
|
||||
重载机制对所有的参数类型注解都有效,因此,依赖注入也可以使用这个特性来对不同的返回值进行处理。
|
||||
|
||||
但 Bot、Event 和 Matcher 三者的参数类型注解具有最高检查优先级,如果三者任一类型注解不匹配,那么其他依赖注入将不会执行(如:`Depends`)。
|
||||
|
@ -4,8 +4,8 @@ description: 控制事件响应器的权限
|
||||
|
||||
options:
|
||||
menu:
|
||||
weight: 60
|
||||
category: appendices
|
||||
- category: appendices
|
||||
weight: 60
|
||||
---
|
||||
|
||||
# 权限控制
|
||||
|
@ -4,8 +4,8 @@ description: 自定义响应规则
|
||||
|
||||
options:
|
||||
menu:
|
||||
weight: 20
|
||||
category: appendices
|
||||
- category: appendices
|
||||
weight: 20
|
||||
---
|
||||
|
||||
# 响应规则
|
||||
|
@ -4,8 +4,8 @@ description: 更灵活的会话控制
|
||||
|
||||
options:
|
||||
menu:
|
||||
weight: 30
|
||||
category: appendices
|
||||
- category: appendices
|
||||
weight: 30
|
||||
---
|
||||
|
||||
# 会话控制
|
||||
@ -322,7 +322,7 @@ async def _(matcher: Matcher):
|
||||
matcher.stop_propagation()
|
||||
```
|
||||
|
||||
:::warning 注意
|
||||
:::caution 注意
|
||||
`stop_propagation` 操作是实例方法,需要先通过依赖注入获取事件响应器实例再进行调用。
|
||||
:::
|
||||
|
||||
|
@ -4,8 +4,8 @@ description: 会话状态信息
|
||||
|
||||
options:
|
||||
menu:
|
||||
weight: 40
|
||||
category: appendices
|
||||
- category: appendices
|
||||
weight: 40
|
||||
---
|
||||
|
||||
# 会话状态
|
||||
|
Reference in New Issue
Block a user