@@ -215,11 +215,11 @@ export class SendMsgBase extends OneBotAction<SendMsgPayload, ReturnDataType> {
215215 uuid ?: string ,
216216 packetMsg : PacketMsg [ ] ,
217217 deleteAfterSentFiles : string [ ] ,
218- innerPacketMsg ?: Array < { uuid : string , packetMsg : PacketMsg [ ] ; } > ;
218+ innerPacketMsg ?: Array < { uuid : string , packetMsg ? : PacketMsg [ ] , actionMsgBody ?: UploadForwardMsgParams [ 'actionMsgBody' ] ; } > ;
219219 } | null > {
220220 const packetMsg : PacketMsg [ ] = [ ] ;
221221 const delFiles : string [ ] = [ ] ;
222- const innerMsg : Array < { uuid : string , packetMsg : PacketMsg [ ] ; } > = new Array ( ) ;
222+ const innerMsg : Array < { uuid : string , packetMsg ? : PacketMsg [ ] , actionMsgBody ?: UploadForwardMsgParams [ 'actionMsgBody' ] ; } > = new Array ( ) ;
223223 for ( const node of messageNodes ) {
224224 if ( dp >= 3 ) {
225225 this . core . context . logger . logWarn ( '转发消息深度超过3层,将停止解析!' ) ;
@@ -240,7 +240,7 @@ export class SendMsgBase extends OneBotAction<SendMsgPayload, ReturnDataType> {
240240 if ( uploadReturnData ?. uuid ) {
241241 innerMsg . push ( { uuid : uploadReturnData . uuid , packetMsg : uploadReturnData . packetMsg } ) ;
242242 uploadReturnData . innerPacketMsg ?. forEach ( m => {
243- innerMsg . push ( { uuid : m . uuid , packetMsg : m . packetMsg } ) ;
243+ innerMsg . push ( m ) ;
244244 } ) ;
245245 }
246246
@@ -274,6 +274,37 @@ export class SendMsgBase extends OneBotAction<SendMsgPayload, ReturnDataType> {
274274 const msgCache = await this . core . apis . FileApi . downloadRawMsgMedia ( [ msg ] ) ;
275275 delFiles . push ( ...msgCache ) ;
276276 const transformedMsg = this . core . apis . PacketApi . pkt . msgConverter . rawMsgToPacketMsg ( msg , msgPeer ) ;
277+ // 检测嵌套合并转发消息,拉取内层protobuf数据
278+ for ( const element of msg . elements ) {
279+ let resId : string | undefined ;
280+ let uuid : string | undefined ;
281+ if ( element . multiForwardMsgElement ?. resId ) {
282+ resId = element . multiForwardMsgElement . resId ;
283+ uuid = element . multiForwardMsgElement . fileName ;
284+ } else if ( element . arkElement ?. bytesData ) {
285+ try {
286+ const json = JSON . parse ( element . arkElement . bytesData ) ;
287+ if ( json . app === 'com.tencent.multimsg' ) {
288+ resId = json . meta ?. detail ?. resid ;
289+ uuid = json . meta ?. detail ?. uniseq || json . extra ?. filename ;
290+ }
291+ } catch { /* not a valid json */ }
292+ }
293+ if ( resId && uuid ) {
294+ try {
295+ const rawActions = await this . core . apis . PacketApi . pkt . operation . FetchForwardMsgRaw ( resId ) ;
296+ for ( const action of rawActions ) {
297+ if ( action . actionCommand === 'MultiMsg' ) {
298+ innerMsg . push ( { uuid, actionMsgBody : action . actionData . msgBody } ) ;
299+ } else {
300+ innerMsg . push ( { uuid : action . actionCommand , actionMsgBody : action . actionData . msgBody } ) ;
301+ }
302+ }
303+ } catch ( e ) {
304+ this . core . context . logger . logError ( `获取合并转发内层消息失败: ${ ( e as Error ) ?. stack } ` ) ;
305+ }
306+ }
307+ }
277308 this . core . context . logger . logDebug ( `handleForwardedNodesPacket[PureRaw] 转换为 ${ stringifyWithBigInt ( transformedMsg ) } ` ) ;
278309 packetMsg . push ( transformedMsg ) ;
279310 }
@@ -289,10 +320,11 @@ export class SendMsgBase extends OneBotAction<SendMsgPayload, ReturnDataType> {
289320 actionCommand : 'MultiMsg' ,
290321 actionMsg : packetMsg ,
291322 } ] ;
292- innerMsg . forEach ( ( { uuid, packetMsg : msg } ) => {
323+ innerMsg . forEach ( ( { uuid, packetMsg : msg , actionMsgBody : raw } ) => {
293324 uploadMsgData . push ( {
294325 actionCommand : uuid ,
295326 actionMsg : msg ,
327+ actionMsgBody : raw ,
296328 } ) ;
297329 } ) ;
298330 const resid = await this . core . apis . PacketApi . pkt . operation . UploadForwardMsgV2 ( uploadMsgData , msgPeer . chatType === ChatType . KCHATTYPEGROUP ? + msgPeer . peerUid : 0 ) ;
0 commit comments