优化推送能力

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