Skip to content

Commit

Permalink
💥 change forward setup api
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyongyu committed Jul 31, 2021
1 parent f48c61c commit cda1ad0
Show file tree
Hide file tree
Showing 11 changed files with 600 additions and 246 deletions.
4 changes: 4 additions & 0 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ module.exports = (context) => ({
title: "nonebot.drivers.quart 模块",
path: "drivers/quart",
},
{
title: "nonebot.drivers.aiohttp 模块",
path: "drivers/aiohttp",
},
{
title: "nonebot.adapters 模块",
path: "adapters/",
Expand Down
3 changes: 3 additions & 0 deletions docs/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
* [nonebot.drivers.quart](drivers/quart.html)


* [nonebot.drivers.aiohttp](drivers/aiohttp.html)


* [nonebot.adapters](adapters/)


Expand Down
114 changes: 114 additions & 0 deletions docs/api/drivers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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 changes: 101 additions & 0 deletions docs/api/drivers/aiohttp.md
Original file line number Diff line number Diff line change
@@ -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)
46 changes: 35 additions & 11 deletions docs/api/drivers/fastapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,9 @@ sidebarDepth: 0

## FastAPI 驱动适配

后端使用方法请参考: [FastAPI 文档](https://fastapi.tiangolo.com/)


## _class_ `HTTPPollingSetup`

基类:`object`
本驱动同时支持服务端以及客户端连接


## _class_ `WebSocketSetup`

基类:`object`
后端使用方法请参考: [FastAPI 文档](https://fastapi.tiangolo.com/)


## _class_ `Config`
Expand Down Expand Up @@ -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 驱动框架

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs_build/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ NoneBot Api Reference
- `nonebot.drivers <drivers/>`_
- `nonebot.drivers.fastapi <drivers/fastapi.html>`_
- `nonebot.drivers.quart <drivers/quart.html>`_
- `nonebot.drivers.aiohttp <drivers/aiohttp.html>`_
- `nonebot.adapters <adapters/>`_
- `nonebot.adapters.cqhttp <adapters/cqhttp.html>`_
- `nonebot.adapters.ding <adapters/ding.html>`_
Expand Down
12 changes: 12 additions & 0 deletions docs_build/drivers/aiohttp.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
\-\-\-
contentSidebar: true
sidebarDepth: 0
\-\-\-

NoneBot.drivers.aiohttp 模块
=============================

.. automodule:: nonebot.drivers.aiohttp
:members:
:private-members:
:show-inheritance:
Loading

0 comments on commit cda1ad0

Please sign in to comment.