From 6754666845603602e82c017ca8eb157a72cec202 Mon Sep 17 00:00:00 2001 From: gaord Date: Wed, 23 Jul 2025 15:22:04 +0800 Subject: [PATCH] =?UTF-8?q?feat(wechatpad):=20=E6=B7=BB=E5=8A=A0=E5=AF=B9@?= =?UTF-8?q?=E6=89=80=E6=9C=89=E4=BA=BA=E7=9A=84=E6=94=AF=E6=8C=81=E5=B9=B6?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E5=A4=84=E7=90=86=E6=B6=88=E6=81=AF=E6=B4=BE?= =?UTF-8?q?=E5=8F=91=20(#1588)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在消息转换器中添加对AtAll组件的支持,将@所有人转换为特定格式。同时在消息派发时统一处理@所有人的情况,确保通知能正确发送。 --- pkg/platform/sources/wechatpad.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/pkg/platform/sources/wechatpad.py b/pkg/platform/sources/wechatpad.py index a24287cb..9bbb471d 100644 --- a/pkg/platform/sources/wechatpad.py +++ b/pkg/platform/sources/wechatpad.py @@ -40,8 +40,10 @@ class WeChatPadMessageConverter(adapter.MessageConverter): content_list = [] for component in message_chain: - if isinstance(component, platform_message.At): - content_list.append({'type': 'at', 'target': component.target}) + if isinstance(component, platform_message.AtAll): + content_list.append({"type": "at", "target": "all"}) + elif isinstance(component, platform_message.At): + content_list.append({"type": "at", "target": component.target}) elif isinstance(component, platform_message.Plain): content_list.append({'type': 'text', 'content': component.text}) elif isinstance(component, platform_message.Image): @@ -577,19 +579,26 @@ class WeChatPadAdapter(adapter.MessagePlatformAdapter): for msg in content_list: # 文本消息处理@ if msg['type'] == 'text' and at_targets: - at_nick_name_list = [] - for member in member_info: - if member['user_name'] in at_targets: - at_nick_name_list.append(f'@{member["nick_name"]}') - msg['content'] = f'{" ".join(at_nick_name_list)} {msg["content"]}' + if "all" in at_targets: + msg['content'] = f'@所有人 {msg["content"]}' + else: + at_nick_name_list = [] + for member in member_info: + if member["user_name"] in at_targets: + at_nick_name_list.append(f'@{member["nick_name"]}') + msg['content'] = f'{" ".join(at_nick_name_list)} {msg["content"]}' # 统一消息派发 handler_map = { 'text': lambda msg: self.bot.send_text_message( - to_wxid=target_id, message=msg['content'], ats=at_targets + to_wxid=target_id, + message=msg['content'], + ats= ["notify@all"] if "all" in at_targets else at_targets ), 'image': lambda msg: self.bot.send_image_message( - to_wxid=target_id, img_url=msg['image'], ats=at_targets + to_wxid=target_id, + img_url=msg["image"], + ats = ["notify@all"] if "all" in at_targets else at_targets ), 'WeChatEmoji': lambda msg: self.bot.send_emoji_message( to_wxid=target_id, emoji_md5=msg['emoji_md5'], emoji_size=msg['emoji_size']