Skip to content

Commit

Permalink
refactor: 同步更改字段
Browse files Browse the repository at this point in the history
  • Loading branch information
Redmomn committed Nov 29, 2024
1 parent 494692a commit ab371c1
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 34 deletions.
2 changes: 1 addition & 1 deletion coolq/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,7 @@ func (bot *CQBot) CQGetEssenceMessageList(groupID int64) global.MSG {
"operator_id": m.OperatorUin,
}
if operator := bot.Client.GetCachedMemberInfo(m.OperatorUin, uint32(groupID)); operator != nil {
msg["operator_nick"] = operator.MemberName
msg["operator_nick"] = operator.DisplayName()
}
msg["message_id"] = db.ToGlobalID(groupID, int32(m.Message.ID))
list = append(list, msg)
Expand Down
6 changes: 1 addition & 5 deletions coolq/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,7 @@ func (bot *CQBot) SendGroupMessage(groupID int64, m *message.SendingMessage) (in
member := bot.Client.GetCachedMemberInfo(i.TargetUin, uint32(groupID))
if member != nil {
i.TargetUID = member.UID
if member.MemberCard != "" {
i.Display = "@" + member.MemberCard
} else {
i.Display = "@" + member.MemberName
}
i.Display = "@" + member.DisplayName()
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions coolq/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ import (
)

func convertGroupMemberInfo(groupID int64, m *entity.GroupMember) global.MSG {
// TODO nt 协议依然是获取不到
sex := "unknown"
//if m.Gender == 1 { // unknown = 0xff
// sex = "female"
//} else if m.Gender == 0 {
// sex = "male"
//}
role := "member"
switch m.Permission { // nolint:exhaustive
case entity.Owner:
Expand All @@ -28,7 +32,7 @@ func convertGroupMemberInfo(groupID int64, m *entity.GroupMember) global.MSG {
return global.MSG{
"group_id": groupID,
"user_id": m.Uin,
"nickname": m.MemberName,
"nickname": m.Nickname,
"card": m.MemberCard,
"sex": sex,
"age": 0,
Expand Down
49 changes: 24 additions & 25 deletions coolq/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ func (bot *CQBot) tempMessageEvent(_ *client.QQClient, e *message.TempMessage) {
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 == "" {
target := c.GetCachedMemberInfo(c.GetUin(e.UserUID, e.GroupUin), e.GroupUin)
if e.UserUID == "" {
if e.Duration != 0 {
log.Infof("群 %v 被 %v 开启全员禁言.",
formatGroupName(g), formatMemberName(operator))
Expand Down Expand Up @@ -219,7 +219,7 @@ 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)
Author := c.GetCachedMemberInfo(c.GetUin(e.UserUID, e.GroupUin), e.GroupUin)
log.Infof("群 %v 内 %v 撤回了 %v 的消息: %v.",
formatGroupName(g), formatMemberName(operator), formatMemberName(Author), gid)

Expand All @@ -239,13 +239,13 @@ func (bot *CQBot) groupNotifyEvent(c *client.QQClient, e event2.INotifyEvent) {
//nolint:gocritic
switch notify := e.(type) {
case *event2.GroupPokeEvent:
sender := c.GetCachedMemberInfo(notify.Sender, e.From())
sender := c.GetCachedMemberInfo(notify.UserUin, e.From())
receiver := c.GetCachedMemberInfo(notify.Receiver, e.From())
log.Infof("群 %v 内 %v 戳了戳 %v", formatGroupName(group), formatMemberName(sender), formatMemberName(receiver))
bot.dispatchEvent("notice/notify/poke", global.MSG{
"group_id": group.GroupUin,
"user_id": notify.Sender,
"sender_id": notify.Sender,
"user_id": notify.UserUin,
"sender_id": notify.UserUin,
"target_id": notify.Receiver,
})
//case *client.GroupRedBagLuckyKingNotifyEvent:
Expand Down Expand Up @@ -301,25 +301,25 @@ func (bot *CQBot) friendNotifyEvent(c *client.QQClient, e event2.INotifyEvent) {

func (bot *CQBot) memberTitleUpdatedEvent(c *client.QQClient, e *event2.MemberSpecialTitleUpdated) {
group := c.GetCachedGroupInfo(e.GroupUin)
mem := c.GetCachedMemberInfo(e.Uin, e.GroupUin)
mem := c.GetCachedMemberInfo(e.UserUin, e.GroupUin)
log.Infof("群 %v(%v) 内成员 %v(%v) 获得了新的头衔: %v", group.GroupName, group.GroupUin, mem.MemberCard, mem.Uin, e.NewTitle)
bot.dispatchEvent("notice/notify/title", global.MSG{
"group_id": group.GroupUin,
"user_id": e.Uin,
"user_id": e.UserUin,
"title": e.NewTitle,
})
}

func (bot *CQBot) friendRecallEvent(c *client.QQClient, e *event2.FriendRecall) {
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)
//} else {
// log.Infof("好友 %v 撤回了消息: %v", e.FriendUin, gid)
//}
gid := db.ToGlobalID(int64(e.FromUin), int32(e.Sequence))
if f != nil {
log.Infof("好友 %v(%v) 撤回了消息: %v", f.Nickname, f.Uin, gid)
} else {
log.Infof("好友 %v 撤回了消息: %v", e.FromUin, gid)
}
ev := bot.event("notice/friend_recall", global.MSG{
"user_id": f.Uin,
"user_id": e.FromUin,
"message_id": gid,
})
ev.Time = int64(e.Time)
Expand Down Expand Up @@ -365,7 +365,7 @@ func (bot *CQBot) memberPermissionChangedEvent(_ *client.QQClient, e *event2.Gro
}
bot.dispatchEvent("notice/group_admin/"+st, global.MSG{
"group_id": e.GroupUin,
"user_id": e.TargetUin,
"user_id": e.UserUin,
})
}

Expand All @@ -381,12 +381,12 @@ func (bot *CQBot) memberPermissionChangedEvent(_ *client.QQClient, e *event2.Gro
//}

func (bot *CQBot) memberJoinEvent(c *client.QQClient, e *event2.GroupMemberIncrease) {
log.Infof("新成员 %v 进入了群 %v.", formatMemberName(c.GetCachedMemberInfo(e.MemberUin, e.GroupUin)), formatGroupName(c.GetCachedGroupInfo(e.GroupUin)))
bot.dispatch(bot.groupIncrease(int64(e.GroupUin), 0, int64(e.MemberUin)))
log.Infof("新成员 %v 进入了群 %v.", formatMemberName(c.GetCachedMemberInfo(e.UserUin, e.GroupUin)), formatGroupName(c.GetCachedGroupInfo(e.GroupUin)))
bot.dispatch(bot.groupIncrease(int64(e.GroupUin), 0, int64(e.UserUin)))
}

func (bot *CQBot) memberLeaveEvent(c *client.QQClient, e *event2.GroupMemberDecrease) {
member := c.GetCachedMemberInfo(c.GetUin(e.MemberUID), e.GroupUin)
member := c.GetCachedMemberInfo(c.GetUin(e.UserUID), e.GroupUin)
op := c.GetCachedMemberInfo(c.GetUin(e.OperatorUID), e.GroupUin)
group := c.GetCachedGroupInfo(e.GroupUin)
if e.IsKicked() {
Expand Down Expand Up @@ -431,11 +431,11 @@ func (bot *CQBot) groupInvitedEvent(_ *client.QQClient, e *event2.GroupInvite) {

func (bot *CQBot) groupJoinReqEvent(c *client.QQClient, e *event2.GroupMemberJoinRequest) {
group := c.GetCachedGroupInfo(e.GroupUin)
log.Infof("群 %v(%v) 收到来自用户 %v(%v) 的加群请求.", group.GroupName, e.GroupUin, e.TargetNick, e.TargetUin)
log.Infof("群 %v(%v) 收到来自用户 %v(%v) 的加群请求.", group.GroupName, e.GroupUin, e.TargetNick, e.UserUin)
flag := strconv.FormatInt(int64(e.RequestSeq), 10)
bot.dispatchEvent("request/group/add", global.MSG{
"group_id": e.GroupUin,
"user_id": e.TargetUin,
"user_id": e.UserUin,
"invitor_id": e.InvitorUin,
"comment": e.Answer,
"flag": flag,
Expand All @@ -458,7 +458,6 @@ func (bot *CQBot) groupJoinReqEvent(c *client.QQClient, e *event2.GroupMemberJoi
// })
//}

// TODO 精华消息
func (bot *CQBot) groupEssenceMsg(c *client.QQClient, e *event2.GroupDigestEvent) {
g := c.GetCachedGroupInfo(e.GroupUin)
gid := db.ToGlobalID(int64(e.GroupUin), int32(e.MessageID))
Expand All @@ -467,15 +466,15 @@ func (bot *CQBot) groupEssenceMsg(c *client.QQClient, e *event2.GroupDigestEvent
"群 %v 内 %v 将 %v 的消息(%v)设为了精华消息.",
formatGroupName(g),
formatMemberName(c.GetCachedMemberInfo(e.OperatorUin, e.GroupUin)),
formatMemberName(c.GetCachedMemberInfo(e.SenderUin, e.GroupUin)),
formatMemberName(c.GetCachedMemberInfo(e.UserUin, e.GroupUin)),
gid,
)
} else {
log.Infof(
"群 %v 内 %v 将 %v 的消息(%v)移出了精华消息.",
formatGroupName(g),
formatMemberName(c.GetCachedMemberInfo(e.OperatorUin, e.GroupUin)),
formatMemberName(c.GetCachedMemberInfo(e.SenderUin, e.GroupUin)),
formatMemberName(c.GetCachedMemberInfo(e.UserUin, e.GroupUin)),
gid,
)
}
Expand All @@ -488,7 +487,7 @@ func (bot *CQBot) groupEssenceMsg(c *client.QQClient, e *event2.GroupDigestEvent
}
bot.dispatchEvent("notice/essence/"+subtype, global.MSG{
"group_id": e.GroupUin,
"sender_id": e.SenderUin,
"sender_id": e.UserUin,
"operator_id": e.OperatorUin,
"message_id": gid,
})
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.3-0.20241129090211-e0fdf8ca5390
github.com/LagrangeDev/LagrangeGo v0.1.3-0.20241129102648-b22bfd7d71ba
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
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/FloatTech/ttl v0.0.0-20230307105452-d6f7b2b647d1 h1:g4pTnDJUW4VbJ9Nvo
github.com/FloatTech/ttl v0.0.0-20230307105452-d6f7b2b647d1/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs=
github.com/LagrangeDev/LagrangeGo v0.1.3-0.20241129090211-e0fdf8ca5390 h1:NIDdk9Z5ztBhWcLJc8WvXxRSgdSqZlikrFBU5pII78Q=
github.com/LagrangeDev/LagrangeGo v0.1.3-0.20241129090211-e0fdf8ca5390/go.mod h1:m7ydyvA8DKOg5c6iTFDfNtfIK9uhqXVJKRXl4mlGkTA=
github.com/LagrangeDev/LagrangeGo v0.1.3-0.20241129102648-b22bfd7d71ba h1:x3ccoK+TJhIcZjO+Ybsv1YwCbowNq9ZHvjOtlKBuCFU=
github.com/LagrangeDev/LagrangeGo v0.1.3-0.20241129102648-b22bfd7d71ba/go.mod h1:m7ydyvA8DKOg5c6iTFDfNtfIK9uhqXVJKRXl4mlGkTA=
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 Expand Up @@ -162,6 +164,7 @@ golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJ
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.ilharper.com/x/isatty v1.1.1 h1:RAg32Pxq/nIK4AVtdm9RBqxsxZZX1uRKRSS21E5SHMk=
gopkg.ilharper.com/x/isatty v1.1.1/go.mod h1:ofpv77Td5qQO6R1dmDd3oNt8TZdRo+l5gYAMxopRyS0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
Expand Down

0 comments on commit ab371c1

Please sign in to comment.