@@ -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)
@@ -741,9 +765,9 @@ func (bot *CQBot) CQSendGroupMessage(groupID int64, m gjson.Result, autoEscape b
741765 }
742766 }
743767 fixAt (elem )
744- mid := bot .SendGroupMessage (groupID , & message.SendingMessage {Elements : elem })
745- if mid == - 1 {
746- return Failed (100 , "SEND_MSG_API_ERROR" , "请参考 go-cqhttp 端输出" )
768+ mid , err := bot .SendGroupMessage (groupID , & message.SendingMessage {Elements : elem })
769+ if err != nil {
770+ return Failed (100 , "SEND_MSG_API_ERROR" , err . Error () )
747771 }
748772 log .Infof ("发送群 %v(%v) 的消息: %v (%v)" , group .Name , groupID , limitedString (m .String ()), mid )
749773 return OK (global.MSG {"message_id" : mid })
@@ -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 [0 ].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 ,
@@ -944,8 +977,11 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupID int64, m gjson.Result) globa
944977 log .Warnf ("合并转发(群)消息发送失败: 账号可能被风控." )
945978 return Failed (100 , "SEND_MSG_API_ERROR" , "请参考 go-cqhttp 端输出" )
946979 }
980+ mid := bot .InsertGroupMessage (ret )
981+ log .Infof ("发送群 %v(%v) 的合并转发消息: %v (%v)" , groupID , groupID , limitedString (m .String ()), mid )
947982 return OK (global.MSG {
948- "message_id" : bot .InsertGroupMessage (ret ),
983+ "message_id" : mid ,
984+ "forward_id" : fe .ResId ,
949985 })
950986}
951987
@@ -967,7 +1003,11 @@ func (bot *CQBot) CQSendPrivateForwardMessage(userID int64, m gjson.Result) glob
9671003 log .Warnf ("合并转发(好友)消息发送失败: 账号可能被风控." )
9681004 return Failed (100 , "SEND_MSG_API_ERROR" , "请参考 go-cqhttp 端输出" )
9691005 }
970- return OK (global.MSG {"message_id" : mid })
1006+ log .Infof ("发送好友 %v(%v) 的合并转发消息: %v (%v)" , userID , userID , limitedString (m .String ()), mid )
1007+ return OK (global.MSG {
1008+ "message_id" : mid ,
1009+ "forward_id" : fe .ResId ,
1010+ })
9711011}
9721012
9731013// CQSendPrivateMessage 发送私聊消息
@@ -1081,6 +1121,23 @@ func (bot *CQBot) CQSetGroupMemo(groupID int64, msg, img string) global.MSG {
10811121 return Failed (100 , "GROUP_NOT_FOUND" , "群聊不存在" )
10821122}
10831123
1124+ // CQDelGroupMemo 扩展API-删除群公告
1125+ // @route(_del_group_notice)
1126+ // @rename(fid->notice_id)
1127+ func (bot * CQBot ) CQDelGroupMemo (groupID int64 , fid string ) global.MSG {
1128+ if g := bot .Client .FindGroup (groupID ); g != nil {
1129+ if g .SelfPermission () == client .Member {
1130+ return Failed (100 , "PERMISSION_DENIED" , "权限不足" )
1131+ }
1132+ err := bot .Client .DelGroupNotice (groupID , fid )
1133+ if err != nil {
1134+ return Failed (100 , "DELETE_NOTICE_ERROR" , err .Error ())
1135+ }
1136+ return OK (nil )
1137+ }
1138+ return Failed (100 , "GROUP_NOT_FOUND" , "群聊不存在" )
1139+ }
1140+
10841141// CQSetGroupKick 群组踢人
10851142//
10861143// https://git.io/Jtz1V
@@ -1364,6 +1421,7 @@ func (bot *CQBot) CQGetStrangerInfo(userID int64) global.MSG {
13641421 "age" : info .Age ,
13651422 "level" : info .Level ,
13661423 "login_days" : info .LoginDays ,
1424+ "vip_level" : info .VipLevel ,
13671425 })
13681426}
13691427
0 commit comments