Skip to content

Commit

Permalink
🐛 fix version 0.13.3
Browse files Browse the repository at this point in the history
fix Payload
  • Loading branch information
RF-Tar-Railt committed Jan 13, 2025
1 parent fc01080 commit 0ab4037
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 27 deletions.
3 changes: 2 additions & 1 deletion nonebot/adapters/satori/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def payload_to_json(payload: Payload) -> str:
return payload.json(by_alias=True)

async def receive_payload(self, info: ClientInfo, ws: WebSocket) -> Payload:
payload = type_validate_python(PayloadType, json.loads(await ws.receive()))
data = json.loads(await ws.receive())
payload = type_validate_python(PayloadType, data)
if isinstance(payload, EventPayload):
self.sequences[info.identity] = payload.body["id"]
return payload
Expand Down
12 changes: 6 additions & 6 deletions nonebot/adapters/satori/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
from .element import parse
from .utils import API, log
from .config import ClientInfo
from .models import PageDequeResult
from .event import Event, MessageEvent
from .models import MessageObject as SatoriMessage
from .models import MessageReceipt, PageDequeResult
from .message import Author, Message, RenderMessage, MessageSegment
from .models import Meta, Role, User, Guild, Login, Order, Member, Upload, Channel, Direction, PageResult
from .exception import (
Expand Down Expand Up @@ -287,7 +287,7 @@ async def send(
event: Event,
message: Union[str, Message, MessageSegment],
**kwargs,
) -> list[SatoriMessage]:
) -> list[MessageReceipt]:
if not event.channel:
raise RuntimeError("Event cannot be replied to!")
return await self.send_message(event.channel.id, message)
Expand All @@ -296,7 +296,7 @@ async def send_message(
self,
channel: Union[str, Channel],
message: Union[str, Message, MessageSegment],
) -> list[SatoriMessage]:
) -> list[MessageReceipt]:
"""发送消息
参数:
Expand All @@ -310,7 +310,7 @@ async def send_private_message(
self,
user: Union[str, User],
message: Union[str, Message, MessageSegment],
) -> list[SatoriMessage]:
) -> list[MessageReceipt]:
"""发送私聊消息
参数:
Expand Down Expand Up @@ -343,14 +343,14 @@ async def message_create(
*,
channel_id: str,
content: str,
) -> list[SatoriMessage]:
) -> list[MessageReceipt]:
request = Request(
"POST",
self.info.api_base / "message.create",
json={"channel_id": channel_id, "content": content},
)
res = await self._request(request)
return [type_validate_python(SatoriMessage, i) for i in res]
return [type_validate_python(MessageReceipt, i) for i in res]

@API
async def message_get(self, *, channel_id: str, message_id: str) -> SatoriMessage:
Expand Down
31 changes: 11 additions & 20 deletions nonebot/adapters/satori/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from pydantic import Field, BaseModel
from nonebot.compat import PYDANTIC_V2, ConfigDict, model_dump

from .utils import log
from .compat import field_validator, model_validator


Expand Down Expand Up @@ -195,12 +194,12 @@ class Identify(BaseModel):


class Ready(BaseModel):
logins: list[LoginOnline]
logins: list[Login]
proxy_urls: list[str] = Field(default_factory=list)


class Meta(BaseModel):
logins: list[LoginOnline]
logins: list[Login]
proxy_urls: list[str] = Field(default_factory=list)


Expand Down Expand Up @@ -241,18 +240,6 @@ class MessageObject(BaseModel):
created_at: Optional[datetime] = None
updated_at: Optional[datetime] = None

@model_validator(mode="before")
def ensure_content(cls, values):
if isinstance(values, dict):
if "content" in values:
return values
log(
"WARNING",
"received message without content, " "this may be caused by a bug of Satori Server.",
)
return {**values, "content": "Unknown"}
return values

@field_validator("created_at", mode="before")
def parse_created_at(cls, v):
if v is None:
Expand Down Expand Up @@ -286,6 +273,10 @@ class Config:
extra = "allow"


class MessageReceipt(MessageObject):
content: Optional[str] = None # type: ignore


class Event(BaseModel):
type: str
timestamp: datetime
Expand Down Expand Up @@ -316,11 +307,11 @@ def parse_timestamp(cls, v):
def ensure_login(cls, values):
if isinstance(values, dict):
if "self_id" in values and "platform" in values:
log(
"WARNING",
"received event with `self_id` and `platform`, "
"this may be caused by Satori Server used protocol under version 1.2.",
)
# log(
# "WARNING",
# "received event with `self_id` and `platform`, "
# "this may be caused by Satori Server used protocol under version 1.2.",
# )
if "login" not in values:
values["login"] = model_dump(
LoginOnline(
Expand Down

0 comments on commit 0ab4037

Please sign in to comment.