Skip to content

Commit

Permalink
🐛 version 0.9.3
Browse files Browse the repository at this point in the history
fix pyd v2
resolve #14
  • Loading branch information
RF-Tar-Railt committed Feb 19, 2024
1 parent ef10946 commit 6cb8fbd
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
6 changes: 3 additions & 3 deletions nonebot/adapters/satori/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from nonebot.utils import escape_tag
from nonebot.exception import WebSocketClosed
from nonebot.compat import PYDANTIC_V2, type_validate_python
from nonebot.compat import PYDANTIC_V2, model_dump, type_validate_python
from nonebot.drivers import Driver, Request, WebSocket, HTTPClientMixin, WebSocketClientMixin

from nonebot import get_plugin_config
Expand Down Expand Up @@ -271,10 +271,10 @@ def payload_to_event(payload: SatoriEvent) -> Event:
EventClass = EVENT_CLASSES.get(payload.type, None)
if EventClass is None:
log("WARNING", f"Unknown payload type: {payload.type}")
event = type_validate_python(Event, payload)
event = type_validate_python(Event, model_dump(payload))
event.__type__ = payload.type # type: ignore
return event
return type_validate_python(EventClass, payload)
return type_validate_python(EventClass, model_dump(payload))

@override
async def _call_api(self, bot: Bot, api: str, **data: Any) -> Any:
Expand Down
5 changes: 4 additions & 1 deletion nonebot/adapters/satori/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,14 @@ def on_ready(self, user: User) -> None:

def get_authorization_header(self) -> Dict[str, str]:
"""获取当前 Bot 的鉴权信息"""
return {
header = {
"Authorization": f"Bearer {self.info.token}",
"X-Self-ID": self.self_id,
"X-Platform": self.platform,
}
if not self.info.token:
del header["Authorization"]
return header

async def handle_event(self, event: Event) -> None:
if isinstance(event, MessageEvent):
Expand Down
26 changes: 13 additions & 13 deletions nonebot/adapters/satori/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import TYPE_CHECKING, Dict, Type, TypeVar, Optional

from nonebot.utils import escape_tag
from nonebot.compat import PYDANTIC_V2, type_validate_python
from nonebot.compat import PYDANTIC_V2, model_dump, type_validate_python

from nonebot.adapters import Event as BaseEvent

Expand Down Expand Up @@ -267,9 +267,9 @@ class MessageCreatedEvent(MessageEvent):

def convert(self):
if self.channel.type == ChannelType.DIRECT:
return type_validate_python(PrivateMessageCreatedEvent, self)
return type_validate_python(PrivateMessageCreatedEvent, model_dump(self))
else:
return type_validate_python(PublicMessageCreatedEvent, self)
return type_validate_python(PublicMessageCreatedEvent, model_dump(self))


@register_event_class
Expand All @@ -278,9 +278,9 @@ class MessageDeletedEvent(MessageEvent):

def convert(self):
if self.channel.type == ChannelType.DIRECT:
return type_validate_python(PrivateMessageDeletedEvent, self)
return type_validate_python(PrivateMessageDeletedEvent, model_dump(self))
else:
return type_validate_python(PublicMessageDeletedEvent, self)
return type_validate_python(PublicMessageDeletedEvent, model_dump(self))


@register_event_class
Expand All @@ -289,9 +289,9 @@ class MessageUpdatedEvent(MessageEvent):

def convert(self):
if self.channel.type == ChannelType.DIRECT:
return type_validate_python(PrivateMessageUpdatedEvent, self)
return type_validate_python(PrivateMessageUpdatedEvent, model_dump(self))
else:
return type_validate_python(PublicMessageUpdatedEvent, self)
return type_validate_python(PublicMessageUpdatedEvent, model_dump(self))


class PrivateMessageEvent(MessageEvent):
Expand Down Expand Up @@ -457,9 +457,9 @@ def get_event_description(self) -> str:

def convert(self):
if self.channel and self.user and self.channel.type != ChannelType.DIRECT:
return type_validate_python(PublicInteractionButtonEvent, self)
return type_validate_python(PublicInteractionButtonEvent, model_dump(self))
if self.user:
return type_validate_python(PrivateInteractionButtonEvent, self)
return type_validate_python(PrivateInteractionButtonEvent, model_dump(self))
return self


Expand Down Expand Up @@ -536,9 +536,9 @@ def generate_message(cls, values):

def convert(self):
if self.channel and self.user and self.channel.type != ChannelType.DIRECT:
return type_validate_python(PublicInteractionCommandArgvEvent, self)
return type_validate_python(PublicInteractionCommandArgvEvent, model_dump(self))
if self.user:
return type_validate_python(PrivateInteractionCommandArgvEvent, self)
return type_validate_python(PrivateInteractionCommandArgvEvent, model_dump(self))
return self


Expand Down Expand Up @@ -591,9 +591,9 @@ def get_event_description(self) -> str:

def convert(self):
if self.channel and self.user and self.channel.type != ChannelType.DIRECT:
return type_validate_python(PublicInteractionCommandMessageEvent, self)
return type_validate_python(PublicInteractionCommandMessageEvent, model_dump(self))
if self.user:
return type_validate_python(PrivateInteractionCommandMessageEvent, self)
return type_validate_python(PrivateInteractionCommandMessageEvent, model_dump(self))
return self


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "nonebot-adapter-satori"
version = "0.9.2"
version = "0.9.3"
description = "Satori Protocol Adapter for Nonebot2"
authors = [
{name = "RF-Tar-Railt",email = "[email protected]"},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def identify(json: dict) -> dict:
},
}

await asyncio.sleep(2)
await asyncio.sleep(5)
bots = nonebot.get_bots()
assert "0" in bots
await adapter.shutdown()
Expand Down

0 comments on commit 6cb8fbd

Please sign in to comment.