Skip to content

Commit

Permalink
修复部分事件接收报错的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ssttkkl committed Apr 6, 2023
1 parent cd14c71 commit a330392
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion nonebot/adapters/kaiheila/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ class Extra(BaseModel):
attachments: Optional[Attachment] = Field(None)
code: Optional[str] = Field(None)

@validator("body")
@validator("body", pre=True)
def convert_body(cls, v):
if v is None:
return None

if not isinstance(v, dict):
raise TypeError('body must be dict')
if not isinstance(v, AttrDict):
Expand Down
9 changes: 7 additions & 2 deletions nonebot/adapters/kaiheila/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,13 @@ def get_sn(cls, self_id: str) -> int:


class AttrDict(UserDict):
def __init__(self, initial=None):
def __init__(self, data=None):
initial = dict(data)
for k in initial:
if isinstance(initial[k], dict):
initial[k] = AttrDict(initial[k])

super().__init__(initial)

def __getattr__(self, name):
return self['name']
return self[name]

0 comments on commit a330392

Please sign in to comment.