mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-07-28 16:51:26 +00:00
🔖 Release 2.0.0-beta.1
This commit is contained in:
@ -0,0 +1,192 @@
|
||||
---
|
||||
id: index
|
||||
slug: /api/drivers/
|
||||
---
|
||||
|
||||
# NoneBot.drivers 模块
|
||||
|
||||
## 后端驱动适配基类
|
||||
|
||||
各驱动请继承以下基类
|
||||
|
||||
## _class_ `Driver`
|
||||
|
||||
基类:`abc.ABC`
|
||||
|
||||
Driver 基类。
|
||||
|
||||
### `_adapters`
|
||||
|
||||
- **类型**
|
||||
|
||||
`Dict[str, Adapter]`
|
||||
|
||||
- **说明**
|
||||
|
||||
已注册的适配器列表
|
||||
|
||||
### `_bot_connection_hook`
|
||||
|
||||
- **类型**
|
||||
|
||||
`Set[T_BotConnectionHook]`
|
||||
|
||||
- **说明**
|
||||
|
||||
Bot 连接建立时执行的函数
|
||||
|
||||
### `_bot_disconnection_hook`
|
||||
|
||||
- **类型**
|
||||
|
||||
`Set[T_BotDisconnectionHook]`
|
||||
|
||||
- **说明**
|
||||
|
||||
Bot 连接断开时执行的函数
|
||||
|
||||
### `__init__(env, config)`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `env: Env`: 包含环境信息的 Env 对象
|
||||
|
||||
- `config: Config`: 包含配置信息的 Config 对象
|
||||
|
||||
### `env`
|
||||
|
||||
- **类型**
|
||||
|
||||
`str`
|
||||
|
||||
- **说明**
|
||||
|
||||
环境名称
|
||||
|
||||
### `config`
|
||||
|
||||
- **类型**
|
||||
|
||||
`Config`
|
||||
|
||||
- **说明**
|
||||
|
||||
配置对象
|
||||
|
||||
### `_clients`
|
||||
|
||||
- **类型**
|
||||
|
||||
`Dict[str, Bot]`
|
||||
|
||||
- **说明**
|
||||
|
||||
已连接的 Bot
|
||||
|
||||
### _property_ `bots`
|
||||
|
||||
- **类型**
|
||||
|
||||
`Dict[str, Bot]`
|
||||
|
||||
- **说明**
|
||||
|
||||
获取当前所有已连接的 Bot
|
||||
|
||||
### `register_adapter(adapter, **kwargs)`
|
||||
|
||||
- **说明**
|
||||
|
||||
注册一个协议适配器
|
||||
|
||||
- **参数**
|
||||
|
||||
- `name: str`: 适配器名称,用于在连接时进行识别
|
||||
|
||||
- `adapter: Type[Bot]`: 适配器 Class
|
||||
|
||||
- `**kwargs`: 其他传递给适配器的参数
|
||||
|
||||
### _abstract property_ `type`
|
||||
|
||||
驱动类型名称
|
||||
|
||||
### _abstract property_ `logger`
|
||||
|
||||
驱动专属 logger 日志记录器
|
||||
|
||||
### _abstract_ `run(*args, **kwargs)`
|
||||
|
||||
- **说明**
|
||||
|
||||
启动驱动框架
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*args`
|
||||
|
||||
- `**kwargs`
|
||||
|
||||
### _abstract_ `on_startup(func)`
|
||||
|
||||
注册一个在驱动启动时运行的函数
|
||||
|
||||
### _abstract_ `on_shutdown(func)`
|
||||
|
||||
注册一个在驱动停止时运行的函数
|
||||
|
||||
### `on_bot_connect(func)`
|
||||
|
||||
- **说明**
|
||||
|
||||
装饰一个函数使他在 bot 通过 WebSocket 连接成功时执行。
|
||||
|
||||
- **函数参数**
|
||||
|
||||
- `bot: Bot`: 当前连接上的 Bot 对象
|
||||
|
||||
### `on_bot_disconnect(func)`
|
||||
|
||||
- **说明**
|
||||
|
||||
装饰一个函数使他在 bot 通过 WebSocket 连接断开时执行。
|
||||
|
||||
- **函数参数**
|
||||
|
||||
- `bot: Bot`: 当前连接上的 Bot 对象
|
||||
|
||||
### `_bot_connect(bot)`
|
||||
|
||||
在 WebSocket 连接成功后,调用该函数来注册 bot 对象
|
||||
|
||||
### `_bot_disconnect(bot)`
|
||||
|
||||
在 WebSocket 连接断开后,调用该函数来注销 bot 对象
|
||||
|
||||
## _class_ `ForwardDriver`
|
||||
|
||||
基类:`nonebot.drivers.Driver`, `nonebot.drivers.ForwardMixin`
|
||||
|
||||
Forward Driver 基类。将客户端框架封装,以满足适配器使用。
|
||||
|
||||
## _class_ `ReverseDriver`
|
||||
|
||||
基类:`nonebot.drivers.Driver`
|
||||
|
||||
Reverse Driver 基类。将后端框架封装,以满足适配器使用。
|
||||
|
||||
### _abstract property_ `server_app`
|
||||
|
||||
驱动 APP 对象
|
||||
|
||||
### _abstract property_ `asgi`
|
||||
|
||||
驱动 ASGI 对象
|
||||
|
||||
## _class_ `HTTPServerSetup`
|
||||
|
||||
基类:`object`
|
||||
|
||||
## _class_ `WebSocketServerSetup`
|
||||
|
||||
基类:`object`
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"position": 13
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
# NoneBot.drivers.aiohttp 模块
|
||||
|
||||
## AIOHTTP 驱动适配
|
||||
|
||||
本驱动仅支持客户端连接
|
@ -0,0 +1,127 @@
|
||||
# NoneBot.drivers.fastapi 模块
|
||||
|
||||
## FastAPI 驱动适配
|
||||
|
||||
本驱动同时支持服务端以及客户端连接
|
||||
|
||||
后端使用方法请参考: [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` 即关闭
|
||||
|
||||
### `fastapi_reload`
|
||||
|
||||
- **类型**
|
||||
|
||||
`bool`
|
||||
|
||||
- **说明**
|
||||
|
||||
开启/关闭冷重载
|
||||
|
||||
### `fastapi_reload_dirs`
|
||||
|
||||
- **类型**
|
||||
|
||||
`Optional[List[str]]`
|
||||
|
||||
- **说明**
|
||||
|
||||
重载监控文件夹列表,默认为 uvicorn 默认值
|
||||
|
||||
### `fastapi_reload_delay`
|
||||
|
||||
- **类型**
|
||||
|
||||
`Optional[float]`
|
||||
|
||||
- **说明**
|
||||
|
||||
重载延迟,默认为 uvicorn 默认值
|
||||
|
||||
### `fastapi_reload_includes`
|
||||
|
||||
- **类型**
|
||||
|
||||
`Optional[List[str]]`
|
||||
|
||||
- **说明**
|
||||
|
||||
要监听的文件列表,支持 glob pattern,默认为 uvicorn 默认值
|
||||
|
||||
### `fastapi_reload_excludes`
|
||||
|
||||
- **类型**
|
||||
|
||||
`Optional[List[str]]`
|
||||
|
||||
- **说明**
|
||||
|
||||
不要监听的文件列表,支持 glob pattern,默认为 uvicorn 默认值
|
||||
|
||||
## _class_ `Driver`
|
||||
|
||||
基类:[`nonebot.drivers.ReverseDriver`](README.md#nonebot.drivers.ReverseDriver)
|
||||
|
||||
FastAPI 驱动框架。包含反向 Server 功能。
|
||||
|
||||
### _property_ `type`
|
||||
|
||||
驱动名称: `fastapi`
|
||||
|
||||
### _property_ `server_app`
|
||||
|
||||
`FastAPI APP` 对象
|
||||
|
||||
### _property_ `asgi`
|
||||
|
||||
`FastAPI APP` 对象
|
||||
|
||||
### _property_ `logger`
|
||||
|
||||
fastapi 使用的 logger
|
||||
|
||||
### `on_startup(func)`
|
||||
|
||||
参考文档: [Events](https://fastapi.tiangolo.com/advanced/events/#startup-event)
|
||||
|
||||
### `on_shutdown(func)`
|
||||
|
||||
参考文档: [Events](https://fastapi.tiangolo.com/advanced/events/#startup-event)
|
||||
|
||||
### `run(host=None, port=None, *, app=None, **kwargs)`
|
||||
|
||||
使用 `uvicorn` 启动 FastAPI
|
@ -0,0 +1 @@
|
||||
# NoneBot.drivers.httpx 模块
|
@ -0,0 +1,95 @@
|
||||
# NoneBot.drivers.quart 模块
|
||||
|
||||
## Quart 驱动适配
|
||||
|
||||
后端使用方法请参考: [Quart 文档](https://pgjones.gitlab.io/quart/index.html)
|
||||
|
||||
## _class_ `Config`
|
||||
|
||||
基类:`pydantic.env_settings.BaseSettings`
|
||||
|
||||
Quart 驱动框架设置
|
||||
|
||||
### `quart_reload`
|
||||
|
||||
- **类型**
|
||||
|
||||
`bool`
|
||||
|
||||
- **说明**
|
||||
|
||||
开启/关闭冷重载
|
||||
|
||||
### `quart_reload_dirs`
|
||||
|
||||
- **类型**
|
||||
|
||||
`Optional[List[str]]`
|
||||
|
||||
- **说明**
|
||||
|
||||
重载监控文件夹列表,默认为 uvicorn 默认值
|
||||
|
||||
### `quart_reload_delay`
|
||||
|
||||
- **类型**
|
||||
|
||||
`Optional[float]`
|
||||
|
||||
- **说明**
|
||||
|
||||
重载延迟,默认为 uvicorn 默认值
|
||||
|
||||
### `quart_reload_includes`
|
||||
|
||||
- **类型**
|
||||
|
||||
`Optional[List[str]]`
|
||||
|
||||
- **说明**
|
||||
|
||||
要监听的文件列表,支持 glob pattern,默认为 uvicorn 默认值
|
||||
|
||||
### `quart_reload_excludes`
|
||||
|
||||
- **类型**
|
||||
|
||||
`Optional[List[str]]`
|
||||
|
||||
- **说明**
|
||||
|
||||
不要监听的文件列表,支持 glob pattern,默认为 uvicorn 默认值
|
||||
|
||||
## _class_ `Driver`
|
||||
|
||||
基类:[`nonebot.drivers.ReverseDriver`](README.md#nonebot.drivers.ReverseDriver)
|
||||
|
||||
Quart 驱动框架
|
||||
|
||||
### _property_ `type`
|
||||
|
||||
驱动名称: `quart`
|
||||
|
||||
### _property_ `server_app`
|
||||
|
||||
`Quart` 对象
|
||||
|
||||
### _property_ `asgi`
|
||||
|
||||
`Quart` 对象
|
||||
|
||||
### _property_ `logger`
|
||||
|
||||
Quart 使用的 logger
|
||||
|
||||
### `on_startup(func)`
|
||||
|
||||
参考文档: [Startup and Shutdown](https://pgjones.gitlab.io/quart/how_to_guides/startup_shutdown.html)
|
||||
|
||||
### `on_shutdown(func)`
|
||||
|
||||
参考文档: [Startup and Shutdown](https://pgjones.gitlab.io/quart/how_to_guides/startup_shutdown.html)
|
||||
|
||||
### `run(host=None, port=None, *, app=None, **kwargs)`
|
||||
|
||||
使用 `uvicorn` 启动 Quart
|
@ -0,0 +1 @@
|
||||
# NoneBot.drivers.websockets 模块
|
Reference in New Issue
Block a user