From 19af3740c1b028c4487b5269879fab9caea861fc Mon Sep 17 00:00:00 2001 From: Dong_master <2213070223@qq.com> Date: Fri, 28 Feb 2025 01:17:25 +0800 Subject: [PATCH 1/3] =?UTF-8?q?'=E4=B8=AA=E4=BA=BA=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E4=B8=AD=E4=B8=BB=E5=8A=A8=E5=8F=91=E9=80=81=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E7=9A=84=E4=BF=AE=E6=94=B9=EF=BC=8C=E4=BD=86=E6=98=AF=E5=8F=AA?= =?UTF-8?q?=E8=83=BD=E5=8F=91=E9=80=81=E9=93=BE=E6=8E=A5'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/platform/sources/gewechat.py | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/pkg/platform/sources/gewechat.py b/pkg/platform/sources/gewechat.py index 3f53f802..f0df4b43 100644 --- a/pkg/platform/sources/gewechat.py +++ b/pkg/platform/sources/gewechat.py @@ -43,8 +43,25 @@ class GewechatMessageConverter(adapter.MessageConverter): elif isinstance(component, platform_message.Plain): content_list.append({"type": "text", "content": component.text}) elif isinstance(component, platform_message.Image): + # if component.base64: + # arg = component.base64 + # content_list.append({"type": "image", "image": arg}) + # elif component.url: + # arg = component.url + # content_list.append({"type": "image", "image": arg}) + # elif component.path: + # arg = component.path + # content_list.append({"type": "image", "image": arg}) + # elif component.image_id: + # arg = component.image_id + # content_list.append({"type": "image", "image_id": arg}) + if not component.url: + pass + content_list.append({"type": "image", "image": component.url}) + + # content_list.append({"type": "image", "image_id": component.image_id}) - pass + # pass elif isinstance(component, platform_message.Forward): for node in component.node_list: content_list.extend(await GewechatMessageConverter.yiri2target(node.message_chain)) @@ -83,6 +100,7 @@ class GewechatMessageConverter(adapter.MessageConverter): platform_message.Plain(text="[图片内容为空]") ]) + try: base64_str, image_format = await image.get_gewechat_image_base64( gewechat_url=self.config["gewechat_url"], @@ -101,7 +119,7 @@ class GewechatMessageConverter(adapter.MessageConverter): except Exception as e: print(f"处理图片消息失败: {str(e)}") return platform_message.MessageChain([ - platform_message.Plain(text="[图片处理失败]") + platform_message.Plain(text=f"[图片处理失败]") ]) elif message["Data"]["MsgType"] == 49: @@ -239,10 +257,17 @@ class GeWeChatAdapter(adapter.MessagePlatformAdapter): message: platform_message.MessageChain ): geweap_msg = await GewechatMessageConverter.yiri2target(message) + # 此处加上群消息at处理 + # ats = [item["target"] for item in geweap_msg if item["type"] == "at"] for msg in geweap_msg: if msg['type'] == 'text': - await self.bot.post_text(app_id=self.config['app_id'], to_wxid=target_id,content=msg['content']) + await self.bot.post_text(app_id=self.config['app_id'], to_wxid=target_id, content=msg['content']) + + elif msg['type'] == 'image': + + await self.bot.post_image(app_id=self.config['app_id'], to_wxid=target_id, img_url=msg["image"]) + async def reply_message( self, From d938129884894c4d53b170774c7aa3b9f3d8176e Mon Sep 17 00:00:00 2001 From: Dong_master <2213070223@qq.com> Date: Fri, 28 Feb 2025 01:30:55 +0800 Subject: [PATCH 2/3] =?UTF-8?q?'=E5=88=A0=E9=99=A4=E5=85=88'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/platform/sources/gewechat.py | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/pkg/platform/sources/gewechat.py b/pkg/platform/sources/gewechat.py index f93cb299..f4ad57d0 100644 --- a/pkg/platform/sources/gewechat.py +++ b/pkg/platform/sources/gewechat.py @@ -43,28 +43,9 @@ class GewechatMessageConverter(adapter.MessageConverter): elif isinstance(component, platform_message.Plain): content_list.append({"type": "text", "content": component.text}) elif isinstance(component, platform_message.Image): - # if component.base64: - # arg = component.base64 - # content_list.append({"type": "image", "image": arg}) - # elif component.url: - # arg = component.url - # content_list.append({"type": "image", "image": arg}) - # elif component.path: - # arg = component.path - # content_list.append({"type": "image", "image": arg}) - # elif component.image_id: - # arg = component.image_id - # content_list.append({"type": "image", "image_id": arg}) - if not component.url: - pass - content_list.append({"type": "image", "image": component.url}) + pass - # content_list.append({"type": "image", "image_id": component.image_id}) - # pass - - # content_list.append({"type": "image", "image_id": component.image_id}) - #pass elif isinstance(component, platform_message.Voice): content_list.append({"type": "voice", "url": component.url, "length": component.length}) elif isinstance(component, platform_message.Forward): @@ -273,9 +254,6 @@ class GeWeChatAdapter(adapter.MessagePlatformAdapter): if msg['type'] == 'text': await self.bot.post_text(app_id=self.config['app_id'], to_wxid=target_id, content=msg['content']) - elif msg['type'] == 'image': - - await self.bot.post_image(app_id=self.config['app_id'], to_wxid=target_id, img_url=msg["image"]) async def reply_message( From d62d5976954d43f15d3b7508050becea068e9a80 Mon Sep 17 00:00:00 2001 From: Dong_master <2213070223@qq.com> Date: Fri, 28 Feb 2025 01:31:59 +0800 Subject: [PATCH 3/3] =?UTF-8?q?'=E4=B8=AA=E4=BA=BA=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E4=B8=AD=E4=B8=BB=E5=8A=A8=E5=8F=91=E9=80=81=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E7=9A=84=E4=BF=AE=E6=94=B9=EF=BC=8C=E4=BD=86=E6=98=AF=E5=8F=AA?= =?UTF-8?q?=E8=83=BD=E5=8F=91=E9=80=81=E9=93=BE=E6=8E=A5'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/platform/sources/gewechat.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/platform/sources/gewechat.py b/pkg/platform/sources/gewechat.py index f4ad57d0..5f8588bb 100644 --- a/pkg/platform/sources/gewechat.py +++ b/pkg/platform/sources/gewechat.py @@ -43,7 +43,9 @@ class GewechatMessageConverter(adapter.MessageConverter): elif isinstance(component, platform_message.Plain): content_list.append({"type": "text", "content": component.text}) elif isinstance(component, platform_message.Image): - pass + if not component.url: + pass + content_list.append({"type": "image", "image": component.url}) elif isinstance(component, platform_message.Voice): @@ -254,6 +256,10 @@ class GeWeChatAdapter(adapter.MessagePlatformAdapter): if msg['type'] == 'text': await self.bot.post_text(app_id=self.config['app_id'], to_wxid=target_id, content=msg['content']) + elif msg['type'] == 'image': + + await self.bot.post_image(app_id=self.config['app_id'], to_wxid=target_id, img_url=msg["image"]) + async def reply_message(