🔀 Merge pull request #369

Flow: add .DS_store to .gitignore
This commit is contained in:
Ju4tCode 2021-05-22 11:32:46 +08:00 committed by GitHub
commit e2de13e122
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 69 additions and 62 deletions

1
.gitignore vendored
View File

@ -190,3 +190,4 @@ docs_build/_build
!tests/.env
*.xmind
yarn.lock
.DS_Store

View File

@ -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()`

View File

@ -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 驱动框架

View File

@ -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 驱动框架

View File

@ -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 连接断开时执行的函数

View File

@ -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 <https://pgjones.gitlab.io/quart/how_to_guides/startup_shutdown.html>`_"""
return self.server_app.before_serving(func) # type: ignore
@overrides(BaseDriver)
@overrides(ReverseDriver)
def on_shutdown(self, func: _AsyncCallable) -> _AsyncCallable:
"""参考文档: `Startup and Shutdown <https://pgjones.gitlab.io/quart/how_to_guides/startup_shutdown.html>`_"""
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: