mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-07-28 00:31:14 +00:00
change typing
This commit is contained in:
@ -5,6 +5,7 @@ import abc
|
||||
from functools import reduce
|
||||
|
||||
from nonebot.config import Config
|
||||
from nonebot.drivers import BaseWebSocket
|
||||
from nonebot.typing import Dict, Union, Iterable, Optional
|
||||
|
||||
|
||||
@ -12,11 +13,19 @@ class BaseBot(abc.ABC):
|
||||
|
||||
@abc.abstractmethod
|
||||
def __init__(self,
|
||||
type: str,
|
||||
connection_type: str,
|
||||
config: Config,
|
||||
self_id: int,
|
||||
*,
|
||||
websocket=None):
|
||||
websocket: BaseWebSocket = None):
|
||||
self.connection_type = connection_type
|
||||
self.config = config
|
||||
self.self_id = self_id
|
||||
self.websocket = websocket
|
||||
|
||||
@property
|
||||
@abc.abstractmethod
|
||||
def type(self) -> str:
|
||||
raise NotImplementedError
|
||||
|
||||
@abc.abstractmethod
|
||||
|
@ -10,7 +10,7 @@ from nonebot.config import Config
|
||||
from nonebot.message import handle_event
|
||||
from nonebot.drivers import BaseWebSocket
|
||||
from nonebot.exception import ApiNotAvailable
|
||||
from nonebot.typing import Tuple, Iterable, Optional
|
||||
from nonebot.typing import Tuple, Iterable, Optional, overrides
|
||||
from nonebot.adapters import BaseBot, BaseMessage, BaseMessageSegment
|
||||
|
||||
|
||||
@ -50,12 +50,15 @@ class Bot(BaseBot):
|
||||
websocket: BaseWebSocket = None):
|
||||
if connection_type not in ["http", "websocket"]:
|
||||
raise ValueError("Unsupported connection type")
|
||||
self.type = "coolq"
|
||||
self.connection_type = connection_type
|
||||
self.config = config
|
||||
self.self_id = self_id
|
||||
self.websocket = websocket
|
||||
|
||||
super().__init__(connection_type, config, self_id, websocket=websocket)
|
||||
|
||||
@property
|
||||
@overrides(BaseBot)
|
||||
def type(self) -> str:
|
||||
return "cqhttp"
|
||||
|
||||
@overrides(BaseBot)
|
||||
async def handle_message(self, message: dict):
|
||||
# TODO: convert message into event
|
||||
event = Event.from_payload(message)
|
||||
@ -68,6 +71,7 @@ class Bot(BaseBot):
|
||||
|
||||
await handle_event(self, event)
|
||||
|
||||
@overrides(BaseBot)
|
||||
async def call_api(self, api: str, data: dict):
|
||||
# TODO: Call API
|
||||
if self.type == "websocket":
|
||||
|
Reference in New Issue
Block a user