发送时,上传到微信,获取URL,进行发送
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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}")
|
||||
|
||||
Reference in New Issue
Block a user