✏️ fix changelog and typing

This commit is contained in:
yanyongyu
2022-02-06 15:24:41 +08:00
parent fd11e2696b
commit 924d9b6536
6 changed files with 71 additions and 74 deletions

View File

@ -21,14 +21,13 @@ from starlette.websockets import WebSocket, WebSocketState, WebSocketDisconnect
from nonebot.config import Env
from nonebot.typing import overrides
from nonebot.internal.model import FileTypes
from nonebot.exception import WebSocketClosed
from nonebot.config import Config as NoneBotConfig
from nonebot.drivers import Request as BaseRequest
from nonebot.drivers import WebSocket as BaseWebSocket
from nonebot.drivers import ReverseDriver, HTTPServerSetup, WebSocketServerSetup
from ..internal.model import FileTypes
def catch_closed(func):
@wraps(func)

View File

@ -24,14 +24,13 @@ from pydantic import BaseSettings
from nonebot.config import Env
from nonebot.typing import overrides
from nonebot.internal.model import FileTypes
from nonebot.exception import WebSocketClosed
from nonebot.config import Config as NoneBotConfig
from nonebot.drivers import Request as BaseRequest
from nonebot.drivers import WebSocket as BaseWebSocket
from nonebot.drivers import ReverseDriver, HTTPServerSetup, WebSocketServerSetup
from ..internal.model import FileTypes
try:
from quart import request as _request
from quart import websocket as _websocket

View File

@ -96,26 +96,28 @@ class Driver(abc.ABC):
"""注册一个在驱动器停止时执行的函数"""
raise NotImplementedError
def on_bot_connect(self, func: T_BotConnectionHook) -> T_BotConnectionHook:
@classmethod
def on_bot_connect(cls, func: T_BotConnectionHook) -> T_BotConnectionHook:
"""装饰一个函数使他在 bot 连接成功时执行。
钩子函数参数:
- bot: 当前连接上的 Bot 对象
"""
self._bot_connection_hook.add(
cls._bot_connection_hook.add(
Dependent[Any].parse(call=func, allow_types=BOT_HOOK_PARAMS)
)
return func
def on_bot_disconnect(self, func: T_BotDisconnectionHook) -> T_BotDisconnectionHook:
@classmethod
def on_bot_disconnect(cls, func: T_BotDisconnectionHook) -> T_BotDisconnectionHook:
"""装饰一个函数使他在 bot 连接断开时执行。
钩子函数参数:
- bot: 当前连接上的 Bot 对象
"""
self._bot_disconnection_hook.add(
cls._bot_disconnection_hook.add(
Dependent[Any].parse(call=func, allow_types=BOT_HOOK_PARAMS)
)
return func

View File

@ -44,9 +44,9 @@ def overrides(InterfaceClass: object) -> Callable[[T_Wrapped], T_Wrapped]:
T_State = Dict[Any, Any]
"""事件处理状态 State 类型"""
T_BotConnectionHook = Callable[["Bot"], Awaitable[Any]]
T_BotConnectionHook = Callable[..., Awaitable[Any]]
"""Bot 连接建立时钩子函数"""
T_BotDisconnectionHook = Callable[["Bot"], Awaitable[Any]]
T_BotDisconnectionHook = Callable[..., Awaitable[Any]]
"""Bot 连接断开时钩子函数"""
T_CallingAPIHook = Callable[["Bot", str, Dict[str, Any]], Awaitable[Any]]
"""`bot.call_api` 钩子函数"""