diff --git a/astrbot/core/pipeline/whitelist_check/stage.py b/astrbot/core/pipeline/whitelist_check/stage.py index cff215da..85f911a6 100644 --- a/astrbot/core/pipeline/whitelist_check/stage.py +++ b/astrbot/core/pipeline/whitelist_check/stage.py @@ -51,7 +51,10 @@ class WhitelistCheckStage(Stage): and event.get_message_type() == MessageType.FRIEND_MESSAGE ): return - if event.unified_msg_origin not in self.whitelist and event.get_group_id() not in self.whitelist: + if ( + event.unified_msg_origin not in self.whitelist + and event.get_group_id() not in self.whitelist + ): if self.wl_log: logger.info( f"会话 ID {event.unified_msg_origin} 不在会话白名单中,已终止事件传播。请在配置文件中添加该会话 ID 到白名单。" diff --git a/astrbot/core/platform/sources/gewechat/client.py b/astrbot/core/platform/sources/gewechat/client.py index 1c3b8bd0..7268efde 100644 --- a/astrbot/core/platform/sources/gewechat/client.py +++ b/astrbot/core/platform/sources/gewechat/client.py @@ -309,32 +309,49 @@ class SimpleGewechatClient: ) if self.appid: - online = await self.check_online(self.appid) - if online: - logger.info(f"APPID: {self.appid} 已在线") - return + try: + online = await self.check_online(self.appid) + if online: + logger.info(f"APPID: {self.appid} 已在线") + return + except Exception as e: + logger.error(f"检查在线状态失败: {e}") + sp.put(f"gewechat-appid-{self.nickname}", "") + self.appid = None payload = {"appId": self.appid} if self.appid: logger.info(f"使用 APPID: {self.appid}, {self.nickname}") - async with aiohttp.ClientSession() as session: - async with session.post( - f"{self.base_url}/login/getLoginQrCode", - headers=self.headers, - json=payload, - ) as resp: - json_blob = await resp.json() - if json_blob["ret"] != 200: - raise Exception(f"获取二维码失败: {json_blob}") - qr_data = json_blob["data"]["qrData"] - qr_uuid = json_blob["data"]["uuid"] - appid = json_blob["data"]["appId"] - logger.info(f"APPID: {appid}") - logger.warning( - f"请打开该网址,然后使用微信扫描二维码登录: https://api.cl2wm.cn/api/qrcode/code?text={qr_data}" - ) + try: + async with aiohttp.ClientSession() as session: + async with session.post( + f"{self.base_url}/login/getLoginQrCode", + headers=self.headers, + json=payload, + ) as resp: + json_blob = await resp.json() + if json_blob["ret"] != 200: + error_msg = json_blob.get("data", {}).get("msg", "") + if "设备不存在" in error_msg: + logger.error( + f"检测到无效的appid: {self.appid},将清除并重新登录。" + ) + sp.put(f"gewechat-appid-{self.nickname}", "") + self.appid = None + return await self.login() + else: + raise Exception(f"获取二维码失败: {json_blob}") + qr_data = json_blob["data"]["qrData"] + qr_uuid = json_blob["data"]["uuid"] + appid = json_blob["data"]["appId"] + logger.info(f"APPID: {appid}") + logger.warning( + f"请打开该网址,然后使用微信扫描二维码登录: https://api.cl2wm.cn/api/qrcode/code?text={qr_data}" + ) + except Exception as e: + raise e # 执行登录 retry_cnt = 64 diff --git a/packages/astrbot/main.py b/packages/astrbot/main.py index 93e370e3..9549fcd3 100644 --- a/packages/astrbot/main.py +++ b/packages/astrbot/main.py @@ -268,7 +268,10 @@ class Main(star.Star): UID: {user_id} 此 ID 可用于设置管理员。 /op 授权管理员, /deop 取消管理员。""" - if self.context.get_config()["platform_settings"]["unique_session"] and event.get_group_id(): + if ( + self.context.get_config()["platform_settings"]["unique_session"] + and event.get_group_id() + ): ret += f"\n\n当前处于独立会话模式, 此群 ID: {event.get_group_id()}, 也可将此 ID 加入白名单来放行整个群聊。" event.set_result(MessageEventResult().message(ret).use_t2i(False))