💥 change forward setup api

This commit is contained in:
yanyongyu
2021-07-31 12:24:11 +08:00
parent f48c61c2e0
commit cda1ad093f
11 changed files with 599 additions and 245 deletions

View File

@ -49,6 +49,9 @@
* [nonebot.drivers.quart](drivers/quart.html)
* [nonebot.drivers.aiohttp](drivers/aiohttp.html)
* [nonebot.adapters](adapters/)

View File

@ -238,6 +238,45 @@ Driver 基类。
在 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`
@ -413,3 +452,78 @@ Always `websocket`
### _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_interval`
WebSocket 重连间隔

101
docs/api/drivers/aiohttp.md Normal file
View File

@ -0,0 +1,101 @@
---
contentSidebar: true
sidebarDepth: 0
---
# 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

@ -7,19 +7,11 @@ sidebarDepth: 0
## FastAPI 驱动适配
本驱动同时支持服务端以及客户端连接
后端使用方法请参考: [FastAPI 文档](https://fastapi.tiangolo.com/)
## _class_ `HTTPPollingSetup`
基类:`object`
## _class_ `WebSocketSetup`
基类:`object`
## _class_ `Config`
基类:`pydantic.env_settings.BaseSettings`
@ -89,7 +81,7 @@ FastAPI 驱动框架设置,详情参考 FastAPI 文档
## _class_ `Driver`
基类:[`nonebot.drivers.ReverseDriver`](README.md#nonebot.drivers.ReverseDriver), `nonebot.drivers.ForwardDriver`
基类:[`nonebot.drivers.ReverseDriver`](README.md#nonebot.drivers.ReverseDriver), [`nonebot.drivers.ForwardDriver`](README.md#nonebot.drivers.ForwardDriver)
FastAPI 驱动框架
@ -140,6 +132,38 @@ fastapi 使用的 logger
参考文档: [Events](https://fastapi.tiangolo.com/advanced/events/#startup-event)
### `setup_http_polling(setup)`
* **说明**
注册一个 HTTP 轮询连接,如果传入一个函数,则该函数会在每次连接时被调用
* **参数**
* `setup: Union[HTTPPollingSetup, Callable[[], Awaitable[HTTPPollingSetup]]]`
### `setup_websocket(setup)`
* **说明**
注册一个 WebSocket 连接,如果传入一个函数,则该函数会在每次重连时被调用
* **参数**
* `setup: Union[WebSocketSetup, Callable[[], Awaitable[WebSocketSetup]]]`
### `run(host=None, port=None, *, app=None, **kwargs)`
使用 `uvicorn` 启动 FastAPI