加入CND图片保存逻辑

This commit is contained in:
liuwei
2025-05-07 14:46:06 +08:00
parent 0d6e047c5d
commit 62c1599932
2 changed files with 33 additions and 9 deletions

View File

@@ -128,7 +128,7 @@ class MessageSummaryPlugin(MessagePluginInterface):
self.LOG.error(f"处理消息总结命令失败: {e}")
return False, None
def _async_generate_and_send_summary(self, chat_content: str, group_name: str, group_id: str,
async def _async_generate_and_send_summary(self, chat_content: str, group_name: str, group_id: str,
message: Dict[str, Any]):
"""异步生成并发送总结"""
try:
@@ -136,12 +136,12 @@ class MessageSummaryPlugin(MessagePluginInterface):
summary, image_path = self._generate_summary(chat_content, group_name)
if image_path:
self.bot.send_image_message(group_id, Path(image_path))
await self.bot.send_image_message(group_id, Path(image_path))
else:
self.bot.send_text_message(group_id, "❌ 生成总结图片失败")
await self.bot.send_text_message(group_id, "❌ 生成总结图片失败")
except Exception as e:
self.LOG.error(f"异步生成总结失败: {e}")
self.bot.send_text_message(group_id, f"❌ 生成总结失败: {str(e)}")
await self.bot.send_text_message(group_id, f"❌ 生成总结失败: {str(e)}")
def _sanitize_group_name(self, group_name: str) -> str:
"""处理群名,去除特殊字符并限制长度"""

View File

@@ -69,10 +69,33 @@ class ToolMixin(WechatAPIClientBase):
return json_resp.get("Data").get("data").get("buffer")
else:
self.error_handler(json_resp)
async def download_attach_xml(self, xml_str: str) -> str:
#读取消息信息,进行处理
import xml.etree.ElementTree as ET
root = ET.fromstring(xml_str)
appmsg = root.find("appmsg")
appid = appmsg.attrib.get("appid", "")
appattach = appmsg.find("appattach")
attach_id = appattach.findtext("attachid", "")
datalen = int(appattach.findtext("totallen", "0"))
username = root.findtext("fromusername", "")
async def download_attach(self, attach_id: str) -> dict:
return self.download_attach(attach_id, datalen, username, appid)
async def download_attach(self, attach_id: str, datalen: int, username: str, appid: str) -> str:
"""下载附件。
{
"AppID": "wx6618f1cfc6c132f8",
"AttachId": "@cdn_3057020100044b304902010002042d0c366c02032df7950204d35d06af0204681af942042438363966373134342d663961352d343065612d623038662d3062643730663335343731370204052400050201000405004c54a100_c57ad24ba4e9ceeb3c5e10e33361028d_1",
"DataLen": 1160,
"Section": {
"DataLen": 1160,
"StartPos": 0
},
"UserName": "Jyunere",
"Wxid": "wxid_ts8v7yk4g5c522"
}
Args:
attach_id (str): 附件ID
@@ -87,8 +110,9 @@ class ToolMixin(WechatAPIClientBase):
raise UserLoggedOut("请先登录")
async with aiohttp.ClientSession() as session:
json_param = {"Wxid": self.wxid, "AttachId": attach_id}
response = await session.post(f'http://{self.ip}:{self.port}/DownloadAttach', json=json_param)
json_param = {"Wxid": self.wxid, "AttachId": attach_id, "DataLen": datalen,
"Section": {"DataLen": datalen, "StartPos": 0}, "UserName": username, "AppID": appid}
response = await session.post(f'http://{self.ip}:{self.port}/api/Tools/DownloadFile', json=json_param)
json_resp = await response.json()
if json_resp.get("Success"):
@@ -358,4 +382,4 @@ class ToolMixin(WechatAPIClientBase):
Returns:
bytes: WAV格式的字节数据
"""
return await ToolMixin.silk_byte_to_byte_wav_byte(base64.b64decode(silk_base64))
return await ToolMixin.silk_byte_to_byte_wav_byte(base64.b64decode(silk_base64))