mirror of
https://github.com/snowy-yang/qqbotsdk.git
synced 2026-10-21 10:08:50 +00:00
refactor: BaseProtocol/Connecter 由 abc 改为 typing.Protocol,统一接口风格
This commit is contained in:
1 parent
feb39b11d5
commit
1d9f509b25
2 files changed
+5
-8
No files matched your search
@@ -16,9 +16,8 @@
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
from abc import ABC, abstractmethod
|
||||
from time import monotonic
|
||||
from typing import cast
|
||||
from typing import Protocol, cast
|
||||
|
||||
import aiohttp
|
||||
import ujson
|
||||
@@ -34,10 +33,9 @@ from .session import Session
|
||||
from .token import AccessToken
|
||||
|
||||
|
||||
class Connecter(ABC):
|
||||
class Connecter(Protocol):
|
||||
"""连接适配器接口:两种接入方式都实现 `run()` 常驻运行。"""
|
||||
|
||||
@abstractmethod
|
||||
async def run(self) -> None: ...
|
||||
|
||||
|
||||
|
||||
@@ -7,19 +7,18 @@ HELLO/READY/INVALID_SESSION/op=13 这类协议帧在适配器内就地处理,
|
||||
与 `webhook_protocol.py`。
|
||||
"""
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Any
|
||||
from typing import Any, Protocol
|
||||
|
||||
from .model import Payload
|
||||
|
||||
|
||||
class BaseProtocol(ABC):
|
||||
class BaseProtocol(Protocol):
|
||||
"""适配器专有的协议处理器:实现方返回需要回送的响应体。"""
|
||||
|
||||
@abstractmethod
|
||||
async def on_frame(self, payload: Payload) -> Payload | dict[str, Any] | None:
|
||||
"""处理一条帧,返回需回送的响应体(无需回送则 None)。
|
||||
|
||||
IDENTIFY/RESUME 等握手应答、op=13 验证应答都经返回值回送;业务事件
|
||||
(op=0)不必处理,连接器会照常入队分发。
|
||||
"""
|
||||
...
|
||||
Reference in new issue
Block a user