Skip to content

Commit

Permalink
🔖 version 0.1.1
Browse files Browse the repository at this point in the history
update model
  • Loading branch information
RF-Tar-Railt committed Oct 8, 2023
1 parent c27df7c commit abce878
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions nonebot/adapters/satori/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from datetime import datetime
from typing import Any, Dict, List, Union, Literal, Optional

from pydantic import Field, BaseModel, validator
from pydantic import Field, BaseModel, validator, Extra, root_validator

from .utils import Element, parse
from .utils import Element, parse, log


class ChannelType(IntEnum):
Expand Down Expand Up @@ -71,7 +71,7 @@ class LoginStatus(IntEnum):
RECONNECT = 4


class InnerLogin(BaseModel):
class InnerLogin(BaseModel, extra=Extra.allow):
user: Optional[User] = None
self_id: Optional[str] = None
platform: Optional[str] = None
Expand Down Expand Up @@ -126,14 +126,26 @@ class PongPayload(Payload):

class InnerMessage(BaseModel):
id: str
content: Optional[List[Element]] = None
content: List[Element]
channel: Optional[Channel] = None
guild: Optional[Guild] = None
member: Optional[InnerMember] = None
user: Optional[User] = None
created_at: Optional[datetime] = None
updated_at: Optional[datetime] = None


@root_validator(pre=True)
def ensure_content(cls, values):
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"}

@validator("content", pre=True)
def parse_content(cls, v):
if isinstance(v, list):
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.1.0"
version = "0.1.1"
description = "Satori Protocol Adapter for Nonebot2"
authors = [
{name = "RF-Tar-Railt",email = "[email protected]"},
Expand Down

0 comments on commit abce878

Please sign in to comment.