From e780e3cbe95a3206af7b443c4210ccdcf3350ac2 Mon Sep 17 00:00:00 2001 From: SXP-Simon Date: Sun, 8 Feb 2026 19:41:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=B9=B3=E5=8F=B0ID?= =?UTF-8?q?=E6=8F=90=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题:_get_platform_id_from_event 方法使用了错误的属性访问方式,导致 platform_id=None。 修复:改为使用正确的 AstrMessageEvent API --- main.py | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/main.py b/main.py index 4c9cc6f..f875162 100644 --- a/main.py +++ b/main.py @@ -68,28 +68,25 @@ class QQGroupDailyAnalysis(Star): logger.info("QQ群日常分析插件已初始化(模块化版本)") - def _get_group_id_from_event(self, event: AstrMessageEvent) -> Optional[str]: + def _get_group_id_from_event(self, event: AstrMessageEvent) -> str | None: """从事件中提取群组ID(跨平台兼容)""" - group_id = None + # 使用正确的 AstrMessageEvent API if hasattr(event, "get_group_id"): group_id = event.get_group_id() - elif hasattr(event, "message_obj") and hasattr(event.message_obj, "group_id"): + return str(group_id) if group_id else None + if hasattr(event, "message_obj") and hasattr(event.message_obj, "group_id"): group_id = event.message_obj.group_id - return str(group_id) if group_id else None + return str(group_id) if group_id else None + return None - def _get_platform_id_from_event(self, event: AstrMessageEvent) -> Optional[str]: + def _get_platform_id_from_event(self, event: AstrMessageEvent) -> str | None: """从事件中提取平台ID(跨平台兼容)""" - platform_id = None - # 尝试从 platform 属性获取 - if hasattr(event, "platform") and isinstance(event.platform, str): - platform_id = event.platform - # 尝试从 metadata 获取 - elif hasattr(event, "metadata") and hasattr(event.metadata, "id"): - platform_id = event.metadata.id - # 尝试从 bot_manager 推断 - if not platform_id and hasattr(event, "bot"): - platform_id = self.bot_manager._get_platform_id_from_instance(event.bot) - return platform_id + # 使用正确的 AstrMessageEvent API + if hasattr(event, "get_platform_id"): + return event.get_platform_id() + if hasattr(event, "platform_meta") and hasattr(event.platform_meta, "id"): + return event.platform_meta.id + return None def _get_orchestrator( self, platform_id: str, bot_instance: Any = None