🚧 update cqhttp event parse

This commit is contained in:
yanyongyu 2020-12-10 00:39:43 +08:00
parent 783efeaf0e
commit a57cd396fa
2 changed files with 9 additions and 1 deletions

View File

@ -302,7 +302,7 @@ class Bot(BaseBot):
detail_type = f".{detail_type}" if detail_type else "" detail_type = f".{detail_type}" if detail_type else ""
sub_type = message.get("sub_type") sub_type = message.get("sub_type")
sub_type = f".{sub_type}" if sub_type else "" sub_type = f".{sub_type}" if sub_type else ""
models = get_event_model(f".{post_type}{detail_type}{sub_type}") models = get_event_model(post_type + detail_type + sub_type)
for model in models: for model in models:
try: try:
event = model.parse_obj(message) event = model.parse_obj(message)

View File

@ -237,6 +237,10 @@ class CQHTTPEvent(Event):
def get_plaintext(self) -> str: def get_plaintext(self) -> str:
raise ValueError("Event has no message!") raise ValueError("Event has no message!")
@overrides(Event)
def get_session_id(self) -> str:
raise ValueError("Event has no message!")
# Models # Models
class Sender(BaseModel): class Sender(BaseModel):
@ -322,6 +326,10 @@ class MessageEvent(CQHTTPEvent):
def get_plaintext(self) -> str: def get_plaintext(self) -> str:
return self.message.extract_plain_text() return self.message.extract_plain_text()
@overrides(CQHTTPEvent)
def get_session_id(self) -> str:
return str(self.user_id)
class PrivateMessageEvent(MessageEvent): class PrivateMessageEvent(MessageEvent):
__event__ = "message.private" __event__ = "message.private"