@@ -601,6 +601,30 @@ func (bot *CQBot) CQUploadGroupFile(groupID int64, file, name, folder string) gl
601601 return OK (nil )
602602}
603603
604+ // CQUploadPrivateFile 扩展API-上传私聊文件
605+ //
606+ // @route(upload_private_file)
607+ func (bot * CQBot ) CQUploadPrivateFile (userID int64 , file , name string ) global.MSG {
608+ target := message.Source {
609+ SourceType : message .SourcePrivate ,
610+ PrimaryID : userID ,
611+ }
612+ fileBody , err := os .Open (file )
613+ if err != nil {
614+ log .Warnf ("上传私聊文件 %v 失败: %+v" , file , err )
615+ return Failed (100 , "OPEN_FILE_ERROR" , "打开文件失败" )
616+ }
617+ localFile := & client.LocalFile {
618+ FileName : name ,
619+ Body : fileBody ,
620+ }
621+ if err := bot .Client .UploadFile (target , localFile ); err != nil {
622+ log .Warnf ("上传私聊 %v 文件 %v 失败: %+v" , userID , file , err )
623+ return Failed (100 , "FILE_SYSTEM_UPLOAD_API_ERROR" , err .Error ())
624+ }
625+ return OK (nil )
626+ }
627+
604628// CQGroupFileCreateFolder 拓展API-创建群文件文件夹
605629//
606630// @route(create_group_file_folder)
@@ -808,7 +832,12 @@ func (bot *CQBot) uploadForwardElement(m gjson.Result, target int64, sourceType
808832 groupID := target
809833 source := message.Source {SourceType : sourceType , PrimaryID : target }
810834 if sourceType == message .SourcePrivate {
811- groupID = 0
835+ // ios 设备的合并转发来源群号不能为 0
836+ if len (bot .Client .GroupList ) == 0 {
837+ groupID = 1
838+ } else {
839+ groupID = bot .Client .GroupList [1 ].Uin
840+ }
812841 }
813842 builder := bot .Client .NewForwardMessageBuilder (groupID )
814843
@@ -849,17 +878,21 @@ func (bot *CQBot) uploadForwardElement(m gjson.Result, target int64, sourceType
849878 }
850879 if e .Get ("data.id" ).Exists () {
851880 i := e .Get ("data.id" ).Int ()
852- m , _ := db .GetGroupMessageByGlobalID (int32 (i ))
881+ m , _ := db .GetMessageByGlobalID (int32 (i ))
853882 if m != nil {
854- msgTime := m .Attribute .Timestamp
883+ mSource := message .SourcePrivate
884+ if m .GetType () == "group" {
885+ mSource = message .SourceGroup
886+ }
887+ msgTime := m .GetAttribute ().Timestamp
855888 if msgTime == 0 {
856889 msgTime = ts .Unix ()
857890 }
858891 return & message.ForwardNode {
859- SenderId : m .Attribute .SenderUin ,
860- SenderName : m .Attribute .SenderName ,
892+ SenderId : m .GetAttribute () .SenderUin ,
893+ SenderName : m .GetAttribute () .SenderName ,
861894 Time : int32 (msgTime ),
862- Message : resolveElement (bot .ConvertContentMessage (m .Content , message . SourceGroup )),
895+ Message : resolveElement (bot .ConvertContentMessage (m .GetContent (), mSource )),
863896 }
864897 }
865898 log .Warnf ("警告: 引用消息 %v 错误或数据库未开启." , e .Get ("data.id" ).Str )
@@ -892,7 +925,7 @@ func (bot *CQBot) uploadForwardElement(m gjson.Result, target int64, sourceType
892925 }
893926 }
894927 }
895- content := bot .ConvertObjectMessage (c , message . SourceGroup )
928+ content := bot .ConvertObjectMessage (c , sourceType )
896929 if uin != 0 && name != "" && len (content ) > 0 {
897930 return & message.ForwardNode {
898931 SenderId : uin ,
@@ -1364,6 +1397,7 @@ func (bot *CQBot) CQGetStrangerInfo(userID int64) global.MSG {
13641397 "age" : info .Age ,
13651398 "level" : info .Level ,
13661399 "login_days" : info .LoginDays ,
1400+ "vip_level" : info .VipLevel ,
13671401 })
13681402}
13691403
0 commit comments