From 3e9dac73ffcee2349d9fff37abb467631cfc1bd3 Mon Sep 17 00:00:00 2001 From: Redmomn <109732988+Redmomn@users.noreply.github.com> Date: Fri, 4 Oct 2024 23:09:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B7=BB=E5=8A=A0=E7=BE=A4=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=93=8D=E4=BD=9C=E5=92=8C=E4=B8=80=E4=BA=9B=E7=BB=86?= =?UTF-8?q?=E8=8A=82=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- coolq/api.go | 282 ++++++++++++++++++++---------------------------- coolq/bot.go | 6 +- coolq/cqcode.go | 48 +++------ coolq/event.go | 37 +++---- go.mod | 2 +- go.sum | 4 +- 6 files changed, 153 insertions(+), 226 deletions(-) diff --git a/coolq/api.go b/coolq/api.go index b4b5da581..6627d89cc 100644 --- a/coolq/api.go +++ b/coolq/api.go @@ -204,183 +204,131 @@ func (bot *CQBot) CQGetGroupMemberInfo(groupID, userID int64, noCache bool) glob return OK(convertGroupMemberInfo(groupID, member)) } -// TODO 不支持的api,扔了先 // CQGetGroupFileSystemInfo 扩展API-获取群文件系统信息 // // https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F%E4%BF%A1%E6%81%AF // @route(get_group_file_system_info) -//func (bot *CQBot) CQGetGroupFileSystemInfo(groupID int64) global.MSG { -// fs, err := bot.Client.GetGroupFileSystem(groupID) -// if err != nil { -// log.Warnf("获取群 %v 文件系统信息失败: %v", groupID, err) -// return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error()) -// } -// return OK(fs) -//} +func (bot *CQBot) CQGetGroupFileSystemInfo(groupID int64) global.MSG { + fs, err := bot.Client.GetGroupFileSystemInfo(uint32(groupID)) + if err != nil { + log.Warnf("获取群 %v 文件系统信息失败: %v", groupID, err) + return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error()) + } + return OK(fs) +} -// TODO 不支持的api,扔了先 // CQGetGroupRootFiles 扩展API-获取群根目录文件列表 // // https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%A0%B9%E7%9B%AE%E5%BD%95%E6%96%87%E4%BB%B6%E5%88%97%E8%A1%A8 // @route(get_group_root_files) -//func (bot *CQBot) CQGetGroupRootFiles(groupID int64) global.MSG { -// fs, err := bot.Client.GetGroupFileSystem(groupID) -// if err != nil { -// log.Warnf("获取群 %v 文件系统信息失败: %v", groupID, err) -// return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error()) -// } -// files, folders, err := fs.Root() -// if err != nil { -// log.Warnf("获取群 %v 根目录文件失败: %v", groupID, err) -// return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error()) -// } -// return OK(global.MSG{ -// "files": files, -// "folders": folders, -// }) -//} +func (bot *CQBot) CQGetGroupRootFiles(groupID int64) global.MSG { + files, folders, err := bot.Client.ListGroupRootFiles(uint32(groupID)) + if err != nil { + log.Warnf("获取群 %v 根目录文件失败: %v", groupID, err) + return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error()) + } + return OK(global.MSG{ + "files": files, + "folders": folders, + }) +} -// TODO 不支持的api,扔了先 // CQGetGroupFilesByFolderID 扩展API-获取群子目录文件列表 // // https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E5%AD%90%E7%9B%AE%E5%BD%95%E6%96%87%E4%BB%B6%E5%88%97%E8%A1%A8 // @route(get_group_files_by_folder) -//func (bot *CQBot) CQGetGroupFilesByFolderID(groupID int64, folderID string) global.MSG { -// fs, err := bot.Client.GetGroupFileSystem(groupID) -// if err != nil { -// log.Warnf("获取群 %v 文件系统信息失败: %v", groupID, err) -// return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error()) -// } -// files, folders, err := fs.GetFilesByFolder(folderID) -// if err != nil { -// log.Warnf("获取群 %v 根目录 %v 子文件失败: %v", groupID, folderID, err) -// return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error()) -// } -// return OK(global.MSG{ -// "files": files, -// "folders": folders, -// }) -//} +func (bot *CQBot) CQGetGroupFilesByFolderID(groupID int64, folderID string) global.MSG { + files, folders, err := bot.Client.ListGroupFilesByFolder(uint32(groupID), folderID) + if err != nil { + log.Warnf("获取群 %v 根目录 %v 子文件失败: %v", groupID, folderID, err) + return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error()) + } + return OK(global.MSG{ + "files": files, + "folders": folders, + }) +} -// TODO 不支持的api,扔了先 // CQGetGroupFileURL 扩展API-获取群文件资源链接 // // https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%96%87%E4%BB%B6%E8%B5%84%E6%BA%90%E9%93%BE%E6%8E%A5 // @route(get_group_file_url) // @rename(bus_id->"[busid\x2Cbus_id].0") -//func (bot *CQBot) CQGetGroupFileURL(groupID int64, fileID string, busID int32) global.MSG { -// url := bot.Client.GetGroupFileUrl(groupID, fileID, busID) -// if url == "" { -// return Failed(100, "FILE_SYSTEM_API_ERROR") -// } -// return OK(global.MSG{ -// "url": url, -// }) -//} +func (bot *CQBot) CQGetGroupFileURL(groupID int64, fileID string, busID int32) global.MSG { + url, err := bot.Client.GetGroupFileUrl(uint32(groupID), fileID) + if err != nil { + return Failed(100, "FILE_SYSTEM_API_ERROR") + } + return OK(global.MSG{ + "url": url, + }) +} -// TODO 不支持的api,扔了先 // CQUploadGroupFile 扩展API-上传群文件 // // https://docs.go-cqhttp.org/api/#%E4%B8%8A%E4%BC%A0%E7%BE%A4%E6%96%87%E4%BB%B6 // @route(upload_group_file) -//func (bot *CQBot) CQUploadGroupFile(groupID int64, file, name, folder string) global.MSG { -// if !global.PathExists(file) { -// log.Warnf("上传群文件 %v 失败: 文件不存在", file) -// return Failed(100, "FILE_NOT_FOUND", "文件不存在") -// } -// fs, err := bot.Client.GetGroupFileSystem(groupID) -// if err != nil { -// log.Warnf("获取群 %v 文件系统信息失败: %v", groupID, err) -// return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error()) -// } -// if folder == "" { -// folder = "/" -// } -// if err = fs.UploadFile(file, name, folder); err != nil { -// log.Warnf("上传群 %v 文件 %v 失败: %v", groupID, file, err) -// return Failed(100, "FILE_SYSTEM_UPLOAD_API_ERROR", err.Error()) -// } -// return OK(nil) -//} +func (bot *CQBot) CQUploadGroupFile(groupID int64, file, name, folder string) global.MSG { + if !global.PathExists(file) { + log.Warnf("上传群文件 %v 失败: 文件不存在", file) + return Failed(100, "FILE_NOT_FOUND", "文件不存在") + } + if err := bot.Client.UploadGroupFile(uint32(groupID), file, name, utils.Ternary(folder == "", "/", folder)); err != nil { + log.Warnf("上传群 %v 文件 %v 失败: %v", groupID, file, err) + return Failed(100, "FILE_SYSTEM_UPLOAD_API_ERROR", err.Error()) + } + return OK(nil) +} -// TODO 不支持的api,扔了先 // CQUploadPrivateFile 扩展API-上传私聊文件 // // @route(upload_private_file) -//func (bot *CQBot) CQUploadPrivateFile(userID int64, file, name string) global.MSG { -// target := message.Source{ -// SourceType: message.SourcePrivate, -// PrimaryID: userID, -// } -// fileBody, err := os.Open(file) -// if err != nil { -// log.Warnf("上传私聊文件 %v 失败: %+v", file, err) -// return Failed(100, "OPEN_FILE_ERROR", "打开文件失败") -// } -// defer func() { _ = fileBody.Close() }() -// localFile := &client.LocalFile{ -// FileName: name, -// Body: fileBody, -// } -// if err := bot.Client.UploadFile(target, localFile); err != nil { -// log.Warnf("上传私聊 %v 文件 %v 失败: %+v", userID, file, err) -// return Failed(100, "FILE_SYSTEM_UPLOAD_API_ERROR", err.Error()) -// } -// return OK(nil) -//} +func (bot *CQBot) CQUploadPrivateFile(userID int64, file, name string) global.MSG { + if !global.PathExists(file) { + log.Warnf("上传群文件 %v 失败: 文件不存在", file) + return Failed(100, "FILE_NOT_FOUND", "文件不存在") + } + if err := bot.Client.UploadPrivateFile(uint32(userID), file, name); err != nil { + log.Warnf("上传私聊 %v 文件 %v 失败: %+v", userID, file, err) + return Failed(100, "FILE_SYSTEM_UPLOAD_API_ERROR", err.Error()) + } + return OK(nil) +} -// TODO 不支持的api,扔了先 // CQGroupFileCreateFolder 拓展API-创建群文件文件夹 // // @route(create_group_file_folder) -//func (bot *CQBot) CQGroupFileCreateFolder(groupID int64, parentID, name string) global.MSG { -// fs, err := bot.Client.GetGroupFileSystem(groupID) -// if err != nil { -// log.Warnf("获取群 %v 文件系统信息失败: %v", groupID, err) -// return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error()) -// } -// if err = fs.CreateFolder(parentID, name); err != nil { -// log.Warnf("创建群 %v 文件夹失败: %v", groupID, err) -// return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error()) -// } -// return OK(nil) -//} +func (bot *CQBot) CQGroupFileCreateFolder(groupID int64, parentID, name string) global.MSG { + if err := bot.Client.CreateGroupFolder(uint32(groupID), parentID, name); err != nil { + log.Warnf("创建群 %v 文件夹失败: %v", groupID, err) + return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error()) + } + return OK(nil) +} -// TODO 不支持的api,扔了先 // CQGroupFileDeleteFolder 拓展API-删除群文件文件夹 // // @route(delete_group_folder) // @rename(id->folder_id) -//func (bot *CQBot) CQGroupFileDeleteFolder(groupID int64, id string) global.MSG { -// fs, err := bot.Client.GetGroupFileSystem(groupID) -// if err != nil { -// log.Warnf("获取群 %v 文件系统信息失败: %v", groupID, err) -// return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error()) -// } -// if err = fs.DeleteFolder(id); err != nil { -// log.Warnf("删除群 %v 文件夹 %v 时出现文件: %v", groupID, id, err) -// return Failed(200, "FILE_SYSTEM_API_ERROR", err.Error()) -// } -// return OK(nil) -//} +func (bot *CQBot) CQGroupFileDeleteFolder(groupID int64, id string) global.MSG { + if err := bot.Client.DeleteGroupFolder(uint32(groupID), id); err != nil { + log.Warnf("删除群 %v 文件夹 %v 时出现错误: %v", groupID, id, err) + return Failed(200, "FILE_SYSTEM_API_ERROR", err.Error()) + } + return OK(nil) +} -// TODO 不支持的api,扔了先 // CQGroupFileDeleteFile 拓展API-删除群文件 // // @route(delete_group_file) // @rename(id->file_id, bus_id->"[busid\x2Cbus_id].0") -//func (bot *CQBot) CQGroupFileDeleteFile(groupID int64, id string, busID int32) global.MSG { -// fs, err := bot.Client.GetGroupFileSystem(groupID) -// if err != nil { -// log.Warnf("获取群 %v 文件系统信息失败: %v", groupID, err) -// return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error()) -// } -// if res := fs.DeleteFile("", id, busID); res != "" { -// log.Warnf("删除群 %v 文件 %v 时出现文件: %v", groupID, id, res) -// return Failed(200, "FILE_SYSTEM_API_ERROR", res) -// } -// return OK(nil) -//} +func (bot *CQBot) CQGroupFileDeleteFile(groupID int64, id string, busID int32) global.MSG { + if err := bot.Client.DeleteGroupFile(uint32(groupID), id); err != nil { + log.Warnf("删除群 %v 文件 %v 时出现错误: %v", groupID, id, err) + return Failed(200, "FILE_SYSTEM_API_ERROR", err.Error()) + } + return OK(nil) +} // CQSendMessage 发送消息 // @@ -882,11 +830,17 @@ func (bot *CQBot) CQProcessFriendRequest(flag string, approve bool) global.MSG { // @rename(sub_type->"[sub_type\x2Ctype].0") // @default(approve=true) func (bot *CQBot) CQProcessGroupRequest(flag, subType, reason string, approve bool) global.MSG { - msgs, err := bot.Client.GetGroupSystemMessages() + msgs, err := bot.Client.GetGroupSystemMessages(false, 20) + if err != nil { + log.Warnf("获取群系统消息失败: %v", err) + return Failed(100, "SYSTEM_MSG_API_ERROR", err.Error()) + } + filteredmsgs, err := bot.Client.GetGroupSystemMessages(true, 20) if err != nil { log.Warnf("获取群系统消息失败: %v", err) return Failed(100, "SYSTEM_MSG_API_ERROR", err.Error()) } + msgs = append(msgs, filteredmsgs...) if subType == "add" { for _, req := range msgs { if strconv.FormatInt(int64(req.Sequence), 10) == flag { @@ -895,9 +849,9 @@ func (bot *CQBot) CQProcessGroupRequest(flag, subType, reason string, approve bo return Failed(100, "FLAG_HAS_BEEN_CHECKED", "消息已被处理") } if approve { - _ = bot.Client.SetGroupRequest(true, req.Sequence, req.EventType, req.GroupUin, "") + _ = bot.Client.SetGroupRequest(req.IsFiltered, true, req.Sequence, req.EventType, req.GroupUin, "") } else { - _ = bot.Client.SetGroupRequest(false, req.Sequence, req.EventType, req.GroupUin, reason) + _ = bot.Client.SetGroupRequest(req.IsFiltered, false, req.Sequence, req.EventType, req.GroupUin, reason) } return OK(nil) } @@ -910,9 +864,9 @@ func (bot *CQBot) CQProcessGroupRequest(flag, subType, reason string, approve bo return Failed(100, "FLAG_HAS_BEEN_CHECKED", "消息已被处理") } if approve { - _ = bot.Client.SetGroupRequest(true, req.Sequence, req.EventType, req.GroupUin, "") + _ = bot.Client.SetGroupRequest(req.IsFiltered, true, req.Sequence, req.EventType, req.GroupUin, "") } else { - _ = bot.Client.SetGroupRequest(false, req.Sequence, req.EventType, req.GroupUin, reason) + _ = bot.Client.SetGroupRequest(req.IsFiltered, false, req.Sequence, req.EventType, req.GroupUin, reason) } return OK(nil) } @@ -1062,31 +1016,31 @@ func (bot *CQBot) CQSetGroupAdmin(groupID, userID int64, enable bool) global.MSG // https://git.io/Jtz17 // @route11(get_stranger_info) // @route12(get_user_info) -//func (bot *CQBot) CQGetStrangerInfo(userID int64) global.MSG { -// info, err := bot.Client.GetSummaryInfo(userID) -// if err != nil { -// return Failed(100, "SUMMARY_API_ERROR", err.Error()) -// } -// return OK(global.MSG{ -// "user_id": info.Uin, -// "nickname": info.Nickname, -// "qid": info.Qid, -// "sex": func() string { -// if info.Sex == 1 { -// return "female" -// } else if info.Sex == 0 { -// return "male" -// } -// // unknown = 0x2 -// return "unknown" -// }(), -// "sign": info.Sign, -// "age": info.Age, -// "level": info.Level, -// "login_days": info.LoginDays, -// "vip_level": info.VipLevel, -// }) -//} +func (bot *CQBot) CQGetStrangerInfo(userID int64) global.MSG { + info, err := bot.Client.FetchUserInfoUin(uint32(userID)) + if err != nil { + return Failed(100, "SUMMARY_API_ERROR", err.Error()) + } + return OK(global.MSG{ + "user_id": info.Uin, + "nickname": info.Nickname, + //"qid": info.Qid, + "sex": func() string { + //if info.Sex == 1 { + // return "female" + //} else if info.Sex == 0 { + // return "male" + //} + // unknown = 0x2 + return "unknown" + }(), + //"sign": info.Sign, + //"age": info.Age, + //"level": info.Level, + //"login_days": info.LoginDays, + //"vip_level": info.VipLevel, + }) +} // CQHandleQuickOperation 隐藏API-对事件执行快速操作 // diff --git a/coolq/bot.go b/coolq/bot.go index 147f0b834..a842e0457 100644 --- a/coolq/bot.go +++ b/coolq/bot.go @@ -195,7 +195,7 @@ func (bot *CQBot) uploadLocalVideo(target message.Source, v *msg.LocalVideo) (*m return nil, err } defer func() { _ = video.Close() }() - return bot.Client.UploadShortVideo(target, message.NewSteramVideo(video, v.Thumb)) + return bot.Client.UploadShortVideo(target, message.NewStreamVideo(video, v.Thumb)) } func removeLocalElement(elements []message.IMessageElement) []message.IMessageElement { @@ -301,7 +301,7 @@ func (bot *CQBot) SendGroupMessage(groupID int64, m *message.SendingMessage) (in return -1, errors.New("empty message") } m.Elements = newElem - bot.checkMedia(newElem, groupID) + bot.checkMedia(newElem, source) ret, err := bot.Client.SendGroupMessage(uint32(groupID), m.Elements, false) if err != nil || ret == nil { if errors.Is(err, sign.VersionMismatchError) { @@ -340,7 +340,7 @@ func (bot *CQBot) SendPrivateMessage(target int64, groupID int64, m *message.Sen return -1 } m.Elements = newElem - bot.checkMedia(newElem, int64(bot.Client.Uin)) + bot.checkMedia(newElem, source) // 单向好友是否存在 //unidirectionalFriendExists := func() bool { diff --git a/coolq/cqcode.go b/coolq/cqcode.go index b7b4ae046..f4f4450f1 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -173,7 +173,7 @@ func toElements(e []message.IMessageElement, source message.Source) (r []msg.Ele case *message.ImageElement: data := pairs{ {K: "file", V: hex.EncodeToString(o.Md5) + ".image"}, - {K: "subType", V: strconv.FormatInt(int64(o.ImageType), 10)}, + {K: "subType", V: strconv.FormatInt(int64(o.SubType), 10)}, {K: "url", V: o.Url}, } //switch { @@ -345,7 +345,7 @@ func ToMessageContent(e []message.IMessageElement, source message.Source) (r []g "data": global.MSG{"file": o.Name, "url": o.Url}, } case *message.ImageElement: - data := global.MSG{"file": hex.EncodeToString(o.Md5) + ".image", "url": o.Url, "subType": uint32(o.ImageType)} + data := global.MSG{"file": hex.EncodeToString(o.Md5) + ".image", "url": o.Url, "subType": uint32(o.SubType)} switch { case o.Flash: data["type"] = "flash" @@ -657,9 +657,7 @@ func (bot *CQBot) ConvertElement(spec *onebot.Spec, elem msg.Element, sourceType img.Flash = flash img.EffectID = int32(id) i, _ := strconv.ParseInt(elem.Get("subType"), 10, 64) - img.ImageType = int32(i) - //case *message.FriendImageElement: - // img.Flash = flash + img.SubType = int32(i) } return img, nil case "reply": @@ -1004,34 +1002,22 @@ func (bot *CQBot) readImageCache(b []byte, sourceType message.SourceType) (messa return nil, errors.New("invalid cache") } r := binary.NewReader(b) - _ = r.ReadBytes(16) - //hash := r.ReadBytes(16) - size := r.ReadI32() - r.ReadStringWithLength("u32", true) - imageURL := r.ReadStringWithLength("u32", true) - if size == 0 && imageURL != "" { - // TODO: fix this - var elem msg.Element - elem.Type = "image" - elem.Data = []msg.Pair{{K: "file", V: imageURL}} - return bot.makeImageOrVideoElem(elem, false, sourceType) + hash := r.ReadBytes(16) + fileUuid := r.ReadStringWithLength("u32", true) + var rsp *message.ImageElement + switch sourceType { // nolint:exhaustive + case message.SourceGroup: + rsp, err = bot.Client.QueryGroupImage(hash, fileUuid) + default: + rsp, err = bot.Client.QueryFriendImage(hash, fileUuid) } - var rsp message.IMessageElement - // TODO 不知道这里是干嘛的 - //switch sourceType { // nolint:exhaustive - //case message.SourceGroup: - // rsp, err = bot.Client.QueryGroupImage(int64(rand.Uint32()), hash, size) - //default: - // rsp, err = bot.Client.QueryFriendImage(int64(rand.Uint32()), hash, size) - //} - err = errors.New("unsuport error") - if err != nil && imageURL != "" { - var elem msg.Element - elem.Type = "image" - elem.Data = []msg.Pair{{K: "file", V: imageURL}} - return bot.makeImageOrVideoElem(elem, false, sourceType) + if err != nil || rsp.Url == "" { + return nil, errors.New("unsuport error") } - return rsp, err + return bot.makeImageOrVideoElem(msg.Element{ + Type: "image", + Data: []msg.Pair{{K: "file", V: rsp.Url}}, + }, false, sourceType) } func (bot *CQBot) readVideoCache(b []byte) message.IMessageElement { diff --git a/coolq/event.go b/coolq/event.go index a31f73c55..ec6050f9b 100644 --- a/coolq/event.go +++ b/coolq/event.go @@ -79,11 +79,11 @@ func (ev *event) MarshalJSON() ([]byte, error) { } func (bot *CQBot) privateMessageEvent(_ *client.QQClient, m *message.PrivateMessage) { - bot.checkMedia(m.Elements, int64(m.Sender.Uin)) source := message.Source{ SourceType: message.SourcePrivate, PrimaryID: int64(m.Sender.Uin), } + bot.checkMedia(m.Elements, source) cqm := toStringMessage(m.Elements, source) id := bot.InsertPrivateMessage(m, source) log.Infof("收到好友 %v(%v) 的消息: %v (%v)", m.Sender.Nickname, m.Sender.Uin, cqm, id) @@ -109,7 +109,11 @@ func (bot *CQBot) privateMessageEvent(_ *client.QQClient, m *message.PrivateMess } func (bot *CQBot) groupMessageEvent(c *client.QQClient, m *message.GroupMessage) { - bot.checkMedia(m.Elements, int64(m.GroupUin)) + source := message.Source{ + SourceType: message.SourceGroup, + PrimaryID: int64(m.GroupUin), + } + bot.checkMedia(m.Elements, source) // TODO 群聊文件上传 //for _, elem := range m.Elements { // if file, ok := elem.(*message.GroupFileElement); ok { @@ -128,10 +132,6 @@ func (bot *CQBot) groupMessageEvent(c *client.QQClient, m *message.GroupMessage) // // return // } //} - source := message.Source{ - SourceType: message.SourceGroup, - PrimaryID: int64(m.GroupUin), - } cqm := toStringMessage(m.Elements, source) id := bot.InsertGroupMessage(m, source) log.Infof("收到群 %v(%v) 内 %v(%v) 的消息: %v (%v)", m.GroupName, m.GroupUin, m.Sender.CardName, m.Sender.Uin, cqm, id) @@ -528,11 +528,11 @@ func (bot *CQBot) groupDecrease(groupCode, userUin int64, operator *entity.Group }) } -func (bot *CQBot) checkMedia(e []message.IMessageElement, sourceID int64) { +func (bot *CQBot) checkMedia(e []message.IMessageElement, source message.Source) { for _, elem := range e { switch i := elem.(type) { case *message.ImageElement: - // 闪照已经4了 + // 闪照已经4了(私聊还没) //if i.Flash && sourceID != 0 { // u, err := bot.Client.GetGroupImageDownloadUrl(i.FileId, sourceID, i.Md5) // if err != nil { @@ -543,21 +543,11 @@ func (bot *CQBot) checkMedia(e []message.IMessageElement, sourceID int64) { //} data := binary.NewWriterF(func(w *binary.Builder) { w.Write(i.Md5) - w.WriteU32(i.Size) + w.WritePacketString(i.FileUUID, "u32", true) w.WritePacketString(i.ImageId, "u32", true) - w.WritePacketString(i.Url, "u32", true) }) cache.Image.Insert(i.Md5, data) - //case *message.FriendImageElement: - // data := binary.NewWriterF(func(w *binary.Writer) { - // w.Write(i.Md5) - // w.WriteUInt32(uint32(i.Size)) - // w.WriteString(i.ImageId) - // w.WriteString(i.Url) - // }) - // cache.Image.Insert(i.Md5, data) - case *message.VoiceElement: // todo: don't download original file? i.Name = strings.ReplaceAll(i.Name, "{", "") @@ -572,17 +562,14 @@ func (bot *CQBot) checkMedia(e []message.IMessageElement, sourceID int64) { case *message.ShortVideoElement: data := binary.NewWriterF(func(w *binary.Builder) { w.Write(i.Md5) - w.Write(i.Thumb.Md5) - w.WriteU32(i.Size) - w.WriteU32(i.Thumb.Size) + w.Write(i.Sha1) w.WritePacketString(i.Name, "u32", true) - w.Write(i.Uuid) + w.WritePacketBytes(i.Uuid, "u32", true) }) filename := hex.EncodeToString(i.Md5) + ".video" cache.Video.Insert(i.Md5, data) + i.Url, _ = bot.Client.GetVideoUrl(source.SourceType == message.SourceGroup, i) i.Name = filename - // TODO 获取短视频链接 - //i.Url = bot.Client.GetShortVideoUrl(i.Uuid, i.Md5) } } } diff --git a/go.mod b/go.mod index e58d94c3b..7b10b43dd 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( github.com/FloatTech/sqlite v1.6.3 - github.com/LagrangeDev/LagrangeGo v0.0.0-20240909043624-2a9e85f064ec + github.com/LagrangeDev/LagrangeGo v0.0.0-20241004145230-5aae9c254b47 github.com/Microsoft/go-winio v0.6.2-0.20230724192519-b29bbd58a65a github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7 github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5 diff --git a/go.sum b/go.sum index 4a79f7d24..acf5ef0c5 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/FloatTech/sqlite v1.6.3 h1:MQkqBNlkPuCoKQQgoNLuTL/2Ci3tBTFAnVYBdD0Wy4 github.com/FloatTech/sqlite v1.6.3/go.mod h1:zFbHzRfB+CJ+VidfjuVbrcin3DAz283F7hF1hIeHzpY= github.com/FloatTech/ttl v0.0.0-20230307105452-d6f7b2b647d1 h1:g4pTnDJUW4VbJ9NvoRfUvdjDrHz/6QhfN/LoIIpICbo= github.com/FloatTech/ttl v0.0.0-20230307105452-d6f7b2b647d1/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs= -github.com/LagrangeDev/LagrangeGo v0.0.0-20240909043624-2a9e85f064ec h1:SgebgJXqhMJn41zJsITYCsr6BKfCQ8dthrufI/SPg8w= -github.com/LagrangeDev/LagrangeGo v0.0.0-20240909043624-2a9e85f064ec/go.mod h1:qK/l75YuMYdJWfPcxPhfjybJdXD4kzMFvcbKlvdAoa0= +github.com/LagrangeDev/LagrangeGo v0.0.0-20241004145230-5aae9c254b47 h1:sFEIpdcAjMYl1OAqPz4OSpDdoDQ4Vg06VQ25JoRIxD0= +github.com/LagrangeDev/LagrangeGo v0.0.0-20241004145230-5aae9c254b47/go.mod h1:qK/l75YuMYdJWfPcxPhfjybJdXD4kzMFvcbKlvdAoa0= github.com/Microsoft/go-winio v0.6.2-0.20230724192519-b29bbd58a65a h1:aU1703IHxupjzipvhu16qYKLMR03e+8WuNR+JMsKfGU= github.com/Microsoft/go-winio v0.6.2-0.20230724192519-b29bbd58a65a/go.mod h1:OZqLNXdYJHmx7aqq/T6wAdFEdoGm5nmIfC4kU7M8P8o= github.com/RomiChan/protobuf v0.1.1-0.20230204044148-2ed269a2e54d h1:/Xuj3fIiMY2ls1TwvPKmaqQrtJsPY+c9s+0lOScVHd8=