@@ -375,13 +375,112 @@ async def shutdown_trigger_placeholder():
375375 self .bot = aiocqhttp .CQHttp ()
376376
377377 async def send_message (self , target_type : str , target_id : str , message : platform_message .MessageChain ):
378+ # Check if message contains a Forward component
379+ forward_msg = message .get_first (platform_message .Forward )
380+ if forward_msg and target_type == 'group' :
381+ # Send as merged forward message via OneBot API
382+ await self ._send_forward_message (int (target_id ), forward_msg )
383+ return
384+
378385 aiocq_msg = (await AiocqhttpMessageConverter .yiri2target (message ))[0 ]
379386
380387 if target_type == 'group' :
381388 await self .bot .send_group_msg (group_id = int (target_id ), message = aiocq_msg )
382389 elif target_type == 'person' :
383390 await self .bot .send_private_msg (user_id = int (target_id ), message = aiocq_msg )
384391
392+ async def _send_forward_message (self , group_id : int , forward : platform_message .Forward ):
393+ """Send a merged forward message to a group using NapCat extended API."""
394+ messages = []
395+
396+ for node in forward .node_list :
397+ # Build content for each node
398+ content = []
399+ if node .message_chain :
400+ for component in node .message_chain :
401+ if isinstance (component , platform_message .Plain ):
402+ if component .text :
403+ content .append ({
404+ "type" : "text" ,
405+ "data" : {"text" : component .text }
406+ })
407+ elif isinstance (component , platform_message .Image ):
408+ img_data = {}
409+ if component .base64 :
410+ b64 = component .base64
411+ if b64 .startswith ('data:' ):
412+ b64 = b64 .split (',' , 1 )[- 1 ] if ',' in b64 else b64
413+ img_data ["file" ] = f"base64://{ b64 } "
414+ elif component .url :
415+ img_data ["file" ] = component .url
416+ elif component .path :
417+ img_data ["file" ] = str (component .path )
418+
419+ if img_data :
420+ content .append ({
421+ "type" : "image" ,
422+ "data" : img_data
423+ })
424+
425+ if not content :
426+ continue
427+
428+ # Build node data - use user_id and nickname format for NapCat
429+ user_id = str (node .sender_id ) if node .sender_id else str (self .bot_account_id or "10000" )
430+ node_data = {
431+ "type" : "node" ,
432+ "data" : {
433+ "user_id" : user_id ,
434+ "nickname" : node .sender_name or "未知" ,
435+ "content" : content ,
436+ }
437+ }
438+
439+ messages .append (node_data )
440+
441+ if not messages :
442+ return
443+
444+ # Build the full message payload for NapCat's send_forward_msg API
445+ # This matches the format used by GiveMeSetuPlugin
446+ bot_id = str (self .bot_account_id ) if self .bot_account_id else "10000"
447+ payload = {
448+ "group_id" : str (group_id ),
449+ "user_id" : bot_id , # Required by NapCat for display
450+ "messages" : messages ,
451+ }
452+
453+ # Add display settings if available
454+ if forward .display :
455+ if forward .display .title :
456+ payload ["news" ] = [{"text" : forward .display .title }]
457+ if forward .display .brief :
458+ payload ["prompt" ] = forward .display .brief
459+ if forward .display .summary :
460+ payload ["summary" ] = forward .display .summary
461+ if forward .display .source :
462+ payload ["source" ] = forward .display .source
463+
464+ try :
465+ # Use send_forward_msg (NapCat extended API) instead of send_group_forward_msg
466+ await self .logger .info (f"Sending forward message to group { group_id } with { len (messages )} nodes, payload keys: { list (payload .keys ())} " )
467+ result = await self .bot .call_action ("send_forward_msg" , ** payload )
468+ await self .logger .info (f"Forward message sent to group { group_id } , result: { result } " )
469+ except Exception as e :
470+ await self .logger .error (f"Failed to send forward message to group { group_id } : { e } " )
471+ # Fallback: try standard OneBot API with integer group_id
472+ try :
473+ await self .logger .info (f"Trying fallback API send_group_forward_msg" )
474+ await self .bot .call_action (
475+ "send_group_forward_msg" ,
476+ group_id = group_id ,
477+ messages = messages
478+ )
479+ await self .logger .info (f"Forward message sent via fallback API to group { group_id } " )
480+ except Exception as e2 :
481+ await self .logger .error (f"Fallback also failed: { e2 } " )
482+ raise
483+
385484 async def reply_message (
386485 self ,
387486 message_source : platform_events .MessageEvent ,
0 commit comments