Skip to content

Commit

Permalink
update LagrangeGo -> v0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Redmomn committed Nov 9, 2024
1 parent 1aa0c25 commit 8ca9db5
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 55 deletions.
4 changes: 3 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
linters-settings:
errcheck:
exclude-functions: fmt:.*,io/ioutil:^Read.*
exclude-functions:
- fmt:.*
- io/ioutil:^Read.*
ignoretests: true

goimports:
Expand Down
12 changes: 6 additions & 6 deletions cmd/gocq/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/gocq/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions coolq/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Check failure on line 262 in coolq/api.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'busID' seems to be unused, consider removing or renaming it as _ (revive)

Check failure on line 262 in coolq/api.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'busID' seems to be unused, consider removing or renaming it as _ (revive)
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")
}
Expand Down Expand Up @@ -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)),
Expand All @@ -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)},
Expand All @@ -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),
Expand Down Expand Up @@ -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", "签名与当前协议版本不对应")
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 11 additions & 11 deletions coolq/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down Expand Up @@ -434,20 +434,20 @@ 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),
},
GroupCode: int64(m.GroupUin),
AnonymousID: func() string {
if m.Sender.IsAnonymous() {
return m.Sender.AnonymousInfo.AnonymousId
return m.Sender.AnonymousInfo.AnonymousID
}
return ""
}(),
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions coolq/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
}
Expand Down
18 changes: 9 additions & 9 deletions coolq/cqcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,22 @@ 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:
m = msg.Element{
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:
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

Expand All @@ -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()),
}
}

Expand Down
24 changes: 12 additions & 12 deletions coolq/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)

Check failure on line 544 in coolq/event.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `w.Write` is not checked (errcheck)

Check failure on line 544 in coolq/event.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `w.Write` is not checked (errcheck)
w.WritePacketString(i.FileUUID, "u32", true)
w.WritePacketString(i.ImageId, "u32", true)
w.WritePacketString(i.ImageID, "u32", true)
})
cache.Image.Insert(i.Md5, data)

Expand All @@ -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
Expand All @@ -563,11 +563,11 @@ func (bot *CQBot) checkMedia(e []message.IMessageElement, source message.Source)
w.Write(i.Md5)

Check failure on line 563 in coolq/event.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `w.Write` is not checked (errcheck)

Check failure on line 563 in coolq/event.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `w.Write` is not checked (errcheck)
w.Write(i.Sha1)

Check failure on line 564 in coolq/event.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `w.Write` is not checked (errcheck)

Check failure on line 564 in coolq/event.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `w.Write` is not checked (errcheck)
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
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 8ca9db5

Please sign in to comment.