diff --git a/astrbot/core/platform/sources/gewechat/client.py b/astrbot/core/platform/sources/gewechat/client.py index 66eded18c..f90c6954b 100644 --- a/astrbot/core/platform/sources/gewechat/client.py +++ b/astrbot/core/platform/sources/gewechat/client.py @@ -119,7 +119,8 @@ class SimpleGewechatClient(): user_real_name = d.get('PushContent', 'unknown : ').split(' : ')[0] \ .replace('在群聊中@了你', '') \ - .replace('在群聊中发了一段语音', '') # 真实昵称 + .replace('在群聊中发了一段语音', '') \ + .replace('在群聊中发了一张图片', '') # 真实昵称 abm.sender = MessageMember(user_id, user_real_name) abm.raw_message = d abm.message_str = "" @@ -200,7 +201,7 @@ class SimpleGewechatClient(): logger.info(f"设置回调结果: {json_blob}") if json_blob['ret'] != 200: raise Exception(f"设置回调失败: {json_blob}") - logger.info(f"将在 {self.callback_url} 上接收 gewechat 下发的消息。如果一直没收到消息请先尝试重启 AstrBot。") + logger.info(f"将在 {self.callback_url} 上接收 gewechat 下发的消息。如果一直没收到消息请先尝试重启 AstrBot。如果仍没收到请到管理面板聊天页输入 /gewe_logout 重新登录。") async def start_polling(self): threading.Thread(target=asyncio.run, args=(self._set_callback_url(),)).start() diff --git a/astrbot/core/platform/sources/gewechat/gewechat_event.py b/astrbot/core/platform/sources/gewechat/gewechat_event.py index f62c71145..e329780a4 100644 --- a/astrbot/core/platform/sources/gewechat/gewechat_event.py +++ b/astrbot/core/platform/sources/gewechat/gewechat_event.py @@ -1,5 +1,6 @@ import wave import uuid +import traceback import os from astrbot.core.utils.io import save_temp_img, download_image_by_url, download_file from astrbot.core.utils.tencent_record_helper import wav_to_tencent_silk @@ -104,7 +105,11 @@ class GewechatPlatformEvent(AstrMessageEvent): record_path = record_url silk_path = f"data/temp/{uuid.uuid4()}.silk" - duration = await wav_to_tencent_silk(record_path, silk_path) + try: + duration = await wav_to_tencent_silk(record_path, silk_path) + except Exception as e: + logger.error(traceback.format_exc()) + await self.send(MessageChain().message(f"语音文件转换失败。{str(e)}")) logger.info("Silk 语音文件格式转换至: " + record_path) if duration == 0: duration = get_wav_duration(record_path) @@ -126,6 +131,8 @@ class GewechatPlatformEvent(AstrMessageEvent): file_url = f"{self.client.file_server_url}/{file_id}" logger.debug(f"gewe callback file url: {file_url}") await self.client.post_file(to_wxid, file_url, file_id) + elif isinstance(comp, At): + pass else: logger.error(f"gewechat 暂不支持发送消息类型: {comp.type}") diff --git a/astrbot/core/platform/sources/gewechat/gewechat_platform_adapter.py b/astrbot/core/platform/sources/gewechat/gewechat_platform_adapter.py index 2862b817c..1ca47391e 100644 --- a/astrbot/core/platform/sources/gewechat/gewechat_platform_adapter.py +++ b/astrbot/core/platform/sources/gewechat/gewechat_platform_adapter.py @@ -30,10 +30,6 @@ class GewechatPlatformAdapter(Platform): @override async def send_by_session(self, session: MessageSesion, message_chain: MessageChain): to_wxid = session.session_id - if "_" in to_wxid: - # 群聊,开启了独立会话 - _, to_wxid = to_wxid.split("_") - if not to_wxid: logger.error("无法获取到 to_wxid。") return