From 01f4e0b96123c869bda9f2292c87cd44b40878e2 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Sat, 18 Jan 2025 22:31:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20gewechat=20=E4=B8=BB=E5=8A=A8=E6=B6=88?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sources/gewechat/gewechat_event.py | 22 ------------------- .../gewechat/gewechat_platform_adapter.py | 16 ++++++++++++-- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/astrbot/core/platform/sources/gewechat/gewechat_event.py b/astrbot/core/platform/sources/gewechat/gewechat_event.py index e2ed4afb9..3c81f65e6 100644 --- a/astrbot/core/platform/sources/gewechat/gewechat_event.py +++ b/astrbot/core/platform/sources/gewechat/gewechat_event.py @@ -21,28 +21,6 @@ class GewechatPlatformEvent(AstrMessageEvent): @staticmethod async def send_with_client(message: MessageChain, user_name: str): - # plain = "" - # for comp in message.chain: - # if isinstance(comp, Plain): - # if message.is_split_: - # await client.send_msg(comp.text, user_name) - # else: - # plain += comp.text - # elif isinstance(comp, Image): - # if comp.file and comp.file.startswith("file:///"): - # file_path = comp.file.replace("file:///", "") - # with open(file_path, "rb") as f: - # await client.send_image(user_name, fd=f) - # elif comp.file and comp.file.startswith("http"): - # image_path = await download_image_by_url(comp.file) - # with open(image_path, "rb") as f: - # await client.send_image(user_name, fd=f) - # else: - # logger.error(f"不支持的 vchat(微信适配器) 消息类型: {comp}") - # await asyncio.sleep(random.uniform(0.5, 1.5)) # 🤓 - - # if plain: - # await client.send_msg(plain, user_name) pass diff --git a/astrbot/core/platform/sources/gewechat/gewechat_platform_adapter.py b/astrbot/core/platform/sources/gewechat/gewechat_platform_adapter.py index fe8500c7b..d0c182cc2 100644 --- a/astrbot/core/platform/sources/gewechat/gewechat_platform_adapter.py +++ b/astrbot/core/platform/sources/gewechat/gewechat_platform_adapter.py @@ -9,6 +9,7 @@ from astrbot.core.platform.astr_message_event import MessageSesion from ...register import register_platform_adapter from .gewechat_event import GewechatPlatformEvent from .client import SimpleGewechatClient +from astrbot.core.message.components import Plain if sys.version_info >= (3, 12): from typing import override @@ -28,8 +29,19 @@ class GewechatPlatformAdapter(Platform): @override async def send_by_session(self, session: MessageSesion, message_chain: MessageChain): - # from_username = session.session_id.split('$$')[0] - # await GewechatPlatformEvent.send_with_client(self.client, message_chain, from_username) + to_wxid = session.session_id + if "_" in to_wxid: + # 群聊,开启了独立会话 + _, to_wxid = to_wxid.split("_") + + if not to_wxid: + logger.error("无法获取到 to_wxid。") + return + + for comp in message_chain.chain: + if isinstance(comp, Plain): + await self.client.post_text(to_wxid, comp.text) + await super().send_by_session(session, message_chain) @override