🔀 Merge pull request #406

Feature: 支持自定义 Response
This commit is contained in:
Ju4tCode
2021-06-14 14:14:43 +08:00
committed by GitHub
18 changed files with 465 additions and 511 deletions

View File

@ -57,7 +57,7 @@ Config 配置对象
### _abstract_ `__init__(connection_type, self_id, *, websocket=None)`
### `__init__(self_id, request)`
* **参数**
@ -73,19 +73,14 @@ Config 配置对象
### `connection_type`
连接类型
### `self_id`
机器人 ID
### `websocket`
### `request`
Websocket 连接对象
连接信息
### _abstract property_ `type`
@ -102,7 +97,7 @@ Adapter 类型
### _abstract async classmethod_ `check_permission(driver, connection_type, headers, body)`
### _abstract async classmethod_ `check_permission(driver, request)`
* **说明**
@ -130,7 +125,10 @@ Adapter 类型
* **返回**
* `str`: 连接唯一标识符
* `str`: 连接唯一标识符`None` 代表连接不合法
* `HTTPResponse`: HTTP 上报响应
@ -153,7 +151,7 @@ Adapter 类型
* **参数**
* `message: dict`: 收到的上报消息
* `message: bytes`: 收到的上报消息

View File

@ -204,7 +204,7 @@ CQHTTP 协议 Bot 适配。继承属性参考 [BaseBot](./#class-basebot) 。
* 返回: `"cqhttp"`
### _async classmethod_ `check_permission(driver, connection_type, headers, body)`
### _async classmethod_ `check_permission(driver, request)`
* **说明**

View File

@ -105,7 +105,7 @@ sidebarDepth: 0
* 返回: `"ding"`
### _async classmethod_ `check_permission(driver, connection_type, headers, body)`
### _async classmethod_ `check_permission(driver, request)`
* **说明**

View File

@ -682,6 +682,11 @@ API中为了使代码更加整洁, 我们采用了与PEP8相符的命名规则
# NoneBot.adapters.mirai.bot_ws 模块
## _class_ `WebSocket`
基类:[`nonebot.drivers.WebSocket`](../drivers/README.md#nonebot.drivers.WebSocket)
## _class_ `WebsocketBot`
基类:`nonebot.adapters.mirai.bot.Bot`

View File

@ -268,74 +268,71 @@ Reverse Driver 基类。将后端框架封装,以满足适配器使用。
用于处理 WebSocket 类型请求的函数
## _class_ `HTTPRequest`
## _class_ `HTTPConnection`
基类:`object`
HTTP 请求封装。参考 [asgi http scope](https://asgi.readthedocs.io/en/latest/specs/www.html#http-connection-scope)。
基类:`abc.ABC`
### _property_ `type`
Always http
### _property_ `scope`
Raw scope from asgi.
The connection scope information, a dictionary that
contains at least a type key specifying the protocol that is incoming.
### _property_ `http_version`
### `http_version`
One of "1.0", "1.1" or "2".
### _property_ `method`
The HTTP method name, uppercased.
### _property_ `schema`
### `scheme`
URL scheme portion (likely "http" or "https").
Optional (but must not be empty); default is "http".
### _property_ `path`
### `path`
HTTP request target excluding any query string,
with percent-encoded sequences and UTF-8 byte sequences
decoded into characters.
### _property_ `query_string`
### `query_string`
URL portion after the ?, percent-encoded.
### _property_ `headers`
### `headers`
An iterable of [name, value] two-item iterables,
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.
Duplicates are possible and must be preserved in the message as received.
Header names must be lowercased.
### _property_ `body`
### _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"".
If more_body is set, treat as start of body and concatenate on further chunks.
### _property_ `type`
Always `http`
## _class_ `HTTPResponse`
@ -350,51 +347,40 @@ HTTP 响应封装。参考 [asgi http scope](https://asgi.readthedocs.io/en/late
HTTP status code.
### `body`
HTTP body content.
Optional; if missing defaults to `None`.
### `headers`
An iterable of [name, value] two-item iterables,
where name is the header name,
and value is the header value.
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 list.
### `body`
HTTP body content.
Optional; if missing defaults to None.
Optional; if missing defaults to an empty dict.
### _property_ `type`
Always http
Always `http`
## _class_ `WebSocket`
基类:`object`
基类:`nonebot.drivers.HTTPConnection`, `abc.ABC`
WebSocket 连接封装。参考 [asgi websocket scope](https://asgi.readthedocs.io/en/latest/specs/www.html#websocket-connection-scope)。
### _abstract_ `__init__(websocket)`
### _property_ `type`
* **参数**
* `websocket: Any`: WebSocket 连接对象
### _property_ `websocket`
WebSocket 连接对象
Always `websocket`
### _abstract property_ `closed`
@ -424,9 +410,19 @@ WebSocket 连接对象
### _abstract async_ `receive()`
接收一条 WebSocket 信息
接收一条 WebSocket text 信息
### _abstract async_ `receive_bytes()`
接收一条 WebSocket binary 信息
### _abstract async_ `send(data)`
发送一条 WebSocket 信息
发送一条 WebSocket text 信息
### _abstract async_ `send_bytes(data)`
发送一条 WebSocket text 信息

View File

@ -133,3 +133,8 @@ fastapi 使用的 logger
### `run(host=None, port=None, *, app=None, **kwargs)`
使用 `uvicorn` 启动 FastAPI
## _class_ `WebSocket`
基类:[`nonebot.drivers.WebSocket`](README.md#nonebot.drivers.WebSocket)

View File

@ -10,6 +10,28 @@ sidebarDepth: 0
后端使用方法请参考: [Quart 文档](https://pgjones.gitlab.io/quart/index.html)
## _class_ `Config`
基类:`pydantic.env_settings.BaseSettings`
Quart 驱动框架设置
### `quart_reload_dirs`
* **类型**
`List[str]`
* **说明**
`debug` 模式下重载监控文件夹列表,默认为 uvicorn 默认值
## _class_ `Driver`
基类:[`nonebot.drivers.ReverseDriver`](README.md#nonebot.drivers.ReverseDriver)
@ -44,7 +66,7 @@ Quart 驱动框架
### _property_ `logger`
fastapi 使用的 logger
Quart 使用的 logger
### `on_startup(func)`

View File

@ -132,27 +132,6 @@ sidebarDepth: 0
## _exception_ `RequestDenied`
基类:`nonebot.exception.NoneBotException`
* **说明**
Bot 连接请求不合法。
* **参数**
* `status_code: int`: HTTP 状态码
* `reason: str`: 拒绝原因
## _exception_ `AdapterException`
基类:`nonebot.exception.NoneBotException`