🏗️ change doc theme

This commit is contained in:
yanyongyu
2021-12-01 16:28:55 +08:00
parent b92c1a0b33
commit a414406039
111 changed files with 8887 additions and 11998 deletions

View File

@ -0,0 +1,529 @@
# NoneBot.drivers 模块
## 后端驱动适配基类
各驱动请继承以下基类
## _class_ `Driver`
基类:`abc.ABC`
Driver 基类。
### `_adapters`
* **类型**
`Dict[str, Type[Bot]]`
* **说明**
已注册的适配器列表
### `_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(name, 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`
Forward Driver 基类。将客户端框架封装,以满足适配器使用。
### _abstract_ `setup_http_polling(setup)`
* **说明**
注册一个 HTTP 轮询连接,如果传入一个函数,则该函数会在每次连接时被调用
* **参数**
* `setup: Union[HTTPPollingSetup, Callable[[], Awaitable[HTTPPollingSetup]]]`
### _abstract_ `setup_websocket(setup)`
* **说明**
注册一个 WebSocket 连接,如果传入一个函数,则该函数会在每次重连时被调用
* **参数**
* `setup: Union[WebSocketSetup, Callable[[], Awaitable[WebSocketSetup]]]`
## _class_ `ReverseDriver`
基类:`nonebot.drivers.Driver`
Reverse Driver 基类。将后端框架封装,以满足适配器使用。
### _abstract property_ `server_app`
驱动 APP 对象
### _abstract property_ `asgi`
驱动 ASGI 对象
## _class_ `HTTPConnection`
基类:`abc.ABC`
### `http_version`
One of `"1.0"`, `"1.1"` or `"2"`.
### `scheme`
URL scheme portion (likely `"http"` or `"https"`).
### `path`
HTTP request target excluding any query string,
with percent-encoded sequences and UTF-8 byte sequences
decoded into characters.
### `query_string`
URL portion after the `?`, percent-encoded.
### `headers`
A dict of name-value pairs,
where name is the header name, and value is the header value.
Order of header values must be preserved from the original HTTP request;
order of header names is not important.
Header names must be lowercased.
### _abstract property_ `type`
Connection type.
## _class_ `HTTPRequest`
基类:`nonebot.drivers.HTTPConnection`
HTTP 请求封装。参考 [asgi http scope](https://asgi.readthedocs.io/en/latest/specs/www.html#http-connection-scope)。
### `method`
The HTTP method name, uppercased.
### `body`
Body of the request.
Optional; if missing defaults to `b""`.
### _property_ `type`
Always `http`
## _class_ `HTTPResponse`
基类:`object`
HTTP 响应封装。参考 [asgi http scope](https://asgi.readthedocs.io/en/latest/specs/www.html#http-connection-scope)。
### `status`
HTTP status code.
### `body`
HTTP body content.
Optional; if missing defaults to `None`.
### `headers`
A dict of name-value pairs,
where name is the header name, and value is the header value.
Order must be preserved in the HTTP response.
Header names must be lowercased.
Optional; if missing defaults to an empty dict.
### _property_ `type`
Always `http`
## _class_ `WebSocket`
基类:`nonebot.drivers.HTTPConnection`, `abc.ABC`
WebSocket 连接封装。参考 [asgi websocket scope](https://asgi.readthedocs.io/en/latest/specs/www.html#websocket-connection-scope)。
### _property_ `type`
Always `websocket`
### _abstract property_ `closed`
* **类型**
`bool`
* **说明**
连接是否已经关闭
### _abstract async_ `accept()`
接受 WebSocket 连接请求
### _abstract async_ `close(code)`
关闭 WebSocket 连接请求
### _abstract async_ `receive()`
接收一条 WebSocket text 信息
### _abstract async_ `receive_bytes()`
接收一条 WebSocket binary 信息
### _abstract async_ `send(data)`
发送一条 WebSocket text 信息
### _abstract async_ `send_bytes(data)`
发送一条 WebSocket binary 信息
## _class_ `HTTPPollingSetup`
基类:`object`
### `adapter`
协议适配器名称
### `self_id`
机器人 ID
### `url`
URL
### `method`
HTTP method
### `body`
HTTP body
### `headers`
HTTP headers
### `http_version`
HTTP version
### `poll_interval`
HTTP 轮询间隔
## _class_ `WebSocketSetup`
基类:`object`
### `adapter`
协议适配器名称
### `self_id`
机器人 ID
### `url`
URL
### `headers`
HTTP headers
### `reconnect`
WebSocket 是否重连
### `reconnect_interval`
WebSocket 重连间隔

View File

@ -0,0 +1,96 @@
# NoneBot.drivers.aiohttp 模块
## AIOHTTP 驱动适配
本驱动仅支持客户端连接
## _class_ `Driver`
基类:[`nonebot.drivers.ForwardDriver`](README.md#nonebot.drivers.ForwardDriver)
AIOHTTP 驱动框架
### _property_ `type`
驱动名称: `aiohttp`
### _property_ `logger`
aiohttp driver 使用的 logger
### `on_startup(func)`
* **说明**
注册一个启动时执行的函数
* **参数**
* `func: Callable[[], Awaitable[None]]`
### `on_shutdown(func)`
* **说明**
注册一个停止时执行的函数
* **参数**
* `func: Callable[[], Awaitable[None]]`
### `setup_http_polling(setup)`
* **说明**
注册一个 HTTP 轮询连接,如果传入一个函数,则该函数会在每次连接时被调用
* **参数**
* `setup: Union[HTTPPollingSetup, Callable[[], Awaitable[HTTPPollingSetup]]]`
### `setup_websocket(setup)`
* **说明**
注册一个 WebSocket 连接,如果传入一个函数,则该函数会在每次重连时被调用
* **参数**
* `setup: Union[WebSocketSetup, Callable[[], Awaitable[WebSocketSetup]]]`
### `run(*args, **kwargs)`
启动 aiohttp driver
## _class_ `WebSocket`
基类:[`nonebot.drivers.WebSocket`](README.md#nonebot.drivers.WebSocket)

View File

@ -0,0 +1,249 @@
# 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`
* **类型**
`Optional[bool]`
* **说明**
开启/关闭冷重载,默认会在配置了 app 的 debug 模式启用
### `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 功能。
* **上报地址**
* `/{adapter name}/`: HTTP POST 上报
* `/{adapter name}/http/`: HTTP POST 上报
* `/{adapter name}/ws`: WebSocket 上报
* `/{adapter name}/ws/`: WebSocket 上报
### _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
## _class_ `FullDriver`
基类:[`nonebot.drivers.ForwardDriver`](README.md#nonebot.drivers.ForwardDriver), `nonebot.drivers.fastapi.Driver`
完整的 FastAPI 驱动框架,包含正向 Client 支持和反向 Server 支持。
* **使用方法**
```dotenv
DRIVER=nonebot.drivers.fastapi:FullDriver
```
### _property_ `type`
驱动名称: `fastapi_full`
### `setup_http_polling(setup)`
* **说明**
注册一个 HTTP 轮询连接,如果传入一个函数,则该函数会在每次连接时被调用
* **参数**
* `setup: Union[HTTPPollingSetup, Callable[[], Awaitable[HTTPPollingSetup]]]`
### `setup_websocket(setup)`
* **说明**
注册一个 WebSocket 连接,如果传入一个函数,则该函数会在每次重连时被调用
* **参数**
* `setup: Union[WebSocketSetup, Callable[[], Awaitable[WebSocketSetup]]]`
## _class_ `WebSocket`
基类:[`nonebot.drivers.WebSocket`](README.md#nonebot.drivers.WebSocket)

View File

@ -0,0 +1,144 @@
# NoneBot.drivers.quart 模块
## Quart 驱动适配
后端使用方法请参考: [Quart 文档](https://pgjones.gitlab.io/quart/index.html)
## _class_ `Config`
基类:`pydantic.env_settings.BaseSettings`
Quart 驱动框架设置
### `quart_reload`
* **类型**
`Optional[bool]`
* **说明**
开启/关闭冷重载,默认会在配置了 app 的 debug 模式启用
### `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 驱动框架
* **上报地址**
* `/{adapter name}/http`: HTTP POST 上报
* `/{adapter name}/ws`: WebSocket 上报
### _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
## _class_ `WebSocket`
基类:[`nonebot.drivers.WebSocket`](README.md#nonebot.drivers.WebSocket)