Skip to content

feat(cqhttp): 修改 CQHTTP 适配器事件的 detail_type 判断方式 #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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