websocket api

This commit is contained in:
yanyongyu
2020-08-13 15:23:04 +08:00
parent 0e73d4ce20
commit e7f9b2c229
10 changed files with 141 additions and 35 deletions

View File

@ -2,27 +2,33 @@
# -*- coding: utf-8 -*-
import abc
from functools import reduce
from functools import reduce, partial
from dataclasses import dataclass, field
from nonebot.config import Config
from nonebot.typing import Dict, Union, Optional, Iterable, WebSocket
from nonebot.typing import Driver, WebSocket
from nonebot.typing import Any, Dict, Union, Optional, Callable, Iterable, Awaitable
class BaseBot(abc.ABC):
@abc.abstractmethod
def __init__(self,
driver: Driver,
connection_type: str,
config: Config,
self_id: int,
self_id: str,
*,
websocket: WebSocket = None):
self.driver = driver
self.connection_type = connection_type
self.config = config
self.self_id = self_id
self.websocket = websocket
def __getattr__(self, name: str) -> Callable[..., Awaitable[Any]]:
return partial(self.call_api, name)
@property
@abc.abstractmethod
def type(self) -> str:
@ -37,6 +43,7 @@ class BaseBot(abc.ABC):
raise NotImplementedError
# TODO: improve event
class BaseEvent(abc.ABC):
def __init__(self, raw_event: dict):