🔖 Release 2.4.0

This commit is contained in:
noneflow[bot]
2024-10-31 13:45:33 +00:00
parent a50a3398de
commit 5e86d53e0b
97 changed files with 19568 additions and 2 deletions

View File

@ -0,0 +1,3 @@
{
"position": 14
}

View File

@ -0,0 +1,206 @@
---
mdx:
format: md
sidebar_position: 2
description: nonebot.drivers.aiohttp 模块
---
# nonebot.drivers.aiohttp
[AIOHTTP](https://aiohttp.readthedocs.io/en/stable/) 驱动适配器。
```bash
nb driver install aiohttp
# 或者
pip install nonebot2[aiohttp]
```
:::tip 提示
本驱动仅支持客户端连接
:::
## _class_ `Session(params=None, headers=None, cookies=None, version=HTTPVersion.H11, timeout=None, proxy=None)` {#Session}
- **参数**
- `params` (QueryTypes)
- `headers` (HeaderTypes)
- `cookies` (CookieTypes)
- `version` (str | [HTTPVersion](index.md#HTTPVersion))
- `timeout` (float | None)
- `proxy` (str | None)
### _async method_ `request(setup)` {#Session-request}
- **参数**
- `setup` ([Request](index.md#Request))
- **返回**
- [Response](index.md#Response)
### _async method_ `setup()` {#Session-setup}
- **参数**
empty
- **返回**
- None
### _async method_ `close()` {#Session-close}
- **参数**
empty
- **返回**
- None
## _class_ `Mixin(<auto>)` {#Mixin}
- **说明:** AIOHTTP Mixin
- **参数**
auto
### _async method_ `request(setup)` {#Mixin-request}
- **参数**
- `setup` ([Request](index.md#Request))
- **返回**
- [Response](index.md#Response)
### _method_ `websocket(setup)` {#Mixin-websocket}
- **参数**
- `setup` ([Request](index.md#Request))
- **返回**
- AsyncGenerator[[WebSocket](index.md#WebSocket), None]
### _method_ `get_session(params=None, headers=None, cookies=None, version=HTTPVersion.H11, timeout=None, proxy=None)` {#Mixin-get-session}
- **参数**
- `params` (QueryTypes)
- `headers` (HeaderTypes)
- `cookies` (CookieTypes)
- `version` (str | [HTTPVersion](index.md#HTTPVersion))
- `timeout` (float | None)
- `proxy` (str | None)
- **返回**
- Session
## _class_ `WebSocket(*, request, session, websocket)` {#WebSocket}
- **说明:** AIOHTTP Websocket Wrapper
- **参数**
- `request` ([Request](index.md#Request))
- `session` (aiohttp.ClientSession)
- `websocket` (aiohttp.ClientWebSocketResponse)
### _async method_ `accept()` {#WebSocket-accept}
- **参数**
empty
- **返回**
- untyped
### _async method_ `close(code=1000, reason="")` {#WebSocket-close}
- **参数**
- `code` (int)
- `reason` (str)
- **返回**
- untyped
### _async method_ `receive()` {#WebSocket-receive}
- **参数**
empty
- **返回**
- str
### _async method_ `receive_text()` {#WebSocket-receive-text}
- **参数**
empty
- **返回**
- str
### _async method_ `receive_bytes()` {#WebSocket-receive-bytes}
- **参数**
empty
- **返回**
- bytes
### _async method_ `send_text(data)` {#WebSocket-send-text}
- **参数**
- `data` (str)
- **返回**
- None
### _async method_ `send_bytes(data)` {#WebSocket-send-bytes}
- **参数**
- `data` (bytes)
- **返回**
- None
## _class_ `Driver(env, config)` {#Driver}
- **参数**
- `env` ([Env](../config.md#Env))
- `config` ([Config](../config.md#Config))

View File

@ -0,0 +1,244 @@
---
mdx:
format: md
sidebar_position: 1
description: nonebot.drivers.fastapi 模块
---
# nonebot.drivers.fastapi
[FastAPI](https://fastapi.tiangolo.com/) 驱动适配
```bash
nb driver install fastapi
# 或者
pip install nonebot2[fastapi]
```
:::tip 提示
本驱动仅支持服务端连接
:::
## _class_ `Config(<auto>)` {#Config}
- **说明:** FastAPI 驱动框架设置,详情参考 FastAPI 文档
- **参数**
auto
### _class-var_ `fastapi_openapi_url` {#Config-fastapi-openapi-url}
- **类型:** str | None
- **说明:** `openapi.json` 地址,默认为 `None` 即关闭
### _class-var_ `fastapi_docs_url` {#Config-fastapi-docs-url}
- **类型:** str | None
- **说明:** `swagger` 地址,默认为 `None` 即关闭
### _class-var_ `fastapi_redoc_url` {#Config-fastapi-redoc-url}
- **类型:** str | None
- **说明:** `redoc` 地址,默认为 `None` 即关闭
### _class-var_ `fastapi_include_adapter_schema` {#Config-fastapi-include-adapter-schema}
- **类型:** bool
- **说明:** 是否包含适配器路由的 schema默认为 `True`
### _class-var_ `fastapi_reload` {#Config-fastapi-reload}
- **类型:** bool
- **说明:** 开启/关闭冷重载
### _class-var_ `fastapi_reload_dirs` {#Config-fastapi-reload-dirs}
- **类型:** list[str] | None
- **说明:** 重载监控文件夹列表,默认为 uvicorn 默认值
### _class-var_ `fastapi_reload_delay` {#Config-fastapi-reload-delay}
- **类型:** float
- **说明:** 重载延迟,默认为 uvicorn 默认值
### _class-var_ `fastapi_reload_includes` {#Config-fastapi-reload-includes}
- **类型:** list[str] | None
- **说明:** 要监听的文件列表,支持 glob pattern默认为 uvicorn 默认值
### _class-var_ `fastapi_reload_excludes` {#Config-fastapi-reload-excludes}
- **类型:** list[str] | None
- **说明:** 不要监听的文件列表,支持 glob pattern默认为 uvicorn 默认值
### _class-var_ `fastapi_extra` {#Config-fastapi-extra}
- **类型:** dict[str, Any]
- **说明:** 传递给 `FastAPI` 的其他参数。
## _class_ `Driver(env, config)` {#Driver}
- **说明:** FastAPI 驱动框架。
- **参数**
- `env` ([Env](../config.md#Env))
- `config` (NoneBotConfig)
### _property_ `type` {#Driver-type}
- **类型:** str
- **说明:** 驱动名称: `fastapi`
### _property_ `server_app` {#Driver-server-app}
- **类型:** FastAPI
- **说明:** `FastAPI APP` 对象
### _property_ `asgi` {#Driver-asgi}
- **类型:** FastAPI
- **说明:** `FastAPI APP` 对象
### _property_ `logger` {#Driver-logger}
- **类型:** logging.Logger
- **说明:** fastapi 使用的 logger
### _method_ `setup_http_server(setup)` {#Driver-setup-http-server}
- **参数**
- `setup` ([HTTPServerSetup](index.md#HTTPServerSetup))
- **返回**
- untyped
### _method_ `setup_websocket_server(setup)` {#Driver-setup-websocket-server}
- **参数**
- `setup` ([WebSocketServerSetup](index.md#WebSocketServerSetup))
- **返回**
- None
### _method_ `run(host=None, port=None, *args, app=None, **kwargs)` {#Driver-run}
- **说明:** 使用 `uvicorn` 启动 FastAPI
- **参数**
- `host` (str | None)
- `port` (int | None)
- `*args`
- `app` (str | None)
- `**kwargs`
- **返回**
- untyped
## _class_ `FastAPIWebSocket(*, request, websocket)` {#FastAPIWebSocket}
- **说明:** FastAPI WebSocket Wrapper
- **参数**
- `request` (BaseRequest)
- `websocket` ([WebSocket](index.md#WebSocket))
### _async method_ `accept()` {#FastAPIWebSocket-accept}
- **参数**
empty
- **返回**
- None
### _async method_ `close(code=status.WS_1000_NORMAL_CLOSURE, reason="")` {#FastAPIWebSocket-close}
- **参数**
- `code` (int)
- `reason` (str)
- **返回**
- None
### _async method_ `receive()` {#FastAPIWebSocket-receive}
- **参数**
empty
- **返回**
- str | bytes
### _async method_ `receive_text()` {#FastAPIWebSocket-receive-text}
- **参数**
empty
- **返回**
- str
### _async method_ `receive_bytes()` {#FastAPIWebSocket-receive-bytes}
- **参数**
empty
- **返回**
- bytes
### _async method_ `send_text(data)` {#FastAPIWebSocket-send-text}
- **参数**
- `data` (str)
- **返回**
- None
### _async method_ `send_bytes(data)` {#FastAPIWebSocket-send-bytes}
- **参数**
- `data` (bytes)
- **返回**
- None

View File

@ -0,0 +1,112 @@
---
mdx:
format: md
sidebar_position: 3
description: nonebot.drivers.httpx 模块
---
# nonebot.drivers.httpx
[HTTPX](https://www.python-httpx.org/) 驱动适配
```bash
nb driver install httpx
# 或者
pip install nonebot2[httpx]
```
:::tip 提示
本驱动仅支持客户端 HTTP 连接
:::
## _class_ `Session(params=None, headers=None, cookies=None, version=HTTPVersion.H11, timeout=None, proxy=None)` {#Session}
- **参数**
- `params` (QueryTypes)
- `headers` (HeaderTypes)
- `cookies` (CookieTypes)
- `version` (str | [HTTPVersion](index.md#HTTPVersion))
- `timeout` (float | None)
- `proxy` (str | None)
### _async method_ `request(setup)` {#Session-request}
- **参数**
- `setup` ([Request](index.md#Request))
- **返回**
- [Response](index.md#Response)
### _async method_ `setup()` {#Session-setup}
- **参数**
empty
- **返回**
- None
### _async method_ `close()` {#Session-close}
- **参数**
empty
- **返回**
- None
## _class_ `Mixin(<auto>)` {#Mixin}
- **说明:** HTTPX Mixin
- **参数**
auto
### _async method_ `request(setup)` {#Mixin-request}
- **参数**
- `setup` ([Request](index.md#Request))
- **返回**
- [Response](index.md#Response)
### _method_ `get_session(params=None, headers=None, cookies=None, version=HTTPVersion.H11, timeout=None, proxy=None)` {#Mixin-get-session}
- **参数**
- `params` (QueryTypes)
- `headers` (HeaderTypes)
- `cookies` (CookieTypes)
- `version` (str | [HTTPVersion](index.md#HTTPVersion))
- `timeout` (float | None)
- `proxy` (str | None)
- **返回**
- Session
## _class_ `Driver(env, config)` {#Driver}
- **参数**
- `env` ([Env](../config.md#Env))
- `config` ([Config](../config.md#Config))

View File

@ -0,0 +1,598 @@
---
mdx:
format: md
sidebar_position: 0
description: nonebot.drivers 模块
---
# nonebot.drivers
本模块定义了驱动适配器基类。
各驱动请继承以下基类。
## _abstract class_ `Mixin(<auto>)` {#Mixin}
- **说明:** 可与其他驱动器共用的混入基类。
- **参数**
auto
### _abstract property_ `type` {#Mixin-type}
- **类型:** str
- **说明:** 混入驱动类型名称
## _abstract class_ `Driver(env, config)` {#Driver}
- **说明**
驱动器基类。
驱动器控制框架的启动和停止,适配器的注册,以及机器人生命周期管理。
- **参数**
- `env` ([Env](../config.md#Env)): 包含环境信息的 Env 对象
- `config` ([Config](../config.md#Config)): 包含配置信息的 Config 对象
### _instance-var_ `env` {#Driver-env}
- **类型:** str
- **说明:** 环境名称
### _instance-var_ `config` {#Driver-config}
- **类型:** [Config](../config.md#Config)
- **说明:** 全局配置对象
### _property_ `bots` {#Driver-bots}
- **类型:** dict[str, [Bot](../adapters/index.md#Bot)]
- **说明:** 获取当前所有已连接的 Bot
### _method_ `register_adapter(adapter, **kwargs)` {#Driver-register-adapter}
- **说明:** 注册一个协议适配器
- **参数**
- `adapter` (type[[Adapter](../adapters/index.md#Adapter)]): 适配器类
- `**kwargs`: 其他传递给适配器的参数
- **返回**
- None
### _abstract property_ `type` {#Driver-type}
- **类型:** str
- **说明:** 驱动类型名称
### _abstract property_ `logger` {#Driver-logger}
- **类型:** untyped
- **说明:** 驱动专属 logger 日志记录器
### _abstract method_ `run(*args, **kwargs)` {#Driver-run}
- **说明:** 启动驱动框架
- **参数**
- `*args`
- `**kwargs`
- **返回**
- untyped
### _method_ `on_startup(func)` {#Driver-on-startup}
- **说明:** 注册一个启动时执行的函数
- **参数**
- `func` (LIFESPAN_FUNC)
- **返回**
- LIFESPAN_FUNC
### _method_ `on_shutdown(func)` {#Driver-on-shutdown}
- **说明:** 注册一个停止时执行的函数
- **参数**
- `func` (LIFESPAN_FUNC)
- **返回**
- LIFESPAN_FUNC
### _classmethod_ `on_bot_connect(func)` {#Driver-on-bot-connect}
- **说明**
装饰一个函数使他在 bot 连接成功时执行。
钩子函数参数:
- bot: 当前连接上的 Bot 对象
- **参数**
- `func` ([T_BotConnectionHook](../typing.md#T-BotConnectionHook))
- **返回**
- [T_BotConnectionHook](../typing.md#T-BotConnectionHook)
### _classmethod_ `on_bot_disconnect(func)` {#Driver-on-bot-disconnect}
- **说明**
装饰一个函数使他在 bot 连接断开时执行。
钩子函数参数:
- bot: 当前连接上的 Bot 对象
- **参数**
- `func` ([T_BotDisconnectionHook](../typing.md#T-BotDisconnectionHook))
- **返回**
- [T_BotDisconnectionHook](../typing.md#T-BotDisconnectionHook)
## _class_ `Cookies(cookies=None)` {#Cookies}
- **参数**
- `cookies` (CookieTypes)
### _method_ `set(name, value, domain="", path="/")` {#Cookies-set}
- **参数**
- `name` (str)
- `value` (str)
- `domain` (str)
- `path` (str)
- **返回**
- None
### _method_ `get(name, default=None, domain=None, path=None)` {#Cookies-get}
- **参数**
- `name` (str)
- `default` (str | None)
- `domain` (str | None)
- `path` (str | None)
- **返回**
- str | None
### _method_ `delete(name, domain=None, path=None)` {#Cookies-delete}
- **参数**
- `name` (str)
- `domain` (str | None)
- `path` (str | None)
- **返回**
- None
### _method_ `clear(domain=None, path=None)` {#Cookies-clear}
- **参数**
- `domain` (str | None)
- `path` (str | None)
- **返回**
- None
### _method_ `update(cookies=None)` {#Cookies-update}
- **参数**
- `cookies` (CookieTypes)
- **返回**
- None
### _method_ `as_header(request)` {#Cookies-as-header}
- **参数**
- `request` (Request)
- **返回**
- dict[str, str]
## _class_ `Request(method, url, *, params=None, headers=None, cookies=None, content=None, data=None, json=None, files=None, version=HTTPVersion.H11, timeout=None, proxy=None)` {#Request}
- **参数**
- `method` (str | bytes)
- `url` (URL | str | RawURL)
- `params` (QueryTypes)
- `headers` (HeaderTypes)
- `cookies` (CookieTypes)
- `content` (ContentTypes)
- `data` (DataTypes)
- `json` (Any)
- `files` (FilesTypes)
- `version` (str | HTTPVersion)
- `timeout` (float | None)
- `proxy` (str | None)
## _class_ `Response(status_code, *, headers=None, content=None, request=None)` {#Response}
- **参数**
- `status_code` (int)
- `headers` (HeaderTypes)
- `content` (ContentTypes)
- `request` (Request | None)
## _abstract class_ `ASGIMixin(<auto>)` {#ASGIMixin}
- **说明**
ASGI 服务端基类。
将后端框架封装,以满足适配器使用。
- **参数**
auto
### _abstract property_ `server_app` {#ASGIMixin-server-app}
- **类型:** Any
- **说明:** 驱动 APP 对象
### _abstract property_ `asgi` {#ASGIMixin-asgi}
- **类型:** Any
- **说明:** 驱动 ASGI 对象
### _abstract method_ `setup_http_server(setup)` {#ASGIMixin-setup-http-server}
- **说明:** 设置一个 HTTP 服务器路由配置
- **参数**
- `setup` ([HTTPServerSetup](#HTTPServerSetup))
- **返回**
- None
### _abstract method_ `setup_websocket_server(setup)` {#ASGIMixin-setup-websocket-server}
- **说明:** 设置一个 WebSocket 服务器路由配置
- **参数**
- `setup` ([WebSocketServerSetup](#WebSocketServerSetup))
- **返回**
- None
## _abstract class_ `WebSocket(*, request)` {#WebSocket}
- **参数**
- `request` (Request)
### _abstract property_ `closed` {#WebSocket-closed}
- **类型:** bool
- **说明:** 连接是否已经关闭
### _abstract async method_ `accept()` {#WebSocket-accept}
- **说明:** 接受 WebSocket 连接请求
- **参数**
empty
- **返回**
- None
### _abstract async method_ `close(code=1000, reason="")` {#WebSocket-close}
- **说明:** 关闭 WebSocket 连接请求
- **参数**
- `code` (int)
- `reason` (str)
- **返回**
- None
### _abstract async method_ `receive()` {#WebSocket-receive}
- **说明:** 接收一条 WebSocket text/bytes 信息
- **参数**
empty
- **返回**
- str | bytes
### _abstract async method_ `receive_text()` {#WebSocket-receive-text}
- **说明:** 接收一条 WebSocket text 信息
- **参数**
empty
- **返回**
- str
### _abstract async method_ `receive_bytes()` {#WebSocket-receive-bytes}
- **说明:** 接收一条 WebSocket binary 信息
- **参数**
empty
- **返回**
- bytes
### _async method_ `send(data)` {#WebSocket-send}
- **说明:** 发送一条 WebSocket text/bytes 信息
- **参数**
- `data` (str | bytes)
- **返回**
- None
### _abstract async method_ `send_text(data)` {#WebSocket-send-text}
- **说明:** 发送一条 WebSocket text 信息
- **参数**
- `data` (str)
- **返回**
- None
### _abstract async method_ `send_bytes(data)` {#WebSocket-send-bytes}
- **说明:** 发送一条 WebSocket binary 信息
- **参数**
- `data` (bytes)
- **返回**
- None
## _enum_ `HTTPVersion` {#HTTPVersion}
- **说明:** An enumeration.
- **参数**
auto
- `H10: '1.0'`
- `H11: '1.1'`
- `H2: '2'`
## _abstract class_ `ForwardMixin(<auto>)` {#ForwardMixin}
- **说明:** 客户端混入基类。
- **参数**
auto
## _abstract class_ `ReverseMixin(<auto>)` {#ReverseMixin}
- **说明:** 服务端混入基类。
- **参数**
auto
## _var_ `ForwardDriver` {#ForwardDriver}
- **类型:** ForwardMixin
- **说明**
支持客户端请求的驱动器。
**Deprecated**,请使用 [ForwardMixin](#ForwardMixin) 或其子类代替。
## _var_ `ReverseDriver` {#ReverseDriver}
- **类型:** ReverseMixin
- **说明**
支持服务端请求的驱动器。
**Deprecated**,请使用 [ReverseMixin](#ReverseMixin) 或其子类代替。
## _def_ `combine_driver(driver, *mixins)` {#combine-driver}
- **说明:** 将一个驱动器和多个混入类合并。
- **重载**
**1.** `(driver) -> type[D]`
- **参数**
- `driver` (type[D])
- **返回**
- type[D]
**2.** `(driver, __m, /, *mixins) -> type[CombinedDriver]`
- **参数**
- `driver` (type[D])
- `__m` (type[[Mixin](#Mixin)])
- `*mixins` (type[[Mixin](#Mixin)])
- **返回**
- type[CombinedDriver]
## _abstract class_ `HTTPClientMixin(<auto>)` {#HTTPClientMixin}
- **说明:** HTTP 客户端混入基类。
- **参数**
auto
### _abstract async method_ `request(setup)` {#HTTPClientMixin-request}
- **说明:** 发送一个 HTTP 请求
- **参数**
- `setup` ([Request](#Request))
- **返回**
- [Response](#Response)
### _abstract method_ `get_session(params=None, headers=None, cookies=None, version=HTTPVersion.H11, timeout=None, proxy=None)` {#HTTPClientMixin-get-session}
- **说明:** 获取一个 HTTP 会话
- **参数**
- `params` (QueryTypes)
- `headers` (HeaderTypes)
- `cookies` (CookieTypes)
- `version` (str | [HTTPVersion](#HTTPVersion))
- `timeout` (float | None)
- `proxy` (str | None)
- **返回**
- HTTPClientSession
## _class_ `HTTPServerSetup(<auto>)` {#HTTPServerSetup}
- **说明:** HTTP 服务器路由配置。
- **参数**
auto
## _abstract class_ `WebSocketClientMixin(<auto>)` {#WebSocketClientMixin}
- **说明:** WebSocket 客户端混入基类。
- **参数**
auto
### _abstract method_ `websocket(setup)` {#WebSocketClientMixin-websocket}
- **说明:** 发起一个 WebSocket 连接
- **参数**
- `setup` ([Request](#Request))
- **返回**
- AsyncGenerator[[WebSocket](#WebSocket), None]
## _class_ `WebSocketServerSetup(<auto>)` {#WebSocketServerSetup}
- **说明:** WebSocket 服务器路由配置。
- **参数**
auto

View File

@ -0,0 +1,62 @@
---
mdx:
format: md
sidebar_position: 6
description: nonebot.drivers.none 模块
---
# nonebot.drivers.none
None 驱动适配
:::tip 提示
本驱动不支持任何服务器或客户端连接
:::
## _class_ `Driver(env, config)` {#Driver}
- **说明:** None 驱动框架
- **参数**
- `env` ([Env](../config.md#Env))
- `config` ([Config](../config.md#Config))
### _property_ `type` {#Driver-type}
- **类型:** str
- **说明:** 驱动名称: `none`
### _property_ `logger` {#Driver-logger}
- **类型:** untyped
- **说明:** none driver 使用的 logger
### _method_ `run(*args, **kwargs)` {#Driver-run}
- **说明:** 启动 none driver
- **参数**
- `*args`
- `**kwargs`
- **返回**
- untyped
### _method_ `exit(force=False)` {#Driver-exit}
- **说明:** 退出 none driver
- **参数**
- `force` (bool): 强制退出
- **返回**
- untyped

View File

@ -0,0 +1,220 @@
---
mdx:
format: md
sidebar_position: 5
description: nonebot.drivers.quart 模块
---
# nonebot.drivers.quart
[Quart](https://pgjones.gitlab.io/quart/index.html) 驱动适配
```bash
nb driver install quart
# 或者
pip install nonebot2[quart]
```
:::tip 提示
本驱动仅支持服务端连接
:::
## _class_ `Config(<auto>)` {#Config}
- **说明:** Quart 驱动框架设置
- **参数**
auto
### _class-var_ `quart_reload` {#Config-quart-reload}
- **类型:** bool
- **说明:** 开启/关闭冷重载
### _class-var_ `quart_reload_dirs` {#Config-quart-reload-dirs}
- **类型:** list[str] | None
- **说明:** 重载监控文件夹列表,默认为 uvicorn 默认值
### _class-var_ `quart_reload_delay` {#Config-quart-reload-delay}
- **类型:** float
- **说明:** 重载延迟,默认为 uvicorn 默认值
### _class-var_ `quart_reload_includes` {#Config-quart-reload-includes}
- **类型:** list[str] | None
- **说明:** 要监听的文件列表,支持 glob pattern默认为 uvicorn 默认值
### _class-var_ `quart_reload_excludes` {#Config-quart-reload-excludes}
- **类型:** list[str] | None
- **说明:** 不要监听的文件列表,支持 glob pattern默认为 uvicorn 默认值
### _class-var_ `quart_extra` {#Config-quart-extra}
- **类型:** dict[str, Any]
- **说明:** 传递给 `Quart` 的其他参数。
## _class_ `Driver(env, config)` {#Driver}
- **说明:** Quart 驱动框架
- **参数**
- `env` ([Env](../config.md#Env))
- `config` (NoneBotConfig)
### _property_ `type` {#Driver-type}
- **类型:** str
- **说明:** 驱动名称: `quart`
### _property_ `server_app` {#Driver-server-app}
- **类型:** Quart
- **说明:** `Quart` 对象
### _property_ `asgi` {#Driver-asgi}
- **类型:** untyped
- **说明:** `Quart` 对象
### _property_ `logger` {#Driver-logger}
- **类型:** untyped
- **说明:** Quart 使用的 logger
### _method_ `setup_http_server(setup)` {#Driver-setup-http-server}
- **参数**
- `setup` ([HTTPServerSetup](index.md#HTTPServerSetup))
- **返回**
- untyped
### _method_ `setup_websocket_server(setup)` {#Driver-setup-websocket-server}
- **参数**
- `setup` ([WebSocketServerSetup](index.md#WebSocketServerSetup))
- **返回**
- None
### _method_ `run(host=None, port=None, *args, app=None, **kwargs)` {#Driver-run}
- **说明:** 使用 `uvicorn` 启动 Quart
- **参数**
- `host` (str | None)
- `port` (int | None)
- `*args`
- `app` (str | None)
- `**kwargs`
- **返回**
- untyped
## _class_ `WebSocket(*, request, websocket_ctx)` {#WebSocket}
- **说明:** Quart WebSocket Wrapper
- **参数**
- `request` (BaseRequest)
- `websocket_ctx` (WebsocketContext)
### _async method_ `accept()` {#WebSocket-accept}
- **参数**
empty
- **返回**
- untyped
### _async method_ `close(code=1000, reason="")` {#WebSocket-close}
- **参数**
- `code` (int)
- `reason` (str)
- **返回**
- untyped
### _async method_ `receive()` {#WebSocket-receive}
- **参数**
empty
- **返回**
- str | bytes
### _async method_ `receive_text()` {#WebSocket-receive-text}
- **参数**
empty
- **返回**
- str
### _async method_ `receive_bytes()` {#WebSocket-receive-bytes}
- **参数**
empty
- **返回**
- bytes
### _async method_ `send_text(data)` {#WebSocket-send-text}
- **参数**
- `data` (str)
- **返回**
- untyped
### _async method_ `send_bytes(data)` {#WebSocket-send-bytes}
- **参数**
- `data` (bytes)
- **返回**
- untyped

View File

@ -0,0 +1,138 @@
---
mdx:
format: md
sidebar_position: 4
description: nonebot.drivers.websockets 模块
---
# nonebot.drivers.websockets
[websockets](https://websockets.readthedocs.io/) 驱动适配
```bash
nb driver install websockets
# 或者
pip install nonebot2[websockets]
```
:::tip 提示
本驱动仅支持客户端 WebSocket 连接
:::
## _def_ `catch_closed(func)` {#catch-closed}
- **参数**
- `func` ((P) -> Coroutine[Any, Any, T])
- **返回**
- (P) -> Coroutine[Any, Any, T]
## _class_ `Mixin(<auto>)` {#Mixin}
- **说明:** Websockets Mixin
- **参数**
auto
### _method_ `websocket(setup)` {#Mixin-websocket}
- **参数**
- `setup` ([Request](index.md#Request))
- **返回**
- AsyncGenerator[[WebSocket](index.md#WebSocket), None]
## _class_ `WebSocket(*, request, websocket)` {#WebSocket}
- **说明:** Websockets WebSocket Wrapper
- **参数**
- `request` ([Request](index.md#Request))
- `websocket` (WebSocketClientProtocol)
### _async method_ `accept()` {#WebSocket-accept}
- **参数**
empty
- **返回**
- untyped
### _async method_ `close(code=1000, reason="")` {#WebSocket-close}
- **参数**
- `code` (int)
- `reason` (str)
- **返回**
- untyped
### _async method_ `receive()` {#WebSocket-receive}
- **参数**
empty
- **返回**
- str | bytes
### _async method_ `receive_text()` {#WebSocket-receive-text}
- **参数**
empty
- **返回**
- str
### _async method_ `receive_bytes()` {#WebSocket-receive-bytes}
- **参数**
empty
- **返回**
- bytes
### _async method_ `send_text(data)` {#WebSocket-send-text}
- **参数**
- `data` (str)
- **返回**
- None
### _async method_ `send_bytes(data)` {#WebSocket-send-bytes}
- **参数**
- `data` (bytes)
- **返回**
- None
## _class_ `Driver(env, config)` {#Driver}
- **参数**
- `env` ([Env](../config.md#Env))
- `config` ([Config](../config.md#Config))