Skip to content

Commit

Permalink
🐛 fix model_validator (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt authored Sep 22, 2024
1 parent 0ef197b commit 609bcc3
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions nonebot/adapters/satori/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,9 @@ def get_message(self) -> Message:

@model_validator(mode="before")
def generate_message(cls, values):
values["_message"] = Message.from_satori_element(parse(values["message"]["content"]))
values["original_message"] = deepcopy(values["_message"])
if isinstance(values, dict):
values["_message"] = Message.from_satori_element(parse(values["message"]["content"]))
values["original_message"] = deepcopy(values["_message"])
return values

@property
Expand Down Expand Up @@ -405,7 +406,8 @@ def get_session_id(self) -> str:

@model_validator(mode="before")
def generate_message(cls, values):
values["_message"] = Message.from_satori_element(parse(values["message"]["content"]))
if isinstance(values, dict):
values["_message"] = Message.from_satori_element(parse(values["message"]["content"]))
return values

@property
Expand Down Expand Up @@ -526,11 +528,12 @@ def get_event_description(self) -> str:

@model_validator(mode="before")
def generate_message(cls, values):
cmd = values["argv"]["name"]
if values["argv"].get("arguments", []):
cmd += " ".join(values["argv"]["arguments"])
values["_message"] = Message(cmd)
values["original_message"] = deepcopy(values["_message"])
if isinstance(values, dict):
cmd = values["argv"]["name"]
if values["argv"].get("arguments", []):
cmd += " ".join(values["argv"]["arguments"])
values["_message"] = Message(cmd)
values["original_message"] = deepcopy(values["_message"])
return values

def convert(self):
Expand Down Expand Up @@ -576,8 +579,9 @@ class InteractionCommandMessageEvent(InteractionCommandEvent):

@model_validator(mode="before")
def generate_message(cls, values):
values["_message"] = Message.from_satori_element(parse(values["message"]["content"]))
values["original_message"] = deepcopy(values["_message"])
if isinstance(values, dict):
values["_message"] = Message.from_satori_element(parse(values["message"]["content"]))
values["original_message"] = deepcopy(values["_message"])
return values

@override
Expand Down

0 comments on commit 609bcc3

Please sign in to comment.