diff --git a/astrbot/core/platform/sources/gewechat/client.py b/astrbot/core/platform/sources/gewechat/client.py index 0355acc08..d009cc4b6 100644 --- a/astrbot/core/platform/sources/gewechat/client.py +++ b/astrbot/core/platform/sources/gewechat/client.py @@ -166,6 +166,21 @@ class SimpleGewechatClient(): ) as resp: json_blob = await resp.json() return json_blob['data'] + + async def logout(self): + if self.appid: + online = await self.check_online(self.appid) + if online: + async with aiohttp.ClientSession() as session: + async with session.post( + f"{self.base_url}/login/logout", + headers=self.headers, + json={ + "appId": self.appid + } + ) as resp: + json_blob = await resp.json() + logger.info(f"登出结果: {json_blob}") async def login(self): if self.token is None: diff --git a/astrbot/core/platform/sources/gewechat/gewechat_platform_adapter.py b/astrbot/core/platform/sources/gewechat/gewechat_platform_adapter.py index d0c182cc2..2862b817c 100644 --- a/astrbot/core/platform/sources/gewechat/gewechat_platform_adapter.py +++ b/astrbot/core/platform/sources/gewechat/gewechat_platform_adapter.py @@ -68,6 +68,9 @@ class GewechatPlatformAdapter(Platform): return self._run() + async def logout(self): + await self.client.logout() + async def _run(self): await self.client.login() diff --git a/packages/astrbot/main.py b/packages/astrbot/main.py index 3523c985b..bb533ee22 100644 --- a/packages/astrbot/main.py +++ b/packages/astrbot/main.py @@ -418,6 +418,16 @@ UID: {user_id} 此 ID 可用于设置管理员。/op 授权管理员, /deo del session_var[key] sp.put("session_variables", session_vars) yield event.plain_result(f"会话 {session_id} 变量 {key} 移除成功。") + + @filter.command("gewe_logout") + async def gewe_logout(self, event: AstrMessageEvent): + platforms = self.context.platform_manager.platform_insts + for platform in platforms: + if platform.meta().name == "gewechat": + yield event.plain_result("正在登出 gewechat") + await platform.logout() + yield event.plain_result("已登出 gewechat") + return @filter.command_group("kdb") def kdb(self):