From cb3f9b7d55fd0c7a7e2b06a889f4f4d9251ff795 Mon Sep 17 00:00:00 2001 From: liuwei Date: Wed, 17 Dec 2025 14:07:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AE=9A=E6=97=B6=E8=AE=A2?= =?UTF-8?q?=E9=98=85=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/weather/main.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/plugins/weather/main.py b/plugins/weather/main.py index 90d788e..339ae01 100644 --- a/plugins/weather/main.py +++ b/plugins/weather/main.py @@ -272,16 +272,31 @@ class WeatherPlugin(MessagePluginInterface): today_str = datetime.datetime.now().strftime("%m月%d日") final_msg = f"📅 {today_str} 天气早报\n{push_content}" + # 聚合到目标ID维度:同一群只发一次,并@所有订阅者 + target_map = {} for user in user_list: room_id = user.get('room_id') sender_id = user.get('sender_id') target_id = room_id if room_id else sender_id + if target_id not in target_map: + target_map[target_id] = { + 'mentions': set(), + 'is_group': bool(room_id) + } + # 仅在群聊中@订阅者;私聊无需@列表 + if room_id: + target_map[target_id]['mentions'].add(sender_id) + for target_id, info in target_map.items(): await asyncio.sleep(0.5) try: if self.bot: - await self.bot.send_at_message(target_id, final_msg, - [sender_id]) + mentions = list(info['mentions']) if info['is_group'] else [] + if mentions: + await self.bot.send_at_message(target_id, final_msg, mentions) + else: + # 私聊:直接发送文本 + await self.bot.send_text_message(target_id, final_msg) except Exception as send_e: self.LOG.error(f"推送给 {target_id} 失败: {send_e}")