mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-07-27 16:21:28 +00:00
👷 update doc ci
This commit is contained in:
@ -1,20 +1,16 @@
|
||||
---
|
||||
sidebar_position: 1
|
||||
id: guide
|
||||
id: index
|
||||
slug: /guide
|
||||
|
||||
options:
|
||||
menu:
|
||||
weight: 10
|
||||
catogory: guide
|
||||
category: guide
|
||||
---
|
||||
|
||||
# 概览
|
||||
|
||||
<!-- :::tip 提示
|
||||
如果在阅读本文档时遇到难以理解的词汇,请随时查阅 [术语表](../glossary.md) 或使用 [Google 搜索](https://www.google.com/)。
|
||||
::: -->
|
||||
|
||||
:::tip 提示
|
||||
初次使用时可能会觉得这里的概览过于枯燥,可以先简单略读之后直接前往 [安装](./installation.md) 查看安装方法,并进行后续的基础使用教程。
|
||||
:::
|
@ -4,7 +4,7 @@ sidebar_position: 5
|
||||
options:
|
||||
menu:
|
||||
weight: 50
|
||||
catogory: guide
|
||||
category: guide
|
||||
---
|
||||
|
||||
# 基本配置
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"label": "编写插件",
|
||||
"position": 2
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
---
|
||||
sidebar_position: 4
|
||||
sidebar_position: 9
|
||||
|
||||
options:
|
||||
menu:
|
||||
weight: 140
|
||||
catogory: guide
|
||||
weight: 90
|
||||
category: guide
|
||||
---
|
||||
|
||||
# 事件处理
|
||||
@ -122,8 +122,8 @@ async def handle(bot: Bot):
|
||||
|
||||
参数分别为:
|
||||
|
||||
1. [nonebot.adapters.Bot](../api/adapters/#class-bot): 即事件上报连接对应的 Bot 对象,为 BaseBot 的子类。特别注意,此处的类型注释可以替换为指定的 Bot 类型,例如:`nonebot.adapters.cqhttp.Bot`,只有在上报事件的 Bot 类型与类型注释相符时才会执行该处理函数!可用于多平台进行不同的处理。
|
||||
2. [nonebot.adapters.Event](../api/adapters/#class-event): 即上报事件对象,可以获取到上报的所有信息。
|
||||
1. [nonebot.adapters.Bot](../api/adapters/README.md#class-bot): 即事件上报连接对应的 Bot 对象,为 BaseBot 的子类。特别注意,此处的类型注释可以替换为指定的 Bot 类型,例如:`nonebot.adapters.cqhttp.Bot`,只有在上报事件的 Bot 类型与类型注释相符时才会执行该处理函数!可用于多平台进行不同的处理。
|
||||
2. [nonebot.adapters.Event](../api/adapters/README.md#class-event): 即上报事件对象,可以获取到上报的所有信息。
|
||||
3. [state](../api/typing.md#t-state): 状态字典,可以存储任意的信息,其中还包含一些特殊的值以获取 NoneBot 内部处理时的一些信息,如:
|
||||
|
||||
- `state["_current_key"]`: 存储当前 `got` 获取的参数名
|
@ -1,10 +1,10 @@
|
||||
---
|
||||
sidebar_position: 3
|
||||
sidebar_position: 8
|
||||
|
||||
options:
|
||||
menu:
|
||||
weight: 130
|
||||
catogory: guide
|
||||
weight: 80
|
||||
category: guide
|
||||
---
|
||||
|
||||
# 注册事件响应器
|
||||
@ -50,7 +50,7 @@ async def get_weather(city: str):
|
||||
从这里开始,你需要对 Python 的 asyncio 编程有所了解,因为 NoneBot 是完全基于 asyncio 的,具体可以参考 [廖雪峰的 Python 教程](https://www.liaoxuefeng.com/wiki/1016959663602400/1017959540289152)
|
||||
:::
|
||||
|
||||
## [事件响应器](../../api/matcher.md)
|
||||
## [事件响应器](../api/matcher.md)
|
||||
|
||||
```python{5}
|
||||
from nonebot import on_command
|
||||
@ -81,11 +81,11 @@ weather = on_command("天气", rule=to_me(), permission=Permission(), priority=5
|
||||
- `on_message()` ~ `on("message")`: 消息事件响应器
|
||||
- `on_request()` ~ `on("request")`: 请求事件响应器
|
||||
- `on_notice()` ~ `on("notice")`: 通知事件响应器
|
||||
- `on_startswith(str)` ~ `on("message", startswith(str))`: 消息开头匹配响应器,参考 [startswith](../../api/rule.md#startswith-msg)
|
||||
- `on_endswith(str)` ~ `on("message", endswith(str))`: 消息结尾匹配响应器,参考 [endswith](../../api/rule.md#endswith-msg)
|
||||
- `on_keyword(set)` ~ `on("message", keyword(str))`: 消息关键词匹配响应器,参考 [keyword](../../api/rule.md#keyword-keywords)
|
||||
- `on_command(str|tuple)` ~ `on("message", command(str|tuple))`: 命令响应器,参考 [command](../../api/rule.md#command-cmds)
|
||||
- `on_regex(pattern_str)` ~ `on("message", regex(pattern_str))`: 正则匹配处理器,参考 [regex](../../api/rule.md#regex-regex-flags-0)
|
||||
- `on_startswith(str)` ~ `on("message", startswith(str))`: 消息开头匹配响应器,参考 [startswith](../api/rule.md#startswith-msg)
|
||||
- `on_endswith(str)` ~ `on("message", endswith(str))`: 消息结尾匹配响应器,参考 [endswith](../api/rule.md#endswith-msg)
|
||||
- `on_keyword(set)` ~ `on("message", keyword(str))`: 消息关键词匹配响应器,参考 [keyword](../api/rule.md#keyword-keywords)
|
||||
- `on_command(str|tuple)` ~ `on("message", command(str|tuple))`: 命令响应器,参考 [command](../api/rule.md#command-cmds)
|
||||
- `on_regex(pattern_str)` ~ `on("message", regex(pattern_str))`: 正则匹配处理器,参考 [regex](../api/rule.md#regex-regex-flags-0)
|
||||
|
||||
### 匹配规则 rule
|
||||
|
||||
@ -116,11 +116,11 @@ NoneBot 内置的事件响应器中,所有 `message` 类的事件响应器默
|
||||
|
||||
rule 的出现使得 nonebot 对事件的响应可以非常自由,nonebot 内置了一些规则:
|
||||
|
||||
- [startswith(msg)](../../api/rule.md#startswith-msg)
|
||||
- [endswith(msg)](../../api/rule.md#endswith-msg)
|
||||
- [keyword(\*keywords)](../../api/rule.md#keyword-keywords)
|
||||
- [command(\*cmds)](../../api/rule.md#command-cmds)
|
||||
- [regex(regex, flag)](../../api/rule.md#regex-regex-flags-0)
|
||||
- [startswith(msg)](../api/rule.md#startswith-msg)
|
||||
- [endswith(msg)](../api/rule.md#endswith-msg)
|
||||
- [keyword(\*keywords)](../api/rule.md#keyword-keywords)
|
||||
- [command(\*cmds)](../api/rule.md#command-cmds)
|
||||
- [regex(regex, flag)](../api/rule.md#regex-regex-flags-0)
|
||||
|
||||
以上规则都是返回类型为 `Rule` 的函数,`Rule` 由非负个 `RuleChecker` 组成,当所有 `RuleChecker` 返回 `True` 时匹配成功。这些 `Rule`, `RuleChecker` 的形式如下:
|
||||
|
@ -1,10 +1,10 @@
|
||||
---
|
||||
sidebar_position: 2
|
||||
sidebar_position: 7
|
||||
|
||||
options:
|
||||
menu:
|
||||
weight: 120
|
||||
catogory: guide
|
||||
weight: 70
|
||||
category: guide
|
||||
---
|
||||
|
||||
# 创建插件
|
@ -4,7 +4,7 @@ sidebar_position: 4
|
||||
options:
|
||||
menu:
|
||||
weight: 40
|
||||
catogory: guide
|
||||
category: guide
|
||||
---
|
||||
|
||||
# 创建一个完整的项目
|
@ -99,4 +99,3 @@ async def feishu_helper(bot: FeishuBot, event: MessageEvent, state: T_State):
|
||||
以上代码注册了一个对飞书平台适用的`say`指令,并会提取`/say`之后的内容发送到事件所对应的群或私聊。
|
||||
|
||||
大功告成!现在可以试试向机器人发送类似`/say Hello, Feishu!`的消息进行测试了。
|
||||
|
||||
|
@ -4,7 +4,7 @@ sidebar_position: 3
|
||||
options:
|
||||
menu:
|
||||
weight: 30
|
||||
catogory: guide
|
||||
category: guide
|
||||
---
|
||||
|
||||
# 开始使用
|
@ -4,7 +4,7 @@ sidebar_position: 2
|
||||
options:
|
||||
menu:
|
||||
weight: 20
|
||||
catogory: guide
|
||||
category: guide
|
||||
---
|
||||
|
||||
# 安装
|
||||
@ -115,7 +115,7 @@ nb plugin install <plugin-name>
|
||||
|
||||
### 其他插件
|
||||
|
||||
还有更多的插件在 [这里](/store.html) 等着你发现~
|
||||
还有更多的插件在 [这里](/store) 等着你发现~
|
||||
|
||||
## 安装开发环境(可选)
|
||||
|
@ -1,10 +1,10 @@
|
||||
---
|
||||
sidebar_position: 1
|
||||
sidebar_position: 6
|
||||
|
||||
options:
|
||||
menu:
|
||||
weight: 110
|
||||
catogory: guide
|
||||
weight: 60
|
||||
category: guide
|
||||
---
|
||||
|
||||
# 加载插件
|
||||
@ -42,7 +42,7 @@ if __name__ == "__main__":
|
||||
- 命令 `say`:可由**superuser**使用,可以将消息内容由特殊纯文本转为富文本
|
||||
- 命令 `echo`:可由任何人使用,将消息原样返回
|
||||
|
||||
以上命令均需要指定机器人,即私聊、群聊内@机器人、群聊内称呼机器人昵称。参考 [Rule: to_me](../../api/rule.md#to-me)
|
||||
以上命令均需要指定机器人,即私聊、群聊内@机器人、群聊内称呼机器人昵称。参考 [Rule: to_me](../api/rule.md#to-me)
|
||||
|
||||
## 加载插件目录
|
||||
|
||||
@ -71,7 +71,7 @@ if __name__ == "__main__":
|
||||
:::
|
||||
|
||||
:::danger 警告
|
||||
插件间不应该存在过多的耦合,如果确实需要导入某个插件内的数据,可以参考 [进阶-跨插件访问](../../advanced/export-and-require.md)
|
||||
插件间不应该存在过多的耦合,如果确实需要导入某个插件内的数据,可以参考 [进阶-跨插件访问](../advanced/export-and-require.md)
|
||||
:::
|
||||
|
||||
## 加载单个插件
|
@ -133,11 +133,11 @@ pip install nonebot-adapter-mirai
|
||||
from nonebot.adapters.mirai import Bot
|
||||
|
||||
nonebot.init()
|
||||
nonebot.get_driver().register_adapter('mirai',
|
||||
Bot,
|
||||
nonebot.get_driver().register_adapter('mirai',
|
||||
Bot,
|
||||
qq=12345678)
|
||||
# qq参数需要填在mah中登录的qq, 如果需要多个帐号, 可以填写类似于 [123456,789100] 的数组形式
|
||||
|
||||
|
||||
nonebot.load_builtin_plugins() # 加载 nonebot 内置插件
|
||||
nonebot.run()
|
||||
```
|
||||
@ -246,7 +246,7 @@ async def _echo(bot: Bot, event: MessageEvent):
|
||||
|
||||
它具有两种行为
|
||||
|
||||
- 在指定机器人,即私聊、群聊内@机器人、群聊内称呼机器人昵称的情况下 (即 [Rule: to_me](../api/rule.md#to-me)), 如果消息内包含 `reply` 字段, 则该消息会被机器人重复一次
|
||||
- 在指定机器人,即私聊、群聊内@机器人、群聊内称呼机器人昵称的情况下 (即 [Rule: to_me](../api/rule.md#to_me)), 如果消息内包含 `reply` 字段, 则该消息会被机器人重复一次
|
||||
|
||||
- 在执行指令`miecho xxx`时, 机器人会发送回参数`xxx`
|
||||
|
||||
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"label": "开始",
|
||||
"position": 1
|
||||
}
|
Reference in New Issue
Block a user