发送时,上传到微信,获取URL,进行发送

This commit is contained in:
liuwei
2025-06-11 10:58:42 +08:00
parent 3982319e1d
commit c85cf16368

View File

@@ -1,4 +1,6 @@
import base64
import json
import os
from datetime import datetime, timedelta
from typing import Dict, Any, List, Optional, Tuple
@@ -209,6 +211,22 @@ class MessagePushTask(MessagePluginInterface):
if not self.bot:
raise Exception("机器人实例未初始化")
# 发送链接消息,提前进行数据整理,上传缩略图
if content_link:
# content_link json 读取内容
link_data = json.loads(content_link)
thumburl_path = link_data.get('thumburl', '')
thumburl_wx = ""
if thumburl_path and os.path.exists(thumburl_path):
# Read local image file
with open(thumburl_path, 'rb') as image_file:
# Convert image to base64
base64_string = base64.b64encode(image_file.read()).decode('utf-8')
# Call upload method with base64 string
thumburl_wx = await self.bot.friend_circle_upload(base64=base64_string)
else:
print(f"Image file not found at: {thumburl_path}")
success_count = 0
fail_count = 0
@@ -229,7 +247,7 @@ class MessagePushTask(MessagePluginInterface):
xml_content = f"{LINK_XML_NORMAL}".format(title=link_data.get('title', ''),
des=link_data.get('des', ''),
url=link_data.get('url', ''),
thumburl=link_data.get('thumburl', '')
thumburl=thumburl_wx
)
await self.bot.send_link_xml_message(xml_content, group_id)
@@ -305,8 +323,8 @@ class MessagePushTask(MessagePluginInterface):
self.LOG.error(f"处理定时任务出错: {e}")
def _calculate_next_schedule_time(self, schedule_time: datetime, recurring_interval: str,
recurring_end: datetime, recurring_time: str,
weekly_days: str = None, monthly_day: int = None) -> Optional[datetime]:
recurring_end: datetime, recurring_time: str,
weekly_days: str = None, monthly_day: int = None) -> Optional[datetime]:
"""计算下次执行时间"""
try:
# 解析执行时间
@@ -373,7 +391,8 @@ class MessagePushTask(MessagePluginInterface):
else:
days_ahead = next_weekday - current_weekday
next_time = now.replace(hour=hour, minute=minute, second=second, microsecond=0) + timedelta(days=days_ahead)
next_time = now.replace(hour=hour, minute=minute, second=second, microsecond=0) + timedelta(
days=days_ahead)
except (json.JSONDecodeError, ValueError, IndexError) as e:
self.LOG.error(f"处理每周执行日失败: {e}")