发送时,上传到微信,获取URL,进行发送
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
|
import base64
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import Dict, Any, List, Optional, Tuple
|
from typing import Dict, Any, List, Optional, Tuple
|
||||||
|
|
||||||
@@ -209,6 +211,22 @@ class MessagePushTask(MessagePluginInterface):
|
|||||||
if not self.bot:
|
if not self.bot:
|
||||||
raise Exception("机器人实例未初始化")
|
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
|
success_count = 0
|
||||||
fail_count = 0
|
fail_count = 0
|
||||||
|
|
||||||
@@ -229,7 +247,7 @@ class MessagePushTask(MessagePluginInterface):
|
|||||||
xml_content = f"{LINK_XML_NORMAL}".format(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=link_data.get('thumburl', '')
|
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)
|
||||||
|
|
||||||
@@ -305,8 +323,8 @@ class MessagePushTask(MessagePluginInterface):
|
|||||||
self.LOG.error(f"处理定时任务出错: {e}")
|
self.LOG.error(f"处理定时任务出错: {e}")
|
||||||
|
|
||||||
def _calculate_next_schedule_time(self, schedule_time: datetime, recurring_interval: str,
|
def _calculate_next_schedule_time(self, schedule_time: datetime, recurring_interval: str,
|
||||||
recurring_end: datetime, recurring_time: str,
|
recurring_end: datetime, recurring_time: str,
|
||||||
weekly_days: str = None, monthly_day: int = None) -> Optional[datetime]:
|
weekly_days: str = None, monthly_day: int = None) -> Optional[datetime]:
|
||||||
"""计算下次执行时间"""
|
"""计算下次执行时间"""
|
||||||
try:
|
try:
|
||||||
# 解析执行时间
|
# 解析执行时间
|
||||||
@@ -373,7 +391,8 @@ class MessagePushTask(MessagePluginInterface):
|
|||||||
else:
|
else:
|
||||||
days_ahead = next_weekday - current_weekday
|
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:
|
except (json.JSONDecodeError, ValueError, IndexError) as e:
|
||||||
self.LOG.error(f"处理每周执行日失败: {e}")
|
self.LOG.error(f"处理每周执行日失败: {e}")
|
||||||
|
|||||||
Reference in New Issue
Block a user