diff --git a/README.md b/README.md index 07724b1a..d2afe009 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ NoneBot2 的驱动框架 `Driver` 以及通信协议 `Adapter` 均可**自定义 - [OneBot(CQHTTP) 协议](https://github.com/howmanybots/onebot/blob/master/README.md) (QQ 等) - [Mirai-API-HTTP 协议](https://github.com/project-mirai/mirai-api-http) -- [钉钉](https://ding-doc.dingtalk.com/document#/org-dev-guide/elzz1p) _开发中_ +- [钉钉](https://ding-doc.dingtalk.com/document#/org-dev-guide/elzz1p) - [Telegram](https://core.telegram.org/bots/api) _计划中_ ## 即刻开始 diff --git a/archive/2.0.0a9/README.md b/archive/2.0.0a9.post1/README.md similarity index 93% rename from archive/2.0.0a9/README.md rename to archive/2.0.0a9.post1/README.md index 78cb0fc4..891eb832 100644 --- a/archive/2.0.0a9/README.md +++ b/archive/2.0.0a9.post1/README.md @@ -1,7 +1,7 @@ --- home: true heroImage: /logo.png -tagline: An asynchronous bot framework. +tagline: 跨平台 Python 异步 QQ 机器人框架 actionText: 开始使用 actionLink: guide/ features: diff --git a/archive/2.0.0a9/advanced/README.md b/archive/2.0.0a9.post1/advanced/README.md similarity index 100% rename from archive/2.0.0a9/advanced/README.md rename to archive/2.0.0a9.post1/advanced/README.md diff --git a/archive/2.0.0a9/advanced/export-and-require.md b/archive/2.0.0a9.post1/advanced/export-and-require.md similarity index 100% rename from archive/2.0.0a9/advanced/export-and-require.md rename to archive/2.0.0a9.post1/advanced/export-and-require.md diff --git a/archive/2.0.0a9/advanced/overloaded-handlers.md b/archive/2.0.0a9.post1/advanced/overloaded-handlers.md similarity index 100% rename from archive/2.0.0a9/advanced/overloaded-handlers.md rename to archive/2.0.0a9.post1/advanced/overloaded-handlers.md diff --git a/archive/2.0.0a9/advanced/permission.md b/archive/2.0.0a9.post1/advanced/permission.md similarity index 100% rename from archive/2.0.0a9/advanced/permission.md rename to archive/2.0.0a9.post1/advanced/permission.md diff --git a/archive/2.0.0a9/advanced/publish-plugin.md b/archive/2.0.0a9.post1/advanced/publish-plugin.md similarity index 100% rename from archive/2.0.0a9/advanced/publish-plugin.md rename to archive/2.0.0a9.post1/advanced/publish-plugin.md diff --git a/archive/2.0.0a9.post1/advanced/runtime-hook.md b/archive/2.0.0a9.post1/advanced/runtime-hook.md new file mode 100644 index 00000000..935d3ce8 --- /dev/null +++ b/archive/2.0.0a9.post1/advanced/runtime-hook.md @@ -0,0 +1 @@ +# 钩子函数 diff --git a/archive/2.0.0a9/advanced/scheduler.md b/archive/2.0.0a9.post1/advanced/scheduler.md similarity index 93% rename from archive/2.0.0a9/advanced/scheduler.md rename to archive/2.0.0a9.post1/advanced/scheduler.md index 86280b5f..c58062f1 100644 --- a/archive/2.0.0a9/advanced/scheduler.md +++ b/archive/2.0.0a9.post1/advanced/scheduler.md @@ -4,7 +4,7 @@ > Advanced Python Scheduler (APScheduler) is a Python library that lets you schedule your Python code to be executed later, either just once or periodically. You can add new jobs or remove old ones on the fly as you please. If you store your jobs in a database, they will also survive scheduler restarts and maintain their state. When the scheduler is restarted, it will then run all the jobs it should have run while it was offline. -## 从 v1 迁移 +## 从 NoneBot v1 迁移 `APScheduler` 作为 `nonebot` v1 的可选依赖,为众多 bot 提供了方便的定时任务功能。`nonebot2` 已将 `APScheduler` 独立为 `nonebot_plugin_apscheduler` 插件,你可以在 [插件广场](https://v2.nonebot.dev/plugin-store.html) 中找到它。 @@ -21,7 +21,7 @@ nb plugin install nonebot_plugin_apscheduler ``` :::tip 提示 -`nb-cli` 默认通过 `pypi` 安装,你可以使用 `-i [mirror]` 或 `--index [mirror]` 来使用镜像源安装。 +`nb-cli` 默认通过 `pypi` 安装,你可以添加命令参数 `-i [mirror]` 或 `--index [mirror]` 以使用镜像源安装。 ::: ### 通过 poetry @@ -96,10 +96,14 @@ scheduler = require('nonebot_plugin_apscheduler').scheduler 对于大多数情况,我们需要在 `nonebot2` 项目被启动时启动定时任务,则此处设为 `true` +##### 在 `.env` 中添加 + ```bash APSCHEDULER_AUTOSTART=true ``` +##### 在 `bot.py` 中添加 + ```python nonebot.init(apscheduler_autostart=True) ``` @@ -116,10 +120,14 @@ nonebot.init(apscheduler_autostart=True) > 官方文档在绝大多数时候能提供最准确和最具时效性的指南 +##### 在 `.env` 中添加 + ```bash APSCHEDULER_CONFIG={"apscheduler.timezone": "Asia/Shanghai"} ``` +##### 在 `bot.py` 中添加 + ```python nonebot.init(apscheduler_config={ "apscheduler.timezone": "Asia/Shanghai" diff --git a/archive/2.0.0a9/api/README.md b/archive/2.0.0a9.post1/api/README.md similarity index 100% rename from archive/2.0.0a9/api/README.md rename to archive/2.0.0a9.post1/api/README.md diff --git a/archive/2.0.0a9/api/adapters/README.md b/archive/2.0.0a9.post1/api/adapters/README.md similarity index 100% rename from archive/2.0.0a9/api/adapters/README.md rename to archive/2.0.0a9.post1/api/adapters/README.md diff --git a/archive/2.0.0a9/api/adapters/cqhttp.md b/archive/2.0.0a9.post1/api/adapters/cqhttp.md similarity index 96% rename from archive/2.0.0a9/api/adapters/cqhttp.md rename to archive/2.0.0a9.post1/api/adapters/cqhttp.md index ca5d91cb..5982e72e 100644 --- a/archive/2.0.0a9/api/adapters/cqhttp.md +++ b/archive/2.0.0a9.post1/api/adapters/cqhttp.md @@ -9,6 +9,23 @@ sidebarDepth: 0 协议详情请看: [CQHTTP](https://github.com/howmanybots/onebot/blob/master/README.md) | [OneBot](https://github.com/howmanybots/onebot/blob/master/README.md) +# NoneBot.adapters.cqhttp.config 模块 + + +## _class_ `Config` + +CQHTTP 配置类 + + +* **配置项** + + + * `access_token` / `cqhttp_access_token`: CQHTTP 协议授权令牌 + + + * `secret` / `cqhttp_secret`: CQHTTP HTTP 上报数据签名口令 + + # NoneBot.adapters.cqhttp.utils 模块 diff --git a/archive/2.0.0a9/api/adapters/ding.md b/archive/2.0.0a9.post1/api/adapters/ding.md similarity index 95% rename from archive/2.0.0a9/api/adapters/ding.md rename to archive/2.0.0a9.post1/api/adapters/ding.md index c64125ac..ed2a2d38 100644 --- a/archive/2.0.0a9/api/adapters/ding.md +++ b/archive/2.0.0a9.post1/api/adapters/ding.md @@ -9,6 +9,23 @@ sidebarDepth: 0 协议详情请看: [钉钉文档](https://ding-doc.dingtalk.com/document#/org-dev-guide/elzz1p) +# NoneBot.adapters.ding.config 模块 + + +## _class_ `Config` + +钉钉配置类 + + +* **配置项** + + + * `access_token` / `ding_access_token`: 钉钉令牌 + + + * `secret` / `ding_secret`: 钉钉 HTTP 上报数据签名口令 + + # NoneBot.adapters.ding.exception 模块 diff --git a/archive/2.0.0a9/api/adapters/mirai.md b/archive/2.0.0a9.post1/api/adapters/mirai.md similarity index 99% rename from archive/2.0.0a9/api/adapters/mirai.md rename to archive/2.0.0a9.post1/api/adapters/mirai.md index 4b568152..b627f72d 100644 --- a/archive/2.0.0a9/api/adapters/mirai.md +++ b/archive/2.0.0a9.post1/api/adapters/mirai.md @@ -21,6 +21,26 @@ Mirai-API-HTTP 的适配器以 [AGPLv3许可](https://opensource.org/licenses/AG 这意味着在使用该适配器时需要 **以该许可开源您的完整程序代码** ::: +# NoneBot.adapters.mirai.config 模块 + + +## _class_ `Config` + +Mirai 配置类 + + +* **必填** + + + * `auth_key` / `mirai_auth_key`: mirai-api-http 的 auth_key + + + * `mirai_host`: mirai-api-http 的地址 + + + * `mirai_port`: mirai-api-http 的端口 + + # NoneBot.adapters.mirai.bot 模块 @@ -690,28 +710,6 @@ mirai-api-http 正向 Websocket 协议 Bot 适配。 * `qq: int`: 要使用的Bot的QQ号 **注意: 在使用正向Websocket时必须指定该值!** -# NoneBot.adapters.mirai.config 模块 - - -## _class_ `Config` - -基类:`pydantic.main.BaseModel` - -Mirai 配置类 - - -* **必填** - - - * `mirai_auth_key`: mirai-api-http的auth_key - - - * `mirai_host`: mirai-api-http的地址 - - - * `mirai_port`: mirai-api-http的端口 - - # NoneBot.adapters.mirai.message 模块 diff --git a/archive/2.0.0a9/api/config.md b/archive/2.0.0a9.post1/api/config.md similarity index 100% rename from archive/2.0.0a9/api/config.md rename to archive/2.0.0a9.post1/api/config.md diff --git a/archive/2.0.0a9/api/drivers/README.md b/archive/2.0.0a9.post1/api/drivers/README.md similarity index 98% rename from archive/2.0.0a9/api/drivers/README.md rename to archive/2.0.0a9.post1/api/drivers/README.md index 77485ed2..673697b4 100644 --- a/archive/2.0.0a9/api/drivers/README.md +++ b/archive/2.0.0a9.post1/api/drivers/README.md @@ -120,7 +120,7 @@ Driver 基类。将后端框架封装,以满足适配器使用。 -### `register_adapter(name, adapter)` +### `register_adapter(name, adapter, **kwargs)` * **说明** diff --git a/archive/2.0.0a9/api/drivers/fastapi.md b/archive/2.0.0a9.post1/api/drivers/fastapi.md similarity index 66% rename from archive/2.0.0a9/api/drivers/fastapi.md rename to archive/2.0.0a9.post1/api/drivers/fastapi.md index edd8e474..fba15c68 100644 --- a/archive/2.0.0a9/api/drivers/fastapi.md +++ b/archive/2.0.0a9.post1/api/drivers/fastapi.md @@ -10,6 +10,58 @@ sidebarDepth: 0 后端使用方法请参考: [FastAPI 文档](https://fastapi.tiangolo.com/) +## _class_ `Config` + +基类:`pydantic.env_settings.BaseSettings` + +FastAPI 驱动框架设置,详情参考 FastAPI 文档 + + +### `fastapi_openapi_url` + + +* **类型** + + `Optional[str]` + + + +* **说明** + + openapi.json 地址,默认为 None 即关闭 + + + +### `fastapi_docs_url` + + +* **类型** + + `Optional[str]` + + + +* **说明** + + swagger 地址,默认为 None 即关闭 + + + +### `fastapi_redoc_url` + + +* **类型** + + `Optional[str]` + + + +* **说明** + + redoc 地址,默认为 None 即关闭 + + + ## _class_ `Driver` 基类:[`nonebot.drivers.Driver`](README.md#nonebot.drivers.Driver) diff --git a/archive/2.0.0a9/api/exception.md b/archive/2.0.0a9.post1/api/exception.md similarity index 100% rename from archive/2.0.0a9/api/exception.md rename to archive/2.0.0a9.post1/api/exception.md diff --git a/archive/2.0.0a9/api/log.md b/archive/2.0.0a9.post1/api/log.md similarity index 100% rename from archive/2.0.0a9/api/log.md rename to archive/2.0.0a9.post1/api/log.md diff --git a/archive/2.0.0a9/api/matcher.md b/archive/2.0.0a9.post1/api/matcher.md similarity index 100% rename from archive/2.0.0a9/api/matcher.md rename to archive/2.0.0a9.post1/api/matcher.md diff --git a/archive/2.0.0a9/api/message.md b/archive/2.0.0a9.post1/api/message.md similarity index 100% rename from archive/2.0.0a9/api/message.md rename to archive/2.0.0a9.post1/api/message.md diff --git a/archive/2.0.0a9/api/nonebot.md b/archive/2.0.0a9.post1/api/nonebot.md similarity index 100% rename from archive/2.0.0a9/api/nonebot.md rename to archive/2.0.0a9.post1/api/nonebot.md diff --git a/archive/2.0.0a9/api/permission.md b/archive/2.0.0a9.post1/api/permission.md similarity index 100% rename from archive/2.0.0a9/api/permission.md rename to archive/2.0.0a9.post1/api/permission.md diff --git a/archive/2.0.0a9/api/plugin.md b/archive/2.0.0a9.post1/api/plugin.md similarity index 94% rename from archive/2.0.0a9/api/plugin.md rename to archive/2.0.0a9.post1/api/plugin.md index 960521da..1d134c52 100644 --- a/archive/2.0.0a9/api/plugin.md +++ b/archive/2.0.0a9.post1/api/plugin.md @@ -960,7 +960,7 @@ def something_else(): -### `on_startswith(msg, rule=None, **kwargs)` +### `on_startswith(msg, **kwargs)` * **说明** @@ -1007,7 +1007,7 @@ def something_else(): -### `on_endswith(msg, rule=None, **kwargs)` +### `on_endswith(msg, **kwargs)` * **说明** @@ -1054,7 +1054,7 @@ def something_else(): -### `on_keyword(keywords, rule=None, **kwargs)` +### `on_keyword(keywords, **kwargs)` * **说明** @@ -1101,7 +1101,7 @@ def something_else(): -### `on_command(cmd, rule=None, aliases=None, **kwargs)` +### `on_command(cmd, aliases=None, **kwargs)` * **说明** @@ -1118,12 +1118,12 @@ def something_else(): * `cmd: Union[str, Tuple[str, ...]]`: 指定命令内容 - * `rule: Optional[Union[Rule, T_RuleChecker]]`: 事件响应规则 - - * `aliases: Optional[Set[Union[str, Tuple[str, ...]]]]`: 命令别名 + * `rule: Optional[Union[Rule, T_RuleChecker]]`: 事件响应规则 + + * `permission: Optional[Permission]`: 事件响应权限 @@ -1153,64 +1153,64 @@ def something_else(): -### `on_shell_command(cmd, rule=None, aliases=None, parser=None, **kwargs)` +### `on_shell_command(cmd, aliases=None, parser=None, **kwargs)` * **说明** + 注册一个支持 `shell_like` 解析参数的命令消息事件响应器。 -注册一个支持 `shell_like` 解析参数的命令消息事件响应器。 + 与普通的 `on_command` 不同的是,在添加 `parser` 参数时, 响应器会自动处理消息。 -与普通的 `on_command` 不同的是,在添加 `parser` 参数时, 响应器会自动处理消息。 + 并将用户输入的原始参数列表保存在 `state["argv"]`, `parser` 处理的参数保存在 `state["args"]` 中 -并将用户输入的原始参数列表保存在 `state["argv"]`, `parser` 处理的参数保存在 `state["args"]` 中 * **参数** + + * `cmd: Union[str, Tuple[str, ...]]`: 指定命令内容 -* `cmd: Union[str, Tuple[str, ...]]`: 指定命令内容 + * `aliases: Optional[Set[Union[str, Tuple[str, ...]]]]`: 命令别名 -* `rule: Optional[Union[Rule, T_RuleChecker]]`: 事件响应规则 + * `parser: Optional[ArgumentParser]`: `nonebot.rule.ArgumentParser` 对象 -* `aliases: Optional[Set[Union[str, Tuple[str, ...]]]]`: 命令别名 + * `rule: Optional[Union[Rule, T_RuleChecker]]`: 事件响应规则 -* `parser: Optional[ArgumentParser]`: `nonebot.rule.ArgumentParser` 对象 + * `permission: Optional[Permission]`: 事件响应权限 -* `permission: Optional[Permission]`: 事件响应权限 + * `handlers: Optional[List[T_Handler]]`: 事件处理函数列表 -* `handlers: Optional[List[T_Handler]]`: 事件处理函数列表 + * `temp: bool`: 是否为临时事件响应器(仅执行一次) -* `temp: bool`: 是否为临时事件响应器(仅执行一次) + * `priority: int`: 事件响应器优先级 -* `priority: int`: 事件响应器优先级 + * `block: bool`: 是否阻止事件向更低优先级传递 -* `block: bool`: 是否阻止事件向更低优先级传递 + * `state: Optional[T_State]`: 默认 state -* `state: Optional[T_State]`: 默认 state + * `state_factory: Optional[T_StateFactory]`: 默认 state 的工厂函数 -* `state_factory: Optional[T_StateFactory]`: 默认 state 的工厂函数 - * **返回** + + * `Type[Matcher]` -* `Type[Matcher]` - -### `on_regex(pattern, flags=0, rule=None, **kwargs)` +### `on_regex(pattern, flags=0, **kwargs)` * **说明** diff --git a/archive/2.0.0a9/api/rule.md b/archive/2.0.0a9.post1/api/rule.md similarity index 100% rename from archive/2.0.0a9/api/rule.md rename to archive/2.0.0a9.post1/api/rule.md diff --git a/archive/2.0.0a9/api/typing.md b/archive/2.0.0a9.post1/api/typing.md similarity index 100% rename from archive/2.0.0a9/api/typing.md rename to archive/2.0.0a9.post1/api/typing.md diff --git a/archive/2.0.0a9/api/utils.md b/archive/2.0.0a9.post1/api/utils.md similarity index 100% rename from archive/2.0.0a9/api/utils.md rename to archive/2.0.0a9.post1/api/utils.md diff --git a/archive/2.0.0a9/guide/README.md b/archive/2.0.0a9.post1/guide/README.md similarity index 99% rename from archive/2.0.0a9/guide/README.md rename to archive/2.0.0a9.post1/guide/README.md index 4326ac1b..8aa8d271 100644 --- a/archive/2.0.0a9/guide/README.md +++ b/archive/2.0.0a9.post1/guide/README.md @@ -8,8 +8,6 @@ 初次使用时可能会觉得这里的概览过于枯燥,可以先简单略读之后直接前往 [安装](./installation.md) 查看安装方法,并进行后续的基础使用教程。 ::: -## 简介 - NoneBot2 是一个可扩展的 Python 异步机器人框架,它会对机器人收到的事件进行解析和处理,并以插件化的形式,按优先级分发给事件所对应的事件响应器,来完成具体的功能。 除了起到解析事件的作用,NoneBot 还为插件提供了大量实用的预设操作和权限控制机制。对于命令处理,它更是提供了完善且易用的会话机制和内部调用机制,以分别适应命令的连续交互和插件内部功能复用等需求。 diff --git a/archive/2.0.0a9/guide/basic-configuration.md b/archive/2.0.0a9.post1/guide/basic-configuration.md similarity index 93% rename from archive/2.0.0a9/guide/basic-configuration.md rename to archive/2.0.0a9.post1/guide/basic-configuration.md index 84ed8fe0..4bb33f4f 100644 --- a/archive/2.0.0a9/guide/basic-configuration.md +++ b/archive/2.0.0a9.post1/guide/basic-configuration.md @@ -2,7 +2,7 @@ 到目前为止我们还在使用 NoneBot 的默认行为,在开始编写自己的插件之前,我们先尝试在配置文件上动动手脚,让 NoneBot 表现出不同的行为。 -在上一章节中,我们创建了默认的项目结构,其中 `.env`, `.env.*` 均为项目的配置文件,下面将介绍几种 NoneBot 配置方式。 +在上一章节中,我们创建了默认的项目结构,其中 `.env` 和 `.env.*` 均为项目的配置文件,下面将介绍几种 NoneBot 配置方式。 :::danger 警告 请勿将敏感信息写入配置文件并提交至开源仓库! @@ -83,4 +83,4 @@ config.custom_config4 = "new config after init" ## 优先级 -`bot.py init` > `system env` > `env file` +`bot.py` 文件( `nonebot.init` ) > 系统环境变量 > `.env` `.env.*` 文件 diff --git a/archive/2.0.0a9/guide/cqhttp-guide.md b/archive/2.0.0a9.post1/guide/cqhttp-guide.md similarity index 100% rename from archive/2.0.0a9/guide/cqhttp-guide.md rename to archive/2.0.0a9.post1/guide/cqhttp-guide.md diff --git a/archive/2.0.0a9/guide/creating-a-handler.md b/archive/2.0.0a9.post1/guide/creating-a-handler.md similarity index 100% rename from archive/2.0.0a9/guide/creating-a-handler.md rename to archive/2.0.0a9.post1/guide/creating-a-handler.md diff --git a/archive/2.0.0a9/guide/creating-a-matcher.md b/archive/2.0.0a9.post1/guide/creating-a-matcher.md similarity index 100% rename from archive/2.0.0a9/guide/creating-a-matcher.md rename to archive/2.0.0a9.post1/guide/creating-a-matcher.md diff --git a/archive/2.0.0a9/guide/creating-a-plugin.md b/archive/2.0.0a9.post1/guide/creating-a-plugin.md similarity index 100% rename from archive/2.0.0a9/guide/creating-a-plugin.md rename to archive/2.0.0a9.post1/guide/creating-a-plugin.md diff --git a/archive/2.0.0a9/guide/creating-a-project.md b/archive/2.0.0a9.post1/guide/creating-a-project.md similarity index 90% rename from archive/2.0.0a9/guide/creating-a-project.md rename to archive/2.0.0a9.post1/guide/creating-a-project.md index 5933b5fa..7c488a41 100644 --- a/archive/2.0.0a9/guide/creating-a-project.md +++ b/archive/2.0.0a9.post1/guide/creating-a-project.md @@ -34,18 +34,18 @@ AweSome-Bot ## 启动 Bot -如果你使用 `nb-cli` +通过 `nb-cli` ```bash nb run [--file=bot.py] [--app=app] ``` -或者使用 +或 ```bash python bot.py ``` :::tip 提示 -如果在 bot 入口文件内定义了 asgi server, `nb-cli` 将会为你启动**冷重载模式** +如果在 bot 入口文件内定义了 asgi server, `nb-cli` 将会为你启动**冷重载模式**(当文件发生变动时自动重启 NoneBot 实例) ::: diff --git a/archive/2.0.0a9/guide/ding-guide.md b/archive/2.0.0a9.post1/guide/ding-guide.md similarity index 93% rename from archive/2.0.0a9/guide/ding-guide.md rename to archive/2.0.0a9.post1/guide/ding-guide.md index c23c6827..ee9449ba 100644 --- a/archive/2.0.0a9/guide/ding-guide.md +++ b/archive/2.0.0a9.post1/guide/ding-guide.md @@ -1,9 +1,9 @@ # 钉钉机器人使用指南 -基于企业机器人的outgoing(回调)机制,用户@机器人之后,钉钉会将消息内容POST到开发者的消息接收地址。开发者解析出消息内容、发送者身份,根据企业的业务逻辑,组装响应的消息内容返回,钉钉会将响应内容发送到群里。 +基于企业机器人的 outgoing(回调)机制,用户@机器人之后,钉钉会将消息内容 POST 到开发者的消息接收地址。开发者解析出消息内容、发送者身份,根据企业的业务逻辑,组装响应的消息内容返回,钉钉会将响应内容发送到群里。 ::: warning 只有企业内部机器人支持接收消息 -普通的机器人尚不支持应答机制,该机制指的是群里成员在聊天@机器人的时候,钉钉回调指定的服务地址,即Outgoing机器人。 +普通的机器人尚不支持应答机制,该机制指的是群里成员在聊天@机器人的时候,钉钉回调指定的服务地址,即 Outgoing 机器人。 ::: 首先你需要有钉钉机器人的相关概念,请参阅相关文档: diff --git a/archive/2.0.0a9/guide/end-or-start.md b/archive/2.0.0a9.post1/guide/end-or-start.md similarity index 100% rename from archive/2.0.0a9/guide/end-or-start.md rename to archive/2.0.0a9.post1/guide/end-or-start.md diff --git a/archive/2.0.0a9/guide/getting-started.md b/archive/2.0.0a9.post1/guide/getting-started.md similarity index 91% rename from archive/2.0.0a9/guide/getting-started.md rename to archive/2.0.0a9.post1/guide/getting-started.md index edb898a3..f5e61215 100644 --- a/archive/2.0.0a9/guide/getting-started.md +++ b/archive/2.0.0a9.post1/guide/getting-started.md @@ -1,16 +1,16 @@ # 开始使用 -一切都安装成功后,你就已经做好了进行简单配置以运行一个最小的 NoneBot 实例的准备。 +一切都安装成功后,你就已经做好了进行简单配置以运行一个最小的 NoneBot 实例的准备工作。 ## 最小实例 -如果你已经按照推荐方式安装了 `nb-cli`,使用脚手架创建一个空项目: +如果你已经按照推荐方式安装了 `nb-cli`,使用它创建一个空项目: ```bash nb create ``` -根据脚手架引导,将在当前目录下创建一个项目目录,项目目录内包含 `bot.py`。 +根据引导进行项目配置,完成后会在当前目录下创建一个项目目录,项目目录内包含 `bot.py`。 如果未安装 `nb-cli`,使用你最熟悉的编辑器或 IDE,创建一个名为 `bot.py` 的文件,内容如下(这里以 CQHTTP 适配器为例): diff --git a/archive/2.0.0a9/guide/installation.md b/archive/2.0.0a9.post1/guide/installation.md similarity index 83% rename from archive/2.0.0a9/guide/installation.md rename to archive/2.0.0a9.post1/guide/installation.md index b56da782..aaf916ec 100644 --- a/archive/2.0.0a9/guide/installation.md +++ b/archive/2.0.0a9.post1/guide/installation.md @@ -7,7 +7,7 @@ ::: :::warning 注意 -请在安装 nonebot2 之前卸载 nonebot 1.x +请在安装 NoneBot v2 之前卸载 NoneBot v1 ```bash pip uninstall nonebot @@ -15,10 +15,10 @@ pip uninstall nonebot ::: -### 通过脚手架安装(推荐安装方式) +### (推荐安装方式)通过脚手架安装 -1. (推荐)使用你喜欢的 Python 环境管理工具(如 `poetry`)创建新的虚拟环境。 -2. 使用 `pip` (或其他包管理工具) 安装 nb-cli,nonebot2 作为其依赖会一起被安装。 +1. (推荐)使用你喜欢的 Python 环境管理工具(如 `poetry`)创建新的虚拟环境 +2. 使用 `pip` 或 其他包管理工具 安装 `nb-cli`,`nonebot2` 会作为其依赖被一起安装 ```bash pip install nb-cli @@ -26,17 +26,17 @@ pip uninstall nonebot 3. 点个 star 吧 - nonebot2: [![nb-cli](https://img.shields.io/github/stars/nonebot/nonebot2?style=social)](https://github.com/nonebot/nonebot2) + nonebot2: [![nonebot2](https://img.shields.io/github/stars/nonebot/nonebot2?style=social)](https://github.com/nonebot/nonebot2) nb-cli: [![nb-cli](https://img.shields.io/github/stars/nonebot/nb-cli?style=social)](https://github.com/nonebot/nb-cli) -4. 如果有疑问,可以加群交流 (点击链接直达) +4. 如果有疑问,可以加群交流(点击链接直达) [![QQ Chat](https://img.shields.io/badge/QQ%E7%BE%A4-768887710-orange?style=social)](https://jq.qq.com/?_wv=1027&k=5OFifDh) [![Telegram Chat](https://img.shields.io/badge/telegram-cqhttp-blue?style=social)](https://t.me/cqhttp) -### 不使用脚手架(纯净安装) +### (纯净安装)不使用脚手架 ```bash pip install nonebot2 @@ -84,8 +84,6 @@ nb plugin install xxx ### 官方插件 -~~自用插件~~ ~~确信~~ - - [NoneBot-Plugin-Docs](https://github.com/nonebot/nonebot2/tree/master/packages/nonebot-plugin-docs) 离线文档插件 - [NoneBot-Plugin-Test](https://github.com/nonebot/plugin-test) 本地机器人测试前端插件 - [NoneBot-Plugin-APScheduler](https://github.com/nonebot/plugin-apscheduler) 定时任务插件 diff --git a/archive/2.0.0a9/guide/loading-a-plugin.md b/archive/2.0.0a9.post1/guide/loading-a-plugin.md similarity index 100% rename from archive/2.0.0a9/guide/loading-a-plugin.md rename to archive/2.0.0a9.post1/guide/loading-a-plugin.md diff --git a/archive/2.0.0a9/guide/mirai-guide.md b/archive/2.0.0a9.post1/guide/mirai-guide.md similarity index 97% rename from archive/2.0.0a9/guide/mirai-guide.md rename to archive/2.0.0a9.post1/guide/mirai-guide.md index bd11083c..403e55e0 100644 --- a/archive/2.0.0a9/guide/mirai-guide.md +++ b/archive/2.0.0a9.post1/guide/mirai-guide.md @@ -4,7 +4,7 @@ Mirai-API-HTTP 的适配现在仍然处于早期阶段, 可能没有进行过充分的测试 -请在生产环境中谨慎使用 +在生产环境中请谨慎使用 ::: @@ -34,7 +34,7 @@ Mirai-API-HTTP 的适配器以 [AGPLv3 许可](https://opensource.org/licenses/A > 单纯运行 NoneBot 实例并不会产生任何效果,因为此刻 QQ 这边还不知道 NoneBot 的存在,也就无法把消息发送给它,因此现在需要使用一个无头 QQ 来把消息等事件上报给 NoneBot。 -这次, 我们将采用在实现上有别于 onebot即 CQHTTP协议的另外一种无头 QQ API 协议, 即 MAH +这次, 我们将采用在实现上有别于 OneBot(CQHTTP)协议的另外一种无头 QQ API 协议, 即 MAH 为了配置 MAH 端, 我们现在需要移步到[MAH 的项目地址](https://github.com/project-mirai/mirai-api-http), 来看看它是如何配置的 diff --git a/archive/2.0.0a9/sidebar.config.json b/archive/2.0.0a9.post1/sidebar.config.json similarity index 100% rename from archive/2.0.0a9/sidebar.config.json rename to archive/2.0.0a9.post1/sidebar.config.json diff --git a/archive/2.0.0a9/advanced/runtime-hook.md b/archive/2.0.0a9/advanced/runtime-hook.md deleted file mode 100644 index 58bca681..00000000 --- a/archive/2.0.0a9/advanced/runtime-hook.md +++ /dev/null @@ -1 +0,0 @@ -# 运行时插槽 diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index 3b011655..971c8b0e 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -3,7 +3,7 @@ const path = require("path"); module.exports = context => ({ base: process.env.VUEPRESS_BASE || "/", title: "NoneBot", - description: "基于 酷Q 的 Python 异步 QQ 机器人框架", + description: "跨平台 Python 异步 QQ 机器人框架", markdown: { lineNumbers: true }, @@ -56,7 +56,7 @@ module.exports = context => ({ "/": { lang: "zh-CN", title: "NoneBot", - description: "基于 酷Q 的 Python 异步 QQ 机器人框架" + description: "跨平台 Python 异步 QQ 机器人框架" } }, diff --git a/docs/.vuepress/public/manifest.json b/docs/.vuepress/public/manifest.json index dcb62739..8f077d5b 100644 --- a/docs/.vuepress/public/manifest.json +++ b/docs/.vuepress/public/manifest.json @@ -3,7 +3,7 @@ "short_name": "NoneBot", "background-color": "#ffffff", "theme-color": "#ea5252", - "description": "An asynchronous python bot framework.", + "description": "跨平台 Python 异步 QQ 机器人框架", "display": "standalone", "icons": [ { diff --git a/docs/.vuepress/versions.json b/docs/.vuepress/versions.json index 95f6667a..f4d9a4cb 100644 --- a/docs/.vuepress/versions.json +++ b/docs/.vuepress/versions.json @@ -1,5 +1,5 @@ [ - "2.0.0a9", + "2.0.0a9.post1", "2.0.0a8.post2", "2.0.0a7" ] \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index 78cb0fc4..891eb832 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,7 +1,7 @@ --- home: true heroImage: /logo.png -tagline: An asynchronous bot framework. +tagline: 跨平台 Python 异步 QQ 机器人框架 actionText: 开始使用 actionLink: guide/ features: diff --git a/docs/advanced/runtime-hook.md b/docs/advanced/runtime-hook.md index 58bca681..935d3ce8 100644 --- a/docs/advanced/runtime-hook.md +++ b/docs/advanced/runtime-hook.md @@ -1 +1 @@ -# 运行时插槽 +# 钩子函数 diff --git a/docs/advanced/scheduler.md b/docs/advanced/scheduler.md index 86280b5f..c58062f1 100644 --- a/docs/advanced/scheduler.md +++ b/docs/advanced/scheduler.md @@ -4,7 +4,7 @@ > Advanced Python Scheduler (APScheduler) is a Python library that lets you schedule your Python code to be executed later, either just once or periodically. You can add new jobs or remove old ones on the fly as you please. If you store your jobs in a database, they will also survive scheduler restarts and maintain their state. When the scheduler is restarted, it will then run all the jobs it should have run while it was offline. -## 从 v1 迁移 +## 从 NoneBot v1 迁移 `APScheduler` 作为 `nonebot` v1 的可选依赖,为众多 bot 提供了方便的定时任务功能。`nonebot2` 已将 `APScheduler` 独立为 `nonebot_plugin_apscheduler` 插件,你可以在 [插件广场](https://v2.nonebot.dev/plugin-store.html) 中找到它。 @@ -21,7 +21,7 @@ nb plugin install nonebot_plugin_apscheduler ``` :::tip 提示 -`nb-cli` 默认通过 `pypi` 安装,你可以使用 `-i [mirror]` 或 `--index [mirror]` 来使用镜像源安装。 +`nb-cli` 默认通过 `pypi` 安装,你可以添加命令参数 `-i [mirror]` 或 `--index [mirror]` 以使用镜像源安装。 ::: ### 通过 poetry @@ -96,10 +96,14 @@ scheduler = require('nonebot_plugin_apscheduler').scheduler 对于大多数情况,我们需要在 `nonebot2` 项目被启动时启动定时任务,则此处设为 `true` +##### 在 `.env` 中添加 + ```bash APSCHEDULER_AUTOSTART=true ``` +##### 在 `bot.py` 中添加 + ```python nonebot.init(apscheduler_autostart=True) ``` @@ -116,10 +120,14 @@ nonebot.init(apscheduler_autostart=True) > 官方文档在绝大多数时候能提供最准确和最具时效性的指南 +##### 在 `.env` 中添加 + ```bash APSCHEDULER_CONFIG={"apscheduler.timezone": "Asia/Shanghai"} ``` +##### 在 `bot.py` 中添加 + ```python nonebot.init(apscheduler_config={ "apscheduler.timezone": "Asia/Shanghai" diff --git a/docs/api/adapters/cqhttp.md b/docs/api/adapters/cqhttp.md index ca5d91cb..5982e72e 100644 --- a/docs/api/adapters/cqhttp.md +++ b/docs/api/adapters/cqhttp.md @@ -9,6 +9,23 @@ sidebarDepth: 0 协议详情请看: [CQHTTP](https://github.com/howmanybots/onebot/blob/master/README.md) | [OneBot](https://github.com/howmanybots/onebot/blob/master/README.md) +# NoneBot.adapters.cqhttp.config 模块 + + +## _class_ `Config` + +CQHTTP 配置类 + + +* **配置项** + + + * `access_token` / `cqhttp_access_token`: CQHTTP 协议授权令牌 + + + * `secret` / `cqhttp_secret`: CQHTTP HTTP 上报数据签名口令 + + # NoneBot.adapters.cqhttp.utils 模块 diff --git a/docs/api/adapters/ding.md b/docs/api/adapters/ding.md index c64125ac..ed2a2d38 100644 --- a/docs/api/adapters/ding.md +++ b/docs/api/adapters/ding.md @@ -9,6 +9,23 @@ sidebarDepth: 0 协议详情请看: [钉钉文档](https://ding-doc.dingtalk.com/document#/org-dev-guide/elzz1p) +# NoneBot.adapters.ding.config 模块 + + +## _class_ `Config` + +钉钉配置类 + + +* **配置项** + + + * `access_token` / `ding_access_token`: 钉钉令牌 + + + * `secret` / `ding_secret`: 钉钉 HTTP 上报数据签名口令 + + # NoneBot.adapters.ding.exception 模块 diff --git a/docs/api/adapters/mirai.md b/docs/api/adapters/mirai.md index 4b568152..b627f72d 100644 --- a/docs/api/adapters/mirai.md +++ b/docs/api/adapters/mirai.md @@ -21,6 +21,26 @@ Mirai-API-HTTP 的适配器以 [AGPLv3许可](https://opensource.org/licenses/AG 这意味着在使用该适配器时需要 **以该许可开源您的完整程序代码** ::: +# NoneBot.adapters.mirai.config 模块 + + +## _class_ `Config` + +Mirai 配置类 + + +* **必填** + + + * `auth_key` / `mirai_auth_key`: mirai-api-http 的 auth_key + + + * `mirai_host`: mirai-api-http 的地址 + + + * `mirai_port`: mirai-api-http 的端口 + + # NoneBot.adapters.mirai.bot 模块 @@ -690,28 +710,6 @@ mirai-api-http 正向 Websocket 协议 Bot 适配。 * `qq: int`: 要使用的Bot的QQ号 **注意: 在使用正向Websocket时必须指定该值!** -# NoneBot.adapters.mirai.config 模块 - - -## _class_ `Config` - -基类:`pydantic.main.BaseModel` - -Mirai 配置类 - - -* **必填** - - - * `mirai_auth_key`: mirai-api-http的auth_key - - - * `mirai_host`: mirai-api-http的地址 - - - * `mirai_port`: mirai-api-http的端口 - - # NoneBot.adapters.mirai.message 模块 diff --git a/docs/api/drivers/README.md b/docs/api/drivers/README.md index 77485ed2..673697b4 100644 --- a/docs/api/drivers/README.md +++ b/docs/api/drivers/README.md @@ -120,7 +120,7 @@ Driver 基类。将后端框架封装,以满足适配器使用。 -### `register_adapter(name, adapter)` +### `register_adapter(name, adapter, **kwargs)` * **说明** diff --git a/docs/api/drivers/fastapi.md b/docs/api/drivers/fastapi.md index edd8e474..fba15c68 100644 --- a/docs/api/drivers/fastapi.md +++ b/docs/api/drivers/fastapi.md @@ -10,6 +10,58 @@ sidebarDepth: 0 后端使用方法请参考: [FastAPI 文档](https://fastapi.tiangolo.com/) +## _class_ `Config` + +基类:`pydantic.env_settings.BaseSettings` + +FastAPI 驱动框架设置,详情参考 FastAPI 文档 + + +### `fastapi_openapi_url` + + +* **类型** + + `Optional[str]` + + + +* **说明** + + openapi.json 地址,默认为 None 即关闭 + + + +### `fastapi_docs_url` + + +* **类型** + + `Optional[str]` + + + +* **说明** + + swagger 地址,默认为 None 即关闭 + + + +### `fastapi_redoc_url` + + +* **类型** + + `Optional[str]` + + + +* **说明** + + redoc 地址,默认为 None 即关闭 + + + ## _class_ `Driver` 基类:[`nonebot.drivers.Driver`](README.md#nonebot.drivers.Driver) diff --git a/docs/api/plugin.md b/docs/api/plugin.md index 960521da..1d134c52 100644 --- a/docs/api/plugin.md +++ b/docs/api/plugin.md @@ -960,7 +960,7 @@ def something_else(): -### `on_startswith(msg, rule=None, **kwargs)` +### `on_startswith(msg, **kwargs)` * **说明** @@ -1007,7 +1007,7 @@ def something_else(): -### `on_endswith(msg, rule=None, **kwargs)` +### `on_endswith(msg, **kwargs)` * **说明** @@ -1054,7 +1054,7 @@ def something_else(): -### `on_keyword(keywords, rule=None, **kwargs)` +### `on_keyword(keywords, **kwargs)` * **说明** @@ -1101,7 +1101,7 @@ def something_else(): -### `on_command(cmd, rule=None, aliases=None, **kwargs)` +### `on_command(cmd, aliases=None, **kwargs)` * **说明** @@ -1118,12 +1118,12 @@ def something_else(): * `cmd: Union[str, Tuple[str, ...]]`: 指定命令内容 - * `rule: Optional[Union[Rule, T_RuleChecker]]`: 事件响应规则 - - * `aliases: Optional[Set[Union[str, Tuple[str, ...]]]]`: 命令别名 + * `rule: Optional[Union[Rule, T_RuleChecker]]`: 事件响应规则 + + * `permission: Optional[Permission]`: 事件响应权限 @@ -1153,64 +1153,64 @@ def something_else(): -### `on_shell_command(cmd, rule=None, aliases=None, parser=None, **kwargs)` +### `on_shell_command(cmd, aliases=None, parser=None, **kwargs)` * **说明** + 注册一个支持 `shell_like` 解析参数的命令消息事件响应器。 -注册一个支持 `shell_like` 解析参数的命令消息事件响应器。 + 与普通的 `on_command` 不同的是,在添加 `parser` 参数时, 响应器会自动处理消息。 -与普通的 `on_command` 不同的是,在添加 `parser` 参数时, 响应器会自动处理消息。 + 并将用户输入的原始参数列表保存在 `state["argv"]`, `parser` 处理的参数保存在 `state["args"]` 中 -并将用户输入的原始参数列表保存在 `state["argv"]`, `parser` 处理的参数保存在 `state["args"]` 中 * **参数** + + * `cmd: Union[str, Tuple[str, ...]]`: 指定命令内容 -* `cmd: Union[str, Tuple[str, ...]]`: 指定命令内容 + * `aliases: Optional[Set[Union[str, Tuple[str, ...]]]]`: 命令别名 -* `rule: Optional[Union[Rule, T_RuleChecker]]`: 事件响应规则 + * `parser: Optional[ArgumentParser]`: `nonebot.rule.ArgumentParser` 对象 -* `aliases: Optional[Set[Union[str, Tuple[str, ...]]]]`: 命令别名 + * `rule: Optional[Union[Rule, T_RuleChecker]]`: 事件响应规则 -* `parser: Optional[ArgumentParser]`: `nonebot.rule.ArgumentParser` 对象 + * `permission: Optional[Permission]`: 事件响应权限 -* `permission: Optional[Permission]`: 事件响应权限 + * `handlers: Optional[List[T_Handler]]`: 事件处理函数列表 -* `handlers: Optional[List[T_Handler]]`: 事件处理函数列表 + * `temp: bool`: 是否为临时事件响应器(仅执行一次) -* `temp: bool`: 是否为临时事件响应器(仅执行一次) + * `priority: int`: 事件响应器优先级 -* `priority: int`: 事件响应器优先级 + * `block: bool`: 是否阻止事件向更低优先级传递 -* `block: bool`: 是否阻止事件向更低优先级传递 + * `state: Optional[T_State]`: 默认 state -* `state: Optional[T_State]`: 默认 state + * `state_factory: Optional[T_StateFactory]`: 默认 state 的工厂函数 -* `state_factory: Optional[T_StateFactory]`: 默认 state 的工厂函数 - * **返回** + + * `Type[Matcher]` -* `Type[Matcher]` - -### `on_regex(pattern, flags=0, rule=None, **kwargs)` +### `on_regex(pattern, flags=0, **kwargs)` * **说明** diff --git a/docs/guide/README.md b/docs/guide/README.md index 4326ac1b..8aa8d271 100644 --- a/docs/guide/README.md +++ b/docs/guide/README.md @@ -8,8 +8,6 @@ 初次使用时可能会觉得这里的概览过于枯燥,可以先简单略读之后直接前往 [安装](./installation.md) 查看安装方法,并进行后续的基础使用教程。 ::: -## 简介 - NoneBot2 是一个可扩展的 Python 异步机器人框架,它会对机器人收到的事件进行解析和处理,并以插件化的形式,按优先级分发给事件所对应的事件响应器,来完成具体的功能。 除了起到解析事件的作用,NoneBot 还为插件提供了大量实用的预设操作和权限控制机制。对于命令处理,它更是提供了完善且易用的会话机制和内部调用机制,以分别适应命令的连续交互和插件内部功能复用等需求。 diff --git a/docs/guide/basic-configuration.md b/docs/guide/basic-configuration.md index 84ed8fe0..4bb33f4f 100644 --- a/docs/guide/basic-configuration.md +++ b/docs/guide/basic-configuration.md @@ -2,7 +2,7 @@ 到目前为止我们还在使用 NoneBot 的默认行为,在开始编写自己的插件之前,我们先尝试在配置文件上动动手脚,让 NoneBot 表现出不同的行为。 -在上一章节中,我们创建了默认的项目结构,其中 `.env`, `.env.*` 均为项目的配置文件,下面将介绍几种 NoneBot 配置方式。 +在上一章节中,我们创建了默认的项目结构,其中 `.env` 和 `.env.*` 均为项目的配置文件,下面将介绍几种 NoneBot 配置方式。 :::danger 警告 请勿将敏感信息写入配置文件并提交至开源仓库! @@ -83,4 +83,4 @@ config.custom_config4 = "new config after init" ## 优先级 -`bot.py init` > `system env` > `env file` +`bot.py` 文件( `nonebot.init` ) > 系统环境变量 > `.env` `.env.*` 文件 diff --git a/docs/guide/creating-a-project.md b/docs/guide/creating-a-project.md index 5933b5fa..7c488a41 100644 --- a/docs/guide/creating-a-project.md +++ b/docs/guide/creating-a-project.md @@ -34,18 +34,18 @@ AweSome-Bot ## 启动 Bot -如果你使用 `nb-cli` +通过 `nb-cli` ```bash nb run [--file=bot.py] [--app=app] ``` -或者使用 +或 ```bash python bot.py ``` :::tip 提示 -如果在 bot 入口文件内定义了 asgi server, `nb-cli` 将会为你启动**冷重载模式** +如果在 bot 入口文件内定义了 asgi server, `nb-cli` 将会为你启动**冷重载模式**(当文件发生变动时自动重启 NoneBot 实例) ::: diff --git a/docs/guide/ding-guide.md b/docs/guide/ding-guide.md index c23c6827..ee9449ba 100644 --- a/docs/guide/ding-guide.md +++ b/docs/guide/ding-guide.md @@ -1,9 +1,9 @@ # 钉钉机器人使用指南 -基于企业机器人的outgoing(回调)机制,用户@机器人之后,钉钉会将消息内容POST到开发者的消息接收地址。开发者解析出消息内容、发送者身份,根据企业的业务逻辑,组装响应的消息内容返回,钉钉会将响应内容发送到群里。 +基于企业机器人的 outgoing(回调)机制,用户@机器人之后,钉钉会将消息内容 POST 到开发者的消息接收地址。开发者解析出消息内容、发送者身份,根据企业的业务逻辑,组装响应的消息内容返回,钉钉会将响应内容发送到群里。 ::: warning 只有企业内部机器人支持接收消息 -普通的机器人尚不支持应答机制,该机制指的是群里成员在聊天@机器人的时候,钉钉回调指定的服务地址,即Outgoing机器人。 +普通的机器人尚不支持应答机制,该机制指的是群里成员在聊天@机器人的时候,钉钉回调指定的服务地址,即 Outgoing 机器人。 ::: 首先你需要有钉钉机器人的相关概念,请参阅相关文档: diff --git a/docs/guide/getting-started.md b/docs/guide/getting-started.md index edb898a3..f5e61215 100644 --- a/docs/guide/getting-started.md +++ b/docs/guide/getting-started.md @@ -1,16 +1,16 @@ # 开始使用 -一切都安装成功后,你就已经做好了进行简单配置以运行一个最小的 NoneBot 实例的准备。 +一切都安装成功后,你就已经做好了进行简单配置以运行一个最小的 NoneBot 实例的准备工作。 ## 最小实例 -如果你已经按照推荐方式安装了 `nb-cli`,使用脚手架创建一个空项目: +如果你已经按照推荐方式安装了 `nb-cli`,使用它创建一个空项目: ```bash nb create ``` -根据脚手架引导,将在当前目录下创建一个项目目录,项目目录内包含 `bot.py`。 +根据引导进行项目配置,完成后会在当前目录下创建一个项目目录,项目目录内包含 `bot.py`。 如果未安装 `nb-cli`,使用你最熟悉的编辑器或 IDE,创建一个名为 `bot.py` 的文件,内容如下(这里以 CQHTTP 适配器为例): diff --git a/docs/guide/installation.md b/docs/guide/installation.md index b56da782..aaf916ec 100644 --- a/docs/guide/installation.md +++ b/docs/guide/installation.md @@ -7,7 +7,7 @@ ::: :::warning 注意 -请在安装 nonebot2 之前卸载 nonebot 1.x +请在安装 NoneBot v2 之前卸载 NoneBot v1 ```bash pip uninstall nonebot @@ -15,10 +15,10 @@ pip uninstall nonebot ::: -### 通过脚手架安装(推荐安装方式) +### (推荐安装方式)通过脚手架安装 -1. (推荐)使用你喜欢的 Python 环境管理工具(如 `poetry`)创建新的虚拟环境。 -2. 使用 `pip` (或其他包管理工具) 安装 nb-cli,nonebot2 作为其依赖会一起被安装。 +1. (推荐)使用你喜欢的 Python 环境管理工具(如 `poetry`)创建新的虚拟环境 +2. 使用 `pip` 或 其他包管理工具 安装 `nb-cli`,`nonebot2` 会作为其依赖被一起安装 ```bash pip install nb-cli @@ -26,17 +26,17 @@ pip uninstall nonebot 3. 点个 star 吧 - nonebot2: [![nb-cli](https://img.shields.io/github/stars/nonebot/nonebot2?style=social)](https://github.com/nonebot/nonebot2) + nonebot2: [![nonebot2](https://img.shields.io/github/stars/nonebot/nonebot2?style=social)](https://github.com/nonebot/nonebot2) nb-cli: [![nb-cli](https://img.shields.io/github/stars/nonebot/nb-cli?style=social)](https://github.com/nonebot/nb-cli) -4. 如果有疑问,可以加群交流 (点击链接直达) +4. 如果有疑问,可以加群交流(点击链接直达) [![QQ Chat](https://img.shields.io/badge/QQ%E7%BE%A4-768887710-orange?style=social)](https://jq.qq.com/?_wv=1027&k=5OFifDh) [![Telegram Chat](https://img.shields.io/badge/telegram-cqhttp-blue?style=social)](https://t.me/cqhttp) -### 不使用脚手架(纯净安装) +### (纯净安装)不使用脚手架 ```bash pip install nonebot2 @@ -84,8 +84,6 @@ nb plugin install xxx ### 官方插件 -~~自用插件~~ ~~确信~~ - - [NoneBot-Plugin-Docs](https://github.com/nonebot/nonebot2/tree/master/packages/nonebot-plugin-docs) 离线文档插件 - [NoneBot-Plugin-Test](https://github.com/nonebot/plugin-test) 本地机器人测试前端插件 - [NoneBot-Plugin-APScheduler](https://github.com/nonebot/plugin-apscheduler) 定时任务插件 diff --git a/docs/guide/mirai-guide.md b/docs/guide/mirai-guide.md index bd11083c..403e55e0 100644 --- a/docs/guide/mirai-guide.md +++ b/docs/guide/mirai-guide.md @@ -4,7 +4,7 @@ Mirai-API-HTTP 的适配现在仍然处于早期阶段, 可能没有进行过充分的测试 -请在生产环境中谨慎使用 +在生产环境中请谨慎使用 ::: @@ -34,7 +34,7 @@ Mirai-API-HTTP 的适配器以 [AGPLv3 许可](https://opensource.org/licenses/A > 单纯运行 NoneBot 实例并不会产生任何效果,因为此刻 QQ 这边还不知道 NoneBot 的存在,也就无法把消息发送给它,因此现在需要使用一个无头 QQ 来把消息等事件上报给 NoneBot。 -这次, 我们将采用在实现上有别于 onebot即 CQHTTP协议的另外一种无头 QQ API 协议, 即 MAH +这次, 我们将采用在实现上有别于 OneBot(CQHTTP)协议的另外一种无头 QQ API 协议, 即 MAH 为了配置 MAH 端, 我们现在需要移步到[MAH 的项目地址](https://github.com/project-mirai/mirai-api-http), 来看看它是如何配置的 diff --git a/docs_build/adapters/cqhttp.rst b/docs_build/adapters/cqhttp.rst index 17d5816a..184c65fc 100644 --- a/docs_build/adapters/cqhttp.rst +++ b/docs_build/adapters/cqhttp.rst @@ -8,6 +8,12 @@ NoneBot.adapters.cqhttp 模块 .. automodule:: nonebot.adapters.cqhttp +NoneBot.adapters.cqhttp.config 模块 +=================================== + +.. automodule:: nonebot.adapters.cqhttp.config + :members: + NoneBot.adapters.cqhttp.utils 模块 =================================== diff --git a/docs_build/adapters/ding.rst b/docs_build/adapters/ding.rst index 3b12564b..21cbed1f 100644 --- a/docs_build/adapters/ding.rst +++ b/docs_build/adapters/ding.rst @@ -8,6 +8,12 @@ NoneBot.adapters.ding 模块 .. automodule:: nonebot.adapters.ding +NoneBot.adapters.ding.config 模块 +=================================== + +.. automodule:: nonebot.adapters.ding.config + :members: + NoneBot.adapters.ding.exception 模块 ===================================== diff --git a/docs_build/adapters/mirai.rst b/docs_build/adapters/mirai.rst index a2f6a9c6..4a991217 100644 --- a/docs_build/adapters/mirai.rst +++ b/docs_build/adapters/mirai.rst @@ -8,6 +8,12 @@ NoneBot.adapters.mirai 模块 .. automodule:: nonebot.adapters.mirai +NoneBot.adapters.mirai.config 模块 +================================== + +.. automodule:: nonebot.adapters.mirai.config + :members: + NoneBot.adapters.mirai.bot 模块 =============================== @@ -22,13 +28,6 @@ NoneBot.adapters.mirai.bot_ws 模块 :members: :show-inheritance: -NoneBot.adapters.mirai.config 模块 -================================== - -.. automodule:: nonebot.adapters.mirai.config - :members: - :show-inheritance: - NoneBot.adapters.mirai.message 模块 =================================== @@ -83,4 +82,4 @@ NoneBot.adapters.mirai.event.request 模块 .. automodule:: nonebot.adapters.mirai.event.request :members: - :show-inheritance: \ No newline at end of file + :show-inheritance: diff --git a/nonebot/adapters/cqhttp/config.py b/nonebot/adapters/cqhttp/config.py index c537170a..8879705a 100644 --- a/nonebot/adapters/cqhttp/config.py +++ b/nonebot/adapters/cqhttp/config.py @@ -5,6 +5,14 @@ from pydantic import Field, BaseModel # priority: alias > origin class Config(BaseModel): + """ + CQHTTP 配置类 + + :配置项: + + - ``access_token`` / ``cqhttp_access_token``: CQHTTP 协议授权令牌 + - ``secret`` / ``cqhttp_secret``: CQHTTP HTTP 上报数据签名口令 + """ access_token: Optional[str] = Field(default=None, alias="cqhttp_access_token") secret: Optional[str] = Field(default=None, alias="cqhttp_secret") diff --git a/nonebot/adapters/ding/config.py b/nonebot/adapters/ding/config.py index 5b334a94..08e84ee2 100644 --- a/nonebot/adapters/ding/config.py +++ b/nonebot/adapters/ding/config.py @@ -4,6 +4,14 @@ from pydantic import Field, BaseModel class Config(BaseModel): + """ + 钉钉配置类 + + :配置项: + + - ``access_token`` / ``ding_access_token``: 钉钉令牌 + - ``secret`` / ``ding_secret``: 钉钉 HTTP 上报数据签名口令 + """ secret: Optional[str] = Field(default=None, alias="ding_secret") access_token: Optional[str] = Field(default=None, alias="ding_access_token") diff --git a/nonebot/adapters/mirai/config.py b/nonebot/adapters/mirai/config.py index a907dd17..e1983f45 100644 --- a/nonebot/adapters/mirai/config.py +++ b/nonebot/adapters/mirai/config.py @@ -10,9 +10,9 @@ class Config(BaseModel): :必填: - - ``mirai_auth_key``: mirai-api-http的auth_key - - ``mirai_host``: mirai-api-http的地址 - - ``mirai_port``: mirai-api-http的端口 + - ``auth_key`` / ``mirai_auth_key``: mirai-api-http 的 auth_key + - ``mirai_host``: mirai-api-http 的地址 + - ``mirai_port``: mirai-api-http 的端口 """ auth_key: Optional[str] = Field(None, alias='mirai_auth_key') host: Optional[IPv4Address] = Field(None, alias='mirai_host') diff --git a/nonebot/drivers/__init__.py b/nonebot/drivers/__init__.py index 986d59a3..134b2078 100644 --- a/nonebot/drivers/__init__.py +++ b/nonebot/drivers/__init__.py @@ -62,7 +62,7 @@ class Driver(abc.ABC): :说明: 已连接的 Bot """ - def register_adapter(self, name: str, adapter: Type["Bot"]): + def register_adapter(self, name: str, adapter: Type["Bot"], **kwargs): """ :说明: @@ -74,7 +74,7 @@ class Driver(abc.ABC): * ``adapter: Type[Bot]``: 适配器 Class """ self._adapters[name] = adapter - adapter.register(self, self.config) + adapter.register(self, self.config, **kwargs) logger.opt( colors=True).debug(f'Succeeded to load adapter "{name}"') diff --git a/nonebot/drivers/fastapi.py b/nonebot/drivers/fastapi.py index 284b738b..f78681c7 100644 --- a/nonebot/drivers/fastapi.py +++ b/nonebot/drivers/fastapi.py @@ -28,9 +28,39 @@ from nonebot.drivers import Driver as BaseDriver, WebSocket as BaseWebSocket class Config(BaseSettings): + """ + FastAPI 驱动框架设置,详情参考 FastAPI 文档 + """ fastapi_openapi_url: Optional[str] = None + """ + :类型: + + ``Optional[str]`` + + :说明: + + `openapi.json` 地址,默认为 `None` 即关闭 + """ fastapi_docs_url: Optional[str] = None + """ + :类型: + + ``Optional[str]`` + + :说明: + + `swagger` 地址,默认为 `None` 即关闭 + """ fastapi_redoc_url: Optional[str] = None + """ + :类型: + + ``Optional[str]`` + + :说明: + + `redoc` 地址,默认为 `None` 即关闭 + """ class Config: extra = "ignore" diff --git a/nonebot/message.py b/nonebot/message.py index cb64a4e0..fb860a96 100644 --- a/nonebot/message.py +++ b/nonebot/message.py @@ -115,6 +115,7 @@ async def _check_matcher(priority: int, Matcher: Type[Matcher], bot: "Bot", except Exception as e: logger.opt(colors=True, exception=e).error( f"Rule check failed for {Matcher}.") + return if Matcher.temp: try: diff --git a/nonebot/plugin.py b/nonebot/plugin.py index 38d657ac..3270fd12 100644 --- a/nonebot/plugin.py +++ b/nonebot/plugin.py @@ -745,11 +745,7 @@ class MatcherGroup: self.matchers.append(matcher) return matcher - def on_startswith(self, - msg: str, - rule: Optional[Optional[Union[Rule, - T_RuleChecker]]] = None, - **kwargs) -> Type[Matcher]: + def on_startswith(self, msg: str, **kwargs) -> Type[Matcher]: """ :说明: @@ -771,12 +767,14 @@ class MatcherGroup: - ``Type[Matcher]`` """ - return self.on_message(rule=startswith(msg) & rule, **kwargs) + final_kwargs = self.base_kwargs.copy() + final_kwargs.update(kwargs) + final_kwargs.pop("type", None) + matcher = on_startswith(msg, **final_kwargs) + self.matchers.append(matcher) + return matcher - def on_endswith(self, - msg: str, - rule: Optional[Optional[Union[Rule, T_RuleChecker]]] = None, - **kwargs) -> Type[Matcher]: + def on_endswith(self, msg: str, **kwargs) -> Type[Matcher]: """ :说明: @@ -798,12 +796,14 @@ class MatcherGroup: - ``Type[Matcher]`` """ - return self.on_message(rule=endswith(msg) & rule, **kwargs) + final_kwargs = self.base_kwargs.copy() + final_kwargs.update(kwargs) + final_kwargs.pop("type", None) + matcher = on_endswith(msg, **final_kwargs) + self.matchers.append(matcher) + return matcher - def on_keyword(self, - keywords: Set[str], - rule: Optional[Union[Rule, T_RuleChecker]] = None, - **kwargs) -> Type[Matcher]: + def on_keyword(self, keywords: Set[str], **kwargs) -> Type[Matcher]: """ :说明: @@ -825,11 +825,15 @@ class MatcherGroup: - ``Type[Matcher]`` """ - return self.on_message(rule=keyword(*keywords) & rule, **kwargs) + final_kwargs = self.base_kwargs.copy() + final_kwargs.update(kwargs) + final_kwargs.pop("type", None) + matcher = on_keyword(keywords, **final_kwargs) + self.matchers.append(matcher) + return matcher def on_command(self, cmd: Union[str, Tuple[str, ...]], - rule: Optional[Union[Rule, T_RuleChecker]] = None, aliases: Optional[Set[Union[str, Tuple[str, ...]]]] = None, **kwargs) -> Type[Matcher]: """ @@ -842,8 +846,8 @@ class MatcherGroup: :参数: * ``cmd: Union[str, Tuple[str, ...]]``: 指定命令内容 - * ``rule: Optional[Union[Rule, T_RuleChecker]]``: 事件响应规则 * ``aliases: Optional[Set[Union[str, Tuple[str, ...]]]]``: 命令别名 + * ``rule: Optional[Union[Rule, T_RuleChecker]]``: 事件响应规则 * ``permission: Optional[Permission]``: 事件响应权限 * ``handlers: Optional[List[T_Handler]]``: 事件处理函数列表 * ``temp: bool``: 是否为临时事件响应器(仅执行一次) @@ -856,27 +860,15 @@ class MatcherGroup: - ``Type[Matcher]`` """ - - async def _strip_cmd(bot: "Bot", event: "Event", state: T_State): - message = event.get_message() - segment = message.pop(0) - new_message = message.__class__( - str(segment) - [len(state["_prefix"]["raw_command"]):].strip()) # type: ignore - for new_segment in reversed(new_message): - message.insert(0, new_segment) - - handlers = kwargs.pop("handlers", []) - handlers.insert(0, _strip_cmd) - - commands = set([cmd]) | (aliases or set()) - return self.on_message(rule=command(*commands) & rule, - handlers=handlers, - **kwargs) + final_kwargs = self.base_kwargs.copy() + final_kwargs.update(kwargs) + final_kwargs.pop("type", None) + matcher = on_command(cmd, aliases=aliases, **final_kwargs) + self.matchers.append(matcher) + return matcher def on_shell_command(self, cmd: Union[str, Tuple[str, ...]], - rule: Optional[Union[Rule, T_RuleChecker]] = None, aliases: Optional[Set[Union[str, Tuple[str, ...]]]] = None, parser: Optional[ArgumentParser] = None, @@ -884,53 +876,43 @@ class MatcherGroup: """ :说明: - 注册一个支持 ``shell_like`` 解析参数的命令消息事件响应器。 + 注册一个支持 ``shell_like`` 解析参数的命令消息事件响应器。 - 与普通的 ``on_command`` 不同的是,在添加 ``parser`` 参数时, 响应器会自动处理消息。 + 与普通的 ``on_command`` 不同的是,在添加 ``parser`` 参数时, 响应器会自动处理消息。 - 并将用户输入的原始参数列表保存在 ``state["argv"]``, ``parser`` 处理的参数保存在 ``state["args"]`` 中 + 并将用户输入的原始参数列表保存在 ``state["argv"]``, ``parser`` 处理的参数保存在 ``state["args"]`` 中 :参数: - * ``cmd: Union[str, Tuple[str, ...]]``: 指定命令内容 - * ``rule: Optional[Union[Rule, T_RuleChecker]]``: 事件响应规则 - * ``aliases: Optional[Set[Union[str, Tuple[str, ...]]]]``: 命令别名 - * ``parser: Optional[ArgumentParser]``: ``nonebot.rule.ArgumentParser`` 对象 - * ``permission: Optional[Permission]``: 事件响应权限 - * ``handlers: Optional[List[T_Handler]]``: 事件处理函数列表 - * ``temp: bool``: 是否为临时事件响应器(仅执行一次) - * ``priority: int``: 事件响应器优先级 - * ``block: bool``: 是否阻止事件向更低优先级传递 - * ``state: Optional[T_State]``: 默认 state - * ``state_factory: Optional[T_StateFactory]``: 默认 state 的工厂函数 + * ``cmd: Union[str, Tuple[str, ...]]``: 指定命令内容 + * ``aliases: Optional[Set[Union[str, Tuple[str, ...]]]]``: 命令别名 + * ``parser: Optional[ArgumentParser]``: ``nonebot.rule.ArgumentParser`` 对象 + * ``rule: Optional[Union[Rule, T_RuleChecker]]``: 事件响应规则 + * ``permission: Optional[Permission]``: 事件响应权限 + * ``handlers: Optional[List[T_Handler]]``: 事件处理函数列表 + * ``temp: bool``: 是否为临时事件响应器(仅执行一次) + * ``priority: int``: 事件响应器优先级 + * ``block: bool``: 是否阻止事件向更低优先级传递 + * ``state: Optional[T_State]``: 默认 state + * ``state_factory: Optional[T_StateFactory]``: 默认 state 的工厂函数 :返回: - - ``Type[Matcher]`` + - ``Type[Matcher]`` """ - - async def _strip_cmd(bot: "Bot", event: "Event", state: T_State): - message = event.get_message() - segment = message.pop(0) - new_message = message.__class__( - str(segment) - [len(state["_prefix"]["raw_command"]):].strip()) # type: ignore - for new_segment in reversed(new_message): - message.insert(0, new_segment) - - handlers = kwargs.pop("handlers", []) - handlers.insert(0, _strip_cmd) - - commands = set([cmd]) | (aliases or set()) - return self.on_message(rule=shell_command(*commands, parser=parser) & - rule, - handlers=handlers, - **kwargs) + final_kwargs = self.base_kwargs.copy() + final_kwargs.update(kwargs) + final_kwargs.pop("type", None) + matcher = on_shell_command(cmd, + aliases=aliases, + parser=parser, + **final_kwargs) + self.matchers.append(matcher) + return matcher def on_regex(self, pattern: str, flags: Union[int, re.RegexFlag] = 0, - rule: Optional[Rule] = None, **kwargs) -> Type[Matcher]: """ :说明: @@ -956,7 +938,12 @@ class MatcherGroup: - ``Type[Matcher]`` """ - return self.on_message(rule=regex(pattern, flags) & rule, **kwargs) + final_kwargs = self.base_kwargs.copy() + final_kwargs.update(kwargs) + final_kwargs.pop("type", None) + matcher = on_regex(pattern, flags=flags, **final_kwargs) + self.matchers.append(matcher) + return matcher def load_plugin(module_path: str) -> Optional[Plugin]: diff --git a/nonebot/plugin.pyi b/nonebot/plugin.pyi index b1efdbe4..409043d5 100644 --- a/nonebot/plugin.pyi +++ b/nonebot/plugin.pyi @@ -320,8 +320,8 @@ class MatcherGroup: def on_startswith( self, - *, msg: str, + *, rule: Optional[Optional[Union[Rule, T_RuleChecker]]] = ..., permission: Optional[Permission] = ..., handlers: Optional[List[T_Handler]] = ..., @@ -334,8 +334,8 @@ class MatcherGroup: def on_endswith( self, - *, msg: str, + *, rule: Optional[Optional[Union[Rule, T_RuleChecker]]] = ..., permission: Optional[Permission] = ..., handlers: Optional[List[T_Handler]] = ..., @@ -348,8 +348,8 @@ class MatcherGroup: def on_keyword( self, - *, keywords: Set[str], + *, rule: Optional[Optional[Union[Rule, T_RuleChecker]]] = ..., permission: Optional[Permission] = ..., handlers: Optional[List[T_Handler]] = ..., @@ -362,10 +362,10 @@ class MatcherGroup: def on_command( self, - *, cmd: Union[str, Tuple[str, ...]], - rule: Optional[Union[Rule, T_RuleChecker]] = ..., aliases: Optional[Set[Union[str, Tuple[str, ...]]]] = ..., + *, + rule: Optional[Union[Rule, T_RuleChecker]] = ..., permission: Optional[Permission] = ..., handlers: Optional[List[T_Handler]] = ..., temp: bool = ..., @@ -377,11 +377,11 @@ class MatcherGroup: def on_shell_command( self, - *, cmd: Union[str, Tuple[str, ...]], - rule: Optional[Union[Rule, T_RuleChecker]] = ..., aliases: Optional[Set[Union[str, Tuple[str, ...]]]] = ..., parser: Optional[ArgumentParser] = ..., + *, + rule: Optional[Union[Rule, T_RuleChecker]] = ..., permission: Optional[Permission] = ..., handlers: Optional[List[T_Handler]] = ..., temp: bool = ..., @@ -393,9 +393,9 @@ class MatcherGroup: def on_regex( self, - *, pattern: str, flags: Union[int, re.RegexFlag] = 0, + *, rule: Optional[Rule] = ..., permission: Optional[Permission] = ..., handlers: Optional[List[T_Handler]] = ..., diff --git a/pyproject.toml b/pyproject.toml index 55646c66..ee03af33 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "nonebot2" -version = "2.0.0-alpha.9" +version = "2.0.0a9.post1" description = "An asynchronous python bot framework." authors = ["yanyongyu "] license = "MIT"