Skip to content

Commit

Permalink
feat(cqhttp): 修改 CQHTTP 适配器事件的 detail_type 判断方式 (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
st1020 authored Sep 8, 2024
1 parent fb1405e commit ffa2c40
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
tuple[Optional[str], Optional[str], Optional[str]], type[CQHTTPEvent]
]

DETAIL_TYPE_KEYS = ("message_type", "notice_type", "request_type", "meta_event_type")
DEFAULT_EVENT_MODELS: EventModels = {}
for _, model in inspect.getmembers(event, inspect.isclass):
if issubclass(model, CQHTTPEvent):
Expand Down Expand Up @@ -172,9 +173,14 @@ async def handle_cqhttp_event(self, msg: dict[str, Any]) -> None:
if post_type is None:
event_class = self.get_event_model(None, None, None)
else:
detail_type: Optional[str] = None
for key in DETAIL_TYPE_KEYS:
detail_type = msg.get(key)
if detail_type is not None:
break
event_class = self.get_event_model(
post_type,
msg.get(post_type + "_type"),
detail_type or msg.get(post_type + "_type"),
msg.get("sub_type"),
)

Expand Down

0 comments on commit ffa2c40

Please sign in to comment.