diff --git a/docs/.vuepress/public/logo.png b/docs/.vuepress/public/logo.png index 45857ada..2b7e3815 100644 Binary files a/docs/.vuepress/public/logo.png and b/docs/.vuepress/public/logo.png differ diff --git a/nonebot/adapters/__init__.py b/nonebot/adapters/__init__.py index f7e6a3bd..1ce77bc0 100644 --- a/nonebot/adapters/__init__.py +++ b/nonebot/adapters/__init__.py @@ -4,10 +4,9 @@ import abc from functools import reduce from dataclasses import dataclass, field -from nonebot.rule import notice from nonebot.config import Config -from nonebot.typing import Dict, Union, Iterable, WebSocket +from nonebot.typing import Dict, Union, Optional, Iterable, WebSocket class BaseBot(abc.ABC): @@ -49,32 +48,32 @@ class BaseEvent(abc.ABC): @property @abc.abstractmethod - def type(self): + def type(self) -> str: raise NotImplementedError @type.setter @abc.abstractmethod - def type(self, value): + def type(self, value) -> None: raise NotImplementedError @property @abc.abstractmethod - def detail_type(self): + def detail_type(self) -> str: raise NotImplementedError @detail_type.setter @abc.abstractmethod - def detail_type(self, value): + def detail_type(self, value) -> None: raise NotImplementedError @property @abc.abstractmethod - def sub_type(self): + def sub_type(self) -> Optional[str]: raise NotImplementedError @sub_type.setter @abc.abstractmethod - def sub_type(self, value): + def sub_type(self, value) -> None: raise NotImplementedError diff --git a/nonebot/adapters/cqhttp.py b/nonebot/adapters/cqhttp.py index ee109468..ce68977a 100644 --- a/nonebot/adapters/cqhttp.py +++ b/nonebot/adapters/cqhttp.py @@ -58,14 +58,11 @@ class Bot(BaseBot): @overrides(BaseBot) async def handle_message(self, message: dict): - # TODO: convert message into event - event = Event(message) - - if not event: + if not message: return - # if "message" in event.keys(): - # event["message"] = Message(event["message"]) + # TODO: convert message into event + event = Event(message) await handle_event(self, event) @@ -98,37 +95,39 @@ class Bot(BaseBot): class Event(BaseEvent): def __init__(self, raw_event: dict): + if "message" in raw_event: + raw_event["message"] = Message(raw_event["message"]) super().__init__(raw_event) @property @overrides(BaseEvent) - def type(self): + def type(self) -> str: return self._raw_event["post_type"] @type.setter @overrides(BaseEvent) - def type(self, value): + def type(self, value) -> None: self._raw_event["post_type"] = value @property @overrides(BaseEvent) - def detail_type(self): + def detail_type(self) -> str: return self._raw_event[f"{self.type}_type"] @detail_type.setter @overrides(BaseEvent) - def detail_type(self, value): + def detail_type(self, value) -> None: self._raw_event[f"{self.type}_type"] = value @property @overrides(BaseEvent) - def sub_type(self): - return self._raw_event["sub_type"] + def sub_type(self) -> Optional[str]: + return self._raw_event.get("sub_type") @type.setter @overrides(BaseEvent) - def sub_type(self, value): + def sub_type(self, value) -> None: self._raw_event["sub_type"] = value