From 8ca9db5788af63cbb9389e0bb92f29183c3af2cb Mon Sep 17 00:00:00 2001 From: Redmomn <109732988+Redmomn@users.noreply.github.com> Date: Sat, 9 Nov 2024 22:45:33 +0800 Subject: [PATCH] update LagrangeGo -> v0.1.1 --- .golangci.yml | 4 +++- cmd/gocq/login.go | 12 ++++++------ cmd/gocq/main.go | 2 +- coolq/api.go | 20 ++++++++++---------- coolq/bot.go | 22 +++++++++++----------- coolq/converter.go | 4 ++-- coolq/cqcode.go | 18 +++++++++--------- coolq/event.go | 24 ++++++++++++------------ go.mod | 2 +- go.sum | 4 ++-- 10 files changed, 57 insertions(+), 55 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 13406bc1b..f9a529efa 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,6 +1,8 @@ linters-settings: errcheck: - exclude-functions: fmt:.*,io/ioutil:^Read.* + exclude-functions: + - fmt:.* + - io/ioutil:^Read.* ignoretests: true goimports: diff --git a/cmd/gocq/login.go b/cmd/gocq/login.go index 9c70bb5ad..260b8efcb 100644 --- a/cmd/gocq/login.go +++ b/cmd/gocq/login.go @@ -12,7 +12,7 @@ import ( "github.com/LagrangeDev/LagrangeGo/utils" - "github.com/LagrangeDev/LagrangeGo/client/packets/wtlogin/qrcodeState" + "github.com/LagrangeDev/LagrangeGo/client/packets/wtlogin/qrcodestate" "github.com/LagrangeDev/LagrangeGo/client/auth" @@ -159,19 +159,19 @@ func qrcodeLogin() error { } prevState = s switch s { - case qrcodeState.Canceled: + case qrcodestate.Canceled: log.Fatalf("扫码被用户取消.") - case qrcodeState.Expired: + case qrcodestate.Expired: log.Fatalf("二维码过期") - case qrcodeState.WaitingForConfirm: + case qrcodestate.WaitingForConfirm: log.Infof("扫码成功, 请在手机端确认登录.") - case qrcodeState.Confirmed: + case qrcodestate.Confirmed: err := cli.QRCodeLogin(1) if err != nil { return err } return cli.Register() - case qrcodeState.WaitingForScan: + case qrcodestate.WaitingForScan: // ignore } } diff --git a/cmd/gocq/main.go b/cmd/gocq/main.go index 71af93c34..0cb0afff3 100644 --- a/cmd/gocq/main.go +++ b/cmd/gocq/main.go @@ -183,7 +183,7 @@ func LoginInteract() { } var times uint = 1 // 重试次数 var reLoginLock sync.Mutex - cli.DisconnectedEvent.Subscribe(func(q *client.QQClient, e *client.ClientDisconnectedEvent) { + cli.DisconnectedEvent.Subscribe(func(q *client.QQClient, e *client.DisconnectedEvent) { reLoginLock.Lock() defer reLoginLock.Unlock() times = 1 diff --git a/coolq/api.go b/coolq/api.go index 3babba7b7..a1787aef7 100644 --- a/coolq/api.go +++ b/coolq/api.go @@ -260,7 +260,7 @@ func (bot *CQBot) CQGetGroupFilesByFolderID(groupID int64, folderID string) glob // @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, err := bot.Client.GetGroupFileUrl(uint32(groupID), fileID) + url, err := bot.Client.GetGroupFileURL(uint32(groupID), fileID) if err != nil { return Failed(100, "FILE_SYSTEM_API_ERROR") } @@ -455,7 +455,7 @@ func (bot *CQBot) uploadForwardElement(m gjson.Result, target int64, sourceType msgTime = ts.Unix() } return &message.ForwardNode{ - SenderId: uint32(m.GetAttribute().SenderUin), + SenderID: uint32(m.GetAttribute().SenderUin), SenderName: m.GetAttribute().SenderName, Time: uint32(msgTime), Message: resolveElement(bot.ConvertContentMessage(m.GetContent(), mSource, false)), @@ -482,7 +482,7 @@ func (bot *CQBot) uploadForwardElement(m gjson.Result, target int64, sourceType }) if nested { // 处理嵌套 return &message.ForwardNode{ - SenderId: uint32(uin), + SenderID: uint32(uin), SenderName: name, Time: uint32(msgTime), Message: []message.IMessageElement{convertMessage(c)}, @@ -492,7 +492,7 @@ func (bot *CQBot) uploadForwardElement(m gjson.Result, target int64, sourceType content := bot.ConvertObjectMessage(onebot.V11, c, sourceType) if uin != 0 && name != "" && len(content) > 0 { return &message.ForwardNode{ - SenderId: uint32(uin), + SenderID: uint32(uin), SenderName: name, Time: uint32(msgTime), Message: resolveElement(content), @@ -544,7 +544,7 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupID int64, m gjson.Result) globa } ret, err := bot.Client.SendGroupMessage(uint32(groupID), []message.IMessageElement{fe}) if err != nil || ret == nil { - if errors.Is(err, sign.VersionMismatchError) { + if errors.Is(err, sign.ErrVersionMismatch) { log.Warnf("群 %v 发送消息失败: 签名与当前协议版本不对应.", groupID) return Failed(100, "SIGN_ERRPR", "签名与当前协议版本不对应") } @@ -813,9 +813,9 @@ func (bot *CQBot) CQProcessFriendRequest(flag string, approve bool) global.MSG { return Failed(100, "FLAG_NOT_FOUND", "FLAG不存在") } if approve { - _ = bot.Client.SetFriendRequest(true, req.SourceUid) + _ = bot.Client.SetFriendRequest(true, req.SourceUID) } else { - _ = bot.Client.SetFriendRequest(false, req.SourceUid) + _ = bot.Client.SetFriendRequest(false, req.SourceUID) } return OK(nil) } @@ -1237,12 +1237,12 @@ func (bot *CQBot) CQGetForwardMessage(resID string) global.MSG { } r[i] = global.MSG{ "sender": global.MSG{ - "user_id": n.SenderId, + "user_id": n.SenderID, "nickname": n.SenderName, }, "time": n.Time, "content": content, - "group_id": n.GroupId, + "group_id": n.GroupID, } } return r @@ -1521,7 +1521,7 @@ func (bot *CQBot) CQGetEssenceMessageList(groupID int64) global.MSG { if operator := bot.Client.GetCachedMemberInfo(m.OperatorUin, uint32(groupID)); operator != nil { msg["operator_nick"] = operator.MemberName } - msg["message_id"] = db.ToGlobalID(groupID, int32(m.Message.Id)) + msg["message_id"] = db.ToGlobalID(groupID, int32(m.Message.ID)) list = append(list, msg) } return OK(list) diff --git a/coolq/bot.go b/coolq/bot.go index 2300cce5c..5877bbaea 100644 --- a/coolq/bot.go +++ b/coolq/bot.go @@ -293,7 +293,7 @@ func (bot *CQBot) SendGroupMessage(groupID int64, m *message.SendingMessage) (in } else { member := bot.Client.GetCachedMemberInfo(i.TargetUin, uint32(groupID)) if member != nil { - i.TargetUid = member.Uid + i.TargetUID = member.UID if member.MemberCard != "" { i.Display = "@" + member.MemberCard } else { @@ -312,7 +312,7 @@ func (bot *CQBot) SendGroupMessage(groupID int64, m *message.SendingMessage) (in 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) { + if errors.Is(err, sign.ErrVersionMismatch) { log.Warnf("群 %v 发送消息失败: 签名与当前协议版本不对应.", groupID) return -1, err } @@ -434,12 +434,12 @@ func (bot *CQBot) InsertGroupMessage(m *message.GroupMessage, source message.Sou return ok }) msg := &db.StoredGroupMessage{ - ID: encodeMessageID(int64(m.GroupUin), int32(m.Id)), - GlobalID: db.ToGlobalID(int64(m.GroupUin), int32(m.Id)), + ID: encodeMessageID(int64(m.GroupUin), int32(m.ID)), + GlobalID: db.ToGlobalID(int64(m.GroupUin), int32(m.ID)), SubType: "normal", Attribute: &db.StoredMessageAttribute{ - MessageSeq: int32(m.Id), - InternalID: int32(m.InternalId), + MessageSeq: int32(m.ID), + InternalID: int32(m.InternalID), SenderUin: int64(m.Sender.Uin), SenderName: m.Sender.CardName, Timestamp: int64(m.Time), @@ -447,7 +447,7 @@ func (bot *CQBot) InsertGroupMessage(m *message.GroupMessage, source message.Sou GroupCode: int64(m.GroupUin), AnonymousID: func() string { if m.Sender.IsAnonymous() { - return m.Sender.AnonymousInfo.AnonymousId + return m.Sender.AnonymousInfo.AnonymousID } return "" }(), @@ -477,13 +477,13 @@ func (bot *CQBot) InsertPrivateMessage(m *message.PrivateMessage, source message return ok }) msg := &db.StoredPrivateMessage{ - ID: encodeMessageID(int64(m.Sender.Uin), int32(m.Id)), - GlobalID: db.ToGlobalID(int64(m.Sender.Uin), int32(m.Id)), + ID: encodeMessageID(int64(m.Sender.Uin), int32(m.ID)), + GlobalID: db.ToGlobalID(int64(m.Sender.Uin), int32(m.ID)), SubType: "normal", Attribute: &db.StoredMessageAttribute{ - MessageSeq: int32(m.Id), + MessageSeq: int32(m.ID), ClientSeq: int32(m.ClientSeq), - InternalID: int32(m.InternalId), + InternalID: int32(m.InternalID), SenderUin: int64(m.Sender.Uin), SenderName: m.Sender.Nickname, Timestamp: int64(m.Time), diff --git a/coolq/converter.go b/coolq/converter.go index da293ac2d..426cfec0b 100644 --- a/coolq/converter.go +++ b/coolq/converter.go @@ -60,7 +60,7 @@ func (bot *CQBot) formatGroupMessage(m *message.GroupMessage) *event { "font": 0, "group_id": m.GroupUin, "message": ToFormattedMessage(m.Elements, source), - "message_seq": m.Id, + "message_seq": m.ID, "raw_message": cqm, "sender": global.MSG{ "age": 0, @@ -73,7 +73,7 @@ func (bot *CQBot) formatGroupMessage(m *message.GroupMessage) *event { } if m.Sender.IsAnonymous() { gm["anonymous"] = global.MSG{ - "flag": m.Sender.AnonymousInfo.AnonymousId + "|" + m.Sender.AnonymousInfo.AnonymousNick, + "flag": m.Sender.AnonymousInfo.AnonymousID + "|" + m.Sender.AnonymousInfo.AnonymousNick, "id": m.Sender.Uin, "name": m.Sender.AnonymousInfo.AnonymousNick, } diff --git a/coolq/cqcode.go b/coolq/cqcode.go index d4c352540..bca5a2234 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -159,7 +159,7 @@ func toElements(e []message.IMessageElement, source message.Source) (r []msg.Ele Type: "record", Data: pairs{ {K: "file", V: o.Name}, - {K: "url", V: o.Url}, + {K: "url", V: o.URL}, }, } case *message.ShortVideoElement: @@ -167,14 +167,14 @@ func toElements(e []message.IMessageElement, source message.Source) (r []msg.Ele Type: "video", Data: pairs{ {K: "file", V: o.Name}, - {K: "url", V: o.Url}, + {K: "url", V: o.URL}, }, } case *message.ImageElement: data := pairs{ {K: "file", V: hex.EncodeToString(o.Md5) + ".image"}, {K: "subType", V: strconv.FormatInt(int64(o.SubType), 10)}, - {K: "url", V: o.Url}, + {K: "url", V: o.URL}, } //switch { //case o.Flash: @@ -337,15 +337,15 @@ func ToMessageContent(e []message.IMessageElement, source message.Source) (r []g case *message.VoiceElement: m = global.MSG{ "type": "record", - "data": global.MSG{"file": o.Name, "url": o.Url}, + "data": global.MSG{"file": o.Name, "url": o.URL}, } case *message.ShortVideoElement: m = global.MSG{ "type": "video", - "data": global.MSG{"file": o.Name, "url": o.Url}, + "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.SubType)} + data := global.MSG{"file": hex.EncodeToString(o.Md5) + ".image", "url": o.URL, "subType": uint32(o.SubType)} switch { case o.Flash: data["type"] = "flash" @@ -1013,12 +1013,12 @@ func (bot *CQBot) readImageCache(b []byte, sourceType message.SourceType) (messa default: rsp, err = bot.Client.QueryFriendImage(hash, fileUuid) } - if err != nil || rsp.Url == "" { + if err != nil || rsp.URL == "" { return nil, errors.New("unsuport error") } return bot.makeImageOrVideoElem(msg.Element{ Type: "image", - Data: []msg.Pair{{K: "file", V: rsp.Url}}, + Data: []msg.Pair{{K: "file", V: rsp.URL}}, }, false, sourceType) } @@ -1032,7 +1032,7 @@ func (bot *CQBot) readVideoCache(b []byte) message.IMessageElement { Size: r.ReadU32(), }, Name: r.ReadStringWithLength("u32", true), - Uuid: r.ReadBytes(r.Len()), + UUID: r.ReadBytes(r.Len()), } } diff --git a/coolq/event.go b/coolq/event.go index 0f435fab3..207c8d941 100644 --- a/coolq/event.go +++ b/coolq/event.go @@ -183,9 +183,9 @@ func (bot *CQBot) tempMessageEvent(_ *client.QQClient, e *client.TempMessageEven func (bot *CQBot) groupMutedEvent(c *client.QQClient, e *event2.GroupMute) { g := c.GetCachedGroupInfo(e.GroupUin) - operator := c.GetCachedMemberInfo(c.GetUin(e.OperatorUid, e.GroupUin), e.GroupUin) - target := c.GetCachedMemberInfo(c.GetUin(e.TargetUid, e.GroupUin), e.GroupUin) - if e.TargetUid == "" { + operator := c.GetCachedMemberInfo(c.GetUin(e.OperatorUID, e.GroupUin), e.GroupUin) + target := c.GetCachedMemberInfo(c.GetUin(e.TargetUID, e.GroupUin), e.GroupUin) + if e.TargetUID == "" { if e.Duration != 0 { log.Infof("群 %v 被 %v 开启全员禁言.", formatGroupName(g), formatMemberName(operator)) @@ -223,8 +223,8 @@ func (bot *CQBot) groupMutedEvent(c *client.QQClient, e *event2.GroupMute) { func (bot *CQBot) groupRecallEvent(c *client.QQClient, e *event2.GroupRecall) { g := c.GetCachedGroupInfo(e.GroupUin) gid := db.ToGlobalID(int64(e.GroupUin), int32(e.Sequence)) - operator := c.GetCachedMemberInfo(c.GetUin(e.OperatorUid, e.GroupUin), e.GroupUin) - Author := c.GetCachedMemberInfo(c.GetUin(e.AuthorUid, e.GroupUin), e.GroupUin) + operator := c.GetCachedMemberInfo(c.GetUin(e.OperatorUID, e.GroupUin), e.GroupUin) + Author := c.GetCachedMemberInfo(c.GetUin(e.AuthorUID, e.GroupUin), e.GroupUin) log.Infof("群 %v 内 %v 撤回了 %v 的消息: %v.", formatGroupName(g), formatMemberName(operator), formatMemberName(Author), gid) @@ -316,7 +316,7 @@ func (bot *CQBot) memberTitleUpdatedEvent(c *client.QQClient, e *event2.MemberSp } func (bot *CQBot) friendRecallEvent(c *client.QQClient, e *event2.FriendRecall) { - f := c.GetCachedFriendInfo(c.GetUin(e.FromUid)) + f := c.GetCachedFriendInfo(c.GetUin(e.FromUID)) gid := db.ToGlobalID(int64(f.Uin), int32(e.Sequence)) //if f != nil { log.Infof("好友 %v(%v) 撤回了消息: %v", f.Nickname, f.Uin, gid) @@ -391,8 +391,8 @@ func (bot *CQBot) memberJoinEvent(c *client.QQClient, e *event2.GroupMemberIncre } func (bot *CQBot) memberLeaveEvent(c *client.QQClient, e *event2.GroupMemberDecrease) { - member := c.GetCachedMemberInfo(c.GetUin(e.MemberUid), e.GroupUin) - op := c.GetCachedMemberInfo(c.GetUin(e.OperatorUid), e.GroupUin) + member := c.GetCachedMemberInfo(c.GetUin(e.MemberUID), e.GroupUin) + op := c.GetCachedMemberInfo(c.GetUin(e.OperatorUID), e.GroupUin) group := c.GetCachedGroupInfo(e.GroupUin) if e.IsKicked() { log.Infof("成员 %v 被 %v T出了群 %v.", formatMemberName(member), formatMemberName(op), formatGroupName(group)) @@ -543,7 +543,7 @@ func (bot *CQBot) checkMedia(e []message.IMessageElement, source message.Source) data := binary.NewWriterF(func(w *binary.Builder) { w.Write(i.Md5) w.WritePacketString(i.FileUUID, "u32", true) - w.WritePacketString(i.ImageId, "u32", true) + w.WritePacketString(i.ImageID, "u32", true) }) cache.Image.Insert(i.Md5, data) @@ -552,7 +552,7 @@ func (bot *CQBot) checkMedia(e []message.IMessageElement, source message.Source) i.Name = strings.ReplaceAll(i.Name, "{", "") i.Name = strings.ReplaceAll(i.Name, "}", "") if !global.FileExists(path.Join(global.VoicePath, i.Name)) { - err := download.Request{URL: i.Url}.WriteToFile(path.Join(global.VoicePath, i.Name)) + err := download.Request{URL: i.URL}.WriteToFile(path.Join(global.VoicePath, i.Name)) if err != nil { log.Warnf("语音文件 %v 下载失败: %v", i.Name, err) continue @@ -563,11 +563,11 @@ func (bot *CQBot) checkMedia(e []message.IMessageElement, source message.Source) w.Write(i.Md5) w.Write(i.Sha1) w.WritePacketString(i.Name, "u32", true) - w.WritePacketBytes(i.Uuid, "u32", true) + 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.URL, _ = bot.Client.GetVideoURL(source.SourceType == message.SourceGroup, i) i.Name = filename } } diff --git a/go.mod b/go.mod index 6e836d5f8..f1384284d 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.1.1-0.20241109045849-233e0b659a25 + github.com/LagrangeDev/LagrangeGo v0.1.1 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 2c859ead2..8d800096c 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.1.1-0.20241109045849-233e0b659a25 h1:IGgr52tnRzfMuopLP77VDBRXOTY66VfMkzL12cFE3vk= -github.com/LagrangeDev/LagrangeGo v0.1.1-0.20241109045849-233e0b659a25/go.mod h1:dDLKGYgka2pEfPP49fUlbdnazxAvAlSTDRjd8kAX/Xg= +github.com/LagrangeDev/LagrangeGo v0.1.1 h1:YqnFd1DaWZ9Y4CILS0PSDu3R2yt9myOp7C/xoDwrnGU= +github.com/LagrangeDev/LagrangeGo v0.1.1/go.mod h1:dDLKGYgka2pEfPP49fUlbdnazxAvAlSTDRjd8kAX/Xg= 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=