diff --git a/nonebot/adapters/mirai/bot.py b/nonebot/adapters/mirai/bot.py index fba54a69..6190bedb 100644 --- a/nonebot/adapters/mirai/bot.py +++ b/nonebot/adapters/mirai/bot.py @@ -58,6 +58,7 @@ class WebSocket(BaseWebSocket): try: data = await self.receive() except websockets.ConnectionClosedOK: + logger.debug(f'Websocket connection {self.websocket} closed') break except Exception as e: logger.exception(f'Websocket client listened {self.websocket} ' diff --git a/nonebot/adapters/mirai/event/base.py b/nonebot/adapters/mirai/event/base.py index 451a858e..7a6cae39 100644 --- a/nonebot/adapters/mirai/event/base.py +++ b/nonebot/adapters/mirai/event/base.py @@ -1,12 +1,14 @@ +import json from enum import Enum -from typing import Dict, Any, Optional, Type +from typing import Any, Dict, Optional, Type + from pydantic import BaseModel, Field, ValidationError from typing_extensions import Literal from nonebot.adapters import Event as BaseEvent from nonebot.adapters import Message as BaseMessage -from nonebot.typing import overrides from nonebot.log import logger +from nonebot.typing import overrides class SenderPermission(str, Enum): @@ -104,3 +106,6 @@ class Event(BaseEvent): @overrides(BaseEvent) def is_tome(self) -> bool: return False + + def normalize_dict(self, **kwargs) -> Dict[str, Any]: + return json.loads(self.json(**kwargs)) diff --git a/nonebot/adapters/mirai/event/message.py b/nonebot/adapters/mirai/event/message.py index f680b0a2..9c478e28 100644 --- a/nonebot/adapters/mirai/event/message.py +++ b/nonebot/adapters/mirai/event/message.py @@ -1,10 +1,11 @@ from typing import TYPE_CHECKING from pydantic import Field -from .base import Event, SenderInfo, PrivateSenderInfo + +from nonebot.typing import overrides from ..message import MessageChain -from nonebot.typing import overrides +from .base import Event, PrivateSenderInfo, SenderInfo class MessageEvent(Event): @@ -37,4 +38,4 @@ class FriendMessage(MessageEvent): class TempMessage(MessageEvent): - pass \ No newline at end of file + pass diff --git a/nonebot/adapters/mirai/event/notice.py b/nonebot/adapters/mirai/event/notice.py index ae144b91..b758d9c5 100644 --- a/nonebot/adapters/mirai/event/notice.py +++ b/nonebot/adapters/mirai/event/notice.py @@ -1,4 +1,4 @@ -from typing import Optional, Any +from typing import Any, Optional from pydantic import Field diff --git a/nonebot/adapters/mirai/message.py b/nonebot/adapters/mirai/message.py index 06fc0d28..7562b6be 100644 --- a/nonebot/adapters/mirai/message.py +++ b/nonebot/adapters/mirai/message.py @@ -1,5 +1,5 @@ from enum import Enum -from typing import Any, Dict, List, Union, Iterable +from typing import Any, Dict, Iterable, List, Union from pydantic import validate_arguments