From 3939dfa024f676efa3b847ba963aa12ae9e7b54e Mon Sep 17 00:00:00 2001 From: StarHeartHunt Date: Sat, 22 May 2021 06:43:53 +0800 Subject: [PATCH] :see_no_evil: ignore .DS_Store --- .gitignore | 3 +- docs/api/drivers/README.md | 91 ++++++++++++++++++++----------------- docs/api/drivers/fastapi.md | 2 +- docs/api/drivers/quart.md | 2 +- docs/api/typing.md | 8 ++-- nonebot/drivers/quart.py | 25 +++++----- 6 files changed, 69 insertions(+), 62 deletions(-) diff --git a/.gitignore b/.gitignore index 391fe0dd..81d69c97 100644 --- a/.gitignore +++ b/.gitignore @@ -189,4 +189,5 @@ dev docs_build/_build !tests/.env *.xmind -yarn.lock \ No newline at end of file +yarn.lock +.DS_Store diff --git a/docs/api/drivers/README.md b/docs/api/drivers/README.md index 673697b4..01f34078 100644 --- a/docs/api/drivers/README.md +++ b/docs/api/drivers/README.md @@ -14,7 +14,7 @@ sidebarDepth: 0 基类:`abc.ABC` -Driver 基类。将后端框架封装,以满足适配器使用。 +Driver 基类。 ### `_adapters` @@ -32,33 +32,33 @@ Driver 基类。将后端框架封装,以满足适配器使用。 -### `_ws_connection_hook` +### `_bot_connection_hook` * **类型** - `Set[T_WebSocketConnectionHook]` + `Set[T_BotConnectionHook]` * **说明** - WebSocket 连接建立时执行的函数 + Bot 连接建立时执行的函数 -### `_ws_disconnection_hook` +### `_bot_disconnection_hook` * **类型** - `Set[T_WebSocketDisconnectionHook]` + `Set[T_BotDisconnectionHook]` * **说明** - WebSocket 连接断开时执行的函数 + Bot 连接断开时执行的函数 @@ -120,6 +120,21 @@ Driver 基类。将后端框架封装,以满足适配器使用。 +### _property_ `bots` + + +* **类型** + + `Dict[str, Bot]` + + + +* **说明** + + 获取当前所有已连接的 Bot + + + ### `register_adapter(name, adapter, **kwargs)` @@ -144,33 +159,33 @@ Driver 基类。将后端框架封装,以满足适配器使用。 驱动类型名称 -### _abstract property_ `server_app` - -驱动 APP 对象 - - -### _abstract property_ `asgi` - -驱动 ASGI 对象 - - ### _abstract property_ `logger` 驱动专属 logger 日志记录器 -### _property_ `bots` - - -* **类型** - - `Dict[str, Bot]` - +### _abstract_ `run(host=None, port=None, *args, **kwargs)` * **说明** - 获取当前所有已连接的 Bot + 启动驱动框架 + + + +* **参数** + + + * `host: Optional[str]`: 驱动绑定 IP + + + * `post: Optional[int]`: 驱动绑定端口 + + + * `*args` + + + * `**kwargs` @@ -226,29 +241,21 @@ Driver 基类。将后端框架封装,以满足适配器使用。 在 WebSocket 连接断开后,调用该函数来注销 bot 对象 -### _abstract_ `run(host=None, port=None, *args, **kwargs)` +## _class_ `ReverseDriver` + +基类:`nonebot.drivers.Driver` + +Reverse Driver 基类。将后端框架封装,以满足适配器使用。 -* **说明** +### _abstract property_ `server_app` - 启动驱动框架 +驱动 APP 对象 +### _abstract property_ `asgi` -* **参数** - - - * `host: Optional[str]`: 驱动绑定 IP - - - * `post: Optional[int]`: 驱动绑定端口 - - - * `*args` - - - * `**kwargs` - +驱动 ASGI 对象 ### _abstract async_ `_handle_http()` diff --git a/docs/api/drivers/fastapi.md b/docs/api/drivers/fastapi.md index 3b2f4f23..9f2a0be8 100644 --- a/docs/api/drivers/fastapi.md +++ b/docs/api/drivers/fastapi.md @@ -79,7 +79,7 @@ FastAPI 驱动框架设置,详情参考 FastAPI 文档 ## _class_ `Driver` -基类:[`nonebot.drivers.Driver`](README.md#nonebot.drivers.Driver) +基类:[`nonebot.drivers.ReverseDriver`](README.md#nonebot.drivers.ReverseDriver) FastAPI 驱动框架 diff --git a/docs/api/drivers/quart.md b/docs/api/drivers/quart.md index 068769e0..644c2390 100644 --- a/docs/api/drivers/quart.md +++ b/docs/api/drivers/quart.md @@ -12,7 +12,7 @@ sidebarDepth: 0 ## _class_ `Driver` -基类:[`nonebot.drivers.Driver`](README.md#nonebot.drivers.Driver) +基类:[`nonebot.drivers.ReverseDriver`](README.md#nonebot.drivers.ReverseDriver) Quart 驱动框架 diff --git a/docs/api/typing.md b/docs/api/typing.md index 756ef946..6d339e12 100644 --- a/docs/api/typing.md +++ b/docs/api/typing.md @@ -46,7 +46,7 @@ sidebarDepth: 0 -## `T_WebSocketConnectionHook` +## `T_BotConnectionHook` * **类型** @@ -57,12 +57,12 @@ sidebarDepth: 0 * **说明** - WebSocket 连接建立时执行的函数 + Bot 连接建立时执行的函数 -## `T_WebSocketDisconnectionHook` +## `T_BotDisconnectionHook` * **类型** @@ -73,7 +73,7 @@ sidebarDepth: 0 * **说明** - WebSocket 连接断开时执行的函数 + Bot 连接断开时执行的函数 diff --git a/nonebot/drivers/quart.py b/nonebot/drivers/quart.py index d3c0ad42..cd1ae575 100644 --- a/nonebot/drivers/quart.py +++ b/nonebot/drivers/quart.py @@ -16,8 +16,7 @@ import uvicorn from nonebot.config import Config as NoneBotConfig from nonebot.config import Env -from nonebot.drivers import Driver as BaseDriver -from nonebot.drivers import WebSocket as BaseWebSocket +from nonebot.drivers import ReverseDriver, WebSocket as BaseWebSocket from nonebot.exception import RequestDenied from nonebot.log import logger from nonebot.typing import overrides @@ -35,7 +34,7 @@ except ImportError: _AsyncCallable = TypeVar("_AsyncCallable", bound=Callable[..., Coroutine]) -class Driver(BaseDriver): +class Driver(ReverseDriver): """ Quart 驱动框架 @@ -45,7 +44,7 @@ class Driver(BaseDriver): * ``/{adapter name}/ws``: WebSocket 上报 """ - @overrides(BaseDriver) + @overrides(ReverseDriver) def __init__(self, env: Env, config: NoneBotConfig): super().__init__(env, config) @@ -57,40 +56,40 @@ class Driver(BaseDriver): view_func=self._handle_ws_reverse) @property - @overrides(BaseDriver) + @overrides(ReverseDriver) def type(self) -> str: """驱动名称: ``quart``""" return 'quart' @property - @overrides(BaseDriver) + @overrides(ReverseDriver) def server_app(self) -> Quart: """``Quart`` 对象""" return self._server_app @property - @overrides(BaseDriver) + @overrides(ReverseDriver) def asgi(self): """``Quart`` 对象""" return self._server_app @property - @overrides(BaseDriver) + @overrides(ReverseDriver) def logger(self): """fastapi 使用的 logger""" return self._server_app.logger - @overrides(BaseDriver) + @overrides(ReverseDriver) def on_startup(self, func: _AsyncCallable) -> _AsyncCallable: """参考文档: `Startup and Shutdown `_""" return self.server_app.before_serving(func) # type: ignore - @overrides(BaseDriver) + @overrides(ReverseDriver) def on_shutdown(self, func: _AsyncCallable) -> _AsyncCallable: """参考文档: `Startup and Shutdown `_""" return self.server_app.after_serving(func) # type: ignore - @overrides(BaseDriver) + @overrides(ReverseDriver) def run(self, host: Optional[str] = None, port: Optional[int] = None, @@ -126,7 +125,7 @@ class Driver(BaseDriver): log_config=LOGGING_CONFIG, **kwargs) - @overrides(BaseDriver) + @overrides(ReverseDriver) async def _handle_http(self, adapter: str): request: Request = _request @@ -157,7 +156,7 @@ class Driver(BaseDriver): asyncio.create_task(bot.handle_message(data)) return Response('', 204) - @overrides(BaseDriver) + @overrides(ReverseDriver) async def _handle_ws_reverse(self, adapter: str): websocket: QuartWebSocket = _websocket if adapter not in self._adapters: