From b90e45590add79c7dd3e1ba8d61eeef23b6b9980 Mon Sep 17 00:00:00 2001 From: Dong_master <2213070223@qq.com> Date: Sat, 15 Mar 2025 01:15:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=93=E5=BE=AE=E4=BF=A1=E7=BE=A4=E6=9C=89at?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=97=B6=E5=88=A0=E9=99=A4=E7=AC=AC=E4=B8=80?= =?UTF-8?q?=E4=B8=AAat=E5=B7=B2=E8=BE=BE=E5=88=B0=E8=83=BD=E6=BF=80?= =?UTF-8?q?=E6=B4=BB=E7=AE=A1=E7=90=86=E5=91=98=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/platform/sources/gewechat.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/pkg/platform/sources/gewechat.py b/pkg/platform/sources/gewechat.py index e73b85a8..9a9d2e33 100644 --- a/pkg/platform/sources/gewechat.py +++ b/pkg/platform/sources/gewechat.py @@ -62,20 +62,38 @@ class GewechatMessageConverter(adapter.MessageConverter): bot_account_id: str ) -> platform_message.MessageChain: + + # print(message) + if message["Data"]["MsgType"] == 1: # 检查消息开头,如果有 wxid_sbitaz0mt65n22:\n 则删掉 regex = re.compile(r"^wxid_.*:") + # print(message) line_split = message["Data"]["Content"]["string"].split("\n") if len(line_split) > 0 and regex.match(line_split[0]): message["Data"]["Content"]["string"] = "\n".join(line_split[1:]) - - at_string = f'@{bot_account_id}' + # 获取机器人在群内信息 + # bot_room_datas = bot.get_chatroom_member_detail( + # self.config["app_id"], + # message['Data']['FromUserName']['string'], + # [message['Data']["ToUserName"]['string']] + # )['data'] + # print(bot_room_datas) + # # 拿到机器人在群内名称 + # at_string = '' + # for bot_data in bot_room_datas: + # bot_room_name = bot_data['nickName'] + # at_string += f"@{bot_room_name}" + # 正则表达式模式,匹配'@'后跟任意数量的非空白字符 + pattern = r'@\S+' + # at_string = f"@{bot_account_id}" content_list = [] - if at_string in message["Data"]["Content"]["string"]: + if '@' 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))) + # print(re.sub(pattern, '', message["Data"]["Content"]["string"])) + content_list.append(platform_message.Plain(re.sub(pattern, '', message["Data"]["Content"]["string"]))) else: content_list = [platform_message.Plain(message["Data"]["Content"]["string"])]