From eb841fb73e1bad49639a28cc061b40a3f2412c8c Mon Sep 17 00:00:00 2001 From: Dong_master <2213070223@qq.com> Date: Sun, 16 Mar 2025 19:08:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbot=E8=87=AA=E5=B7=B1?= =?UTF-8?q?=E7=BB=99=E5=88=AB=E4=BA=BA=E5=8F=91=E6=B6=88=E6=81=AF=E6=97=B6?= =?UTF-8?q?=E6=B2=A1=E6=9C=89PushContent=E5=AD=97=E6=AE=B5=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E5=88=A4=E6=96=AD=E9=94=99=E8=AF=AF=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbot=E8=87=AA=E5=B7=B1=E5=8F=91=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E8=87=AA=E5=B7=B1=E5=9B=9E=E5=A4=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/platform/manager.py | 3 ++- pkg/platform/sources/gewechat.py | 11 ++++++++--- pkg/utils/image.py | 7 +++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/pkg/platform/manager.py b/pkg/platform/manager.py index aa0303b9..acdf0990 100644 --- a/pkg/platform/manager.py +++ b/pkg/platform/manager.py @@ -170,7 +170,8 @@ class PlatformManager: self.ap.logger.debug(f"Traceback: {traceback.format_exc()}") tasks.append(exception_wrapper(adapter)) - + + for task in tasks: self.ap.task_mgr.create_task( task, diff --git a/pkg/platform/sources/gewechat.py b/pkg/platform/sources/gewechat.py index 05785093..28a10c67 100644 --- a/pkg/platform/sources/gewechat.py +++ b/pkg/platform/sources/gewechat.py @@ -67,7 +67,7 @@ class GewechatMessageConverter(adapter.MessageConverter): if message["Data"]["MsgType"] == 1: # 检查消息开头,如果有 wxid_sbitaz0mt65n22:\n 则删掉 regex = re.compile(r"^wxid_.*:") - # print(message) + print(message) line_split = message["Data"]["Content"]["string"].split("\n") @@ -78,15 +78,20 @@ class GewechatMessageConverter(adapter.MessageConverter): pattern = r'@\S+' at_string = f"@{bot_account_id}" content_list = [] + if message['Wxid'] == message['Data']['FromUserName']['string']: + return platform_message.MessageChain() if at_string in message["Data"]["Content"]["string"]: content_list.append(platform_message.At(target=bot_account_id)) content_list.append(platform_message.Plain(message["Data"]["Content"]["string"].replace(at_string, '', 1))) # 更优雅的替换改名后@机器人,仅仅限于单独AT的情况 - elif '在群聊中@了你' in message["Data"]["PushContent"]: + elif "PushContent" in message['Data'] and '在群聊中@了你' in message["Data"]["PushContent"]: content_list.append(platform_message.At(target=bot_account_id)) content_list.append(platform_message.Plain(re.sub(pattern, '', message["Data"]["Content"]["string"]))) else: - content_list = [platform_message.Plain(message["Data"]["Content"]["string"])] + if message['Wxid'] == message['Data']['FromUserName']['string']: + pass + else: + content_list = [platform_message.Plain(message["Data"]["Content"]["string"])] return platform_message.MessageChain(content_list) diff --git a/pkg/utils/image.py b/pkg/utils/image.py index 16077ace..397707bf 100644 --- a/pkg/utils/image.py +++ b/pkg/utils/image.py @@ -15,6 +15,9 @@ import asyncio from urllib.parse import urlparse + + + async def get_gewechat_image_base64( gewechat_url: str, gewechat_file_url: str, @@ -67,6 +70,7 @@ async def get_gewechat_image_base64( } ) as response: if response.status != 200: + print(response) raise Exception(f"获取gewechat图片下载失败: {await response.text()}") resp_data = await response.json() @@ -108,6 +112,9 @@ async def get_gewechat_image_base64( raise Exception(f"获取图片失败: {str(e)}") from e + + + async def get_wecom_image_base64(pic_url: str) -> tuple[str, str]: """ 下载企业微信图片并转换为 base64