diff --git a/src/core/apis/file.ts b/src/core/apis/file.ts index de41cda5..fd6063b4 100644 --- a/src/core/apis/file.ts +++ b/src/core/apis/file.ts @@ -6,6 +6,7 @@ import { Peer, PicElement, PicType, + RawMessage, SendFileElement, SendPicElement, SendPttElement, @@ -267,6 +268,29 @@ export class NTQQFileApi { return fileTransNotifyInfo.filePath; } + async downloadRawMsgMedia(msg: RawMessage[]) { + const res = await Promise.all(msg.map(m => + this.downloadMedia(m.msgId, m.chatType, m.peerUid, m.elements[0].elementId, '', '', 1000 * 60 * 2, true) + )); + msg.forEach((m, index) => { + const element = m.elements[0]; + switch (element.elementType) { + case ElementType.PIC: + element.picElement!.sourcePath = res[index]; + break; + case ElementType.VIDEO: + element.videoElement!.filePath = res[index]; + break; + case ElementType.PTT: + element.pttElement!.filePath = res[index]; + break; + case ElementType.FILE: + element.fileElement!.filePath = res[index]; + break; + } + }); + } + async downloadMedia(msgId: string, chatType: ChatType, peerUid: string, elementId: string, thumbPath: string, sourcePath: string, timeout = 1000 * 60 * 2, force: boolean = false) { // 用于下载收到的消息中的图片等 if (sourcePath && fs.existsSync(sourcePath)) { diff --git a/src/onebot/action/msg/SendMsg.ts b/src/onebot/action/msg/SendMsg.ts index 36ac0e94..18084b19 100644 --- a/src/onebot/action/msg/SendMsg.ts +++ b/src/onebot/action/msg/SendMsg.ts @@ -203,6 +203,7 @@ export class SendMsg extends BaseAction { } const msg = (await this.core.apis.MsgApi.getMsgsByMsgId(nodeMsg.Peer, [nodeMsg.MsgId])).msgList[0]; logger.logDebug(`handleForwardedNodesPacket[PureRaw] 开始转换 ${JSON.stringify(msg)}`); + await this.core.apis.FileApi.downloadRawMsgMedia([msg]); const transformedMsg = this.core.apis.PacketApi.packetSession?.packer.packetConverter.rawMsgToPacketMsg(msg); logger.logDebug(`handleForwardedNodesPacket[PureRaw] 转换为 ${JSON.stringify(transformedMsg)}`); packetMsg.push(transformedMsg!);