优化定时订阅内容

This commit is contained in:
liuwei
2025-12-17 14:07:02 +08:00
parent 4bf44a5592
commit cb3f9b7d55

View File

@@ -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}")