优化推送能力

This commit is contained in:
liuwei
2026-02-26 09:17:56 +08:00
parent dd9fc1da88
commit db58bec317

View File

@@ -236,56 +236,50 @@ class MessagePushTask(MessagePluginInterface):
raise Exception("无发送清单")
for group_id in groups:
try:
# 发送文本消息
if content_text:
await self.bot.send_text_message(group_id, content_text)
group_sent = False
for attempt in range(3):
try:
if content_text:
await self.bot.send_text_message(group_id, content_text)
# 发送图片消息
if content_image:
await self.bot.send_image_message(group_id, Path(content_image))
if content_image:
await self.bot.send_image_message(group_id, Path(content_image))
# 发送链接消息
if content_link:
# content_link json 读取内容
link_data = json.loads(content_link)
xml_content = f"{LINK_XML_NORMAL}".format(title=link_data.get('title', ''),
des=link_data.get('des', ''),
url=link_data.get('url', ''),
thumburl=thumburl_wx
)
await self.bot.send_link_xml_message(xml_content, group_id)
if content_link:
link_data = json.loads(content_link)
xml_content = f"{LINK_XML_NORMAL}".format(
title=link_data.get('title', ''),
des=link_data.get('des', ''),
url=link_data.get('url', ''),
thumburl=thumburl_wx
)
await self.bot.send_link_xml_message(xml_content, group_id)
# 发送语音消息
if content_voice:
voice_path = Path(task['content_voice'])
# 根据文件扩展名确定类型
voice_type = 'wav' if voice_path.suffix.lower() == '.wav' else 'mp3'
await self.bot.send_voice_message(group_id, Path(content_voice), voice_type)
if content_voice:
voice_path = Path(task['content_voice'])
voice_type = 'wav' if voice_path.suffix.lower() == '.wav' else 'mp3'
await self.bot.send_voice_message(group_id, Path(content_voice), voice_type)
# 发送视频消息
if content_video:
await self.bot.send_video_message(group_id, Path(content_video))
if content_video:
await self.bot.send_video_message(group_id, Path(content_video))
group_sent = True
break
except Exception as e:
self.LOG.error(f"发送消息到群组 {group_id}{attempt + 1}次失败: {e}")
if group_sent:
success_count += 1
except Exception as e:
self.LOG.error(f"发送消息到群组 {group_id} 失败: {e}")
else:
fail_count += 1
# 更新任务状态
if task['schedule_type'] == 'recurring':
# 检查是否超过重复结束时间
recurring_end = task.get('recurring_end')
if recurring_end and now > recurring_end:
# 如果超过结束时间,标记为已完成
status = 'completed'
else:
# 如果未超过结束时间,根据发送结果设置状态
if fail_count == 0:
status = 'scheduled' # 保持为已调度状态
else:
status = 'failed' # 任何失败都标记为失败
status = 'scheduled'
else:
# 非重复任务的状态处理
if fail_count == 0: