Skip to content

Commit ab371c1

Browse files
committed
refactor: 同步更改字段
1 parent 494692a commit ab371c1

File tree

6 files changed

+36
-34
lines changed

6 files changed

+36
-34
lines changed

coolq/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ func (bot *CQBot) CQGetEssenceMessageList(groupID int64) global.MSG {
15191519
"operator_id": m.OperatorUin,
15201520
}
15211521
if operator := bot.Client.GetCachedMemberInfo(m.OperatorUin, uint32(groupID)); operator != nil {
1522-
msg["operator_nick"] = operator.MemberName
1522+
msg["operator_nick"] = operator.DisplayName()
15231523
}
15241524
msg["message_id"] = db.ToGlobalID(groupID, int32(m.Message.ID))
15251525
list = append(list, msg)

coolq/bot.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,7 @@ func (bot *CQBot) SendGroupMessage(groupID int64, m *message.SendingMessage) (in
294294
member := bot.Client.GetCachedMemberInfo(i.TargetUin, uint32(groupID))
295295
if member != nil {
296296
i.TargetUID = member.UID
297-
if member.MemberCard != "" {
298-
i.Display = "@" + member.MemberCard
299-
} else {
300-
i.Display = "@" + member.MemberName
301-
}
297+
i.Display = "@" + member.DisplayName()
302298
}
303299
}
304300
}

coolq/converter.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ import (
1414
)
1515

1616
func convertGroupMemberInfo(groupID int64, m *entity.GroupMember) global.MSG {
17-
// TODO nt 协议依然是获取不到
1817
sex := "unknown"
18+
//if m.Gender == 1 { // unknown = 0xff
19+
// sex = "female"
20+
//} else if m.Gender == 0 {
21+
// sex = "male"
22+
//}
1923
role := "member"
2024
switch m.Permission { // nolint:exhaustive
2125
case entity.Owner:
@@ -28,7 +32,7 @@ func convertGroupMemberInfo(groupID int64, m *entity.GroupMember) global.MSG {
2832
return global.MSG{
2933
"group_id": groupID,
3034
"user_id": m.Uin,
31-
"nickname": m.MemberName,
35+
"nickname": m.Nickname,
3236
"card": m.MemberCard,
3337
"sex": sex,
3438
"age": 0,

coolq/event.go

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ func (bot *CQBot) tempMessageEvent(_ *client.QQClient, e *message.TempMessage) {
179179
func (bot *CQBot) groupMutedEvent(c *client.QQClient, e *event2.GroupMute) {
180180
g := c.GetCachedGroupInfo(e.GroupUin)
181181
operator := c.GetCachedMemberInfo(c.GetUin(e.OperatorUID, e.GroupUin), e.GroupUin)
182-
target := c.GetCachedMemberInfo(c.GetUin(e.TargetUID, e.GroupUin), e.GroupUin)
183-
if e.TargetUID == "" {
182+
target := c.GetCachedMemberInfo(c.GetUin(e.UserUID, e.GroupUin), e.GroupUin)
183+
if e.UserUID == "" {
184184
if e.Duration != 0 {
185185
log.Infof("群 %v 被 %v 开启全员禁言.",
186186
formatGroupName(g), formatMemberName(operator))
@@ -219,7 +219,7 @@ func (bot *CQBot) groupRecallEvent(c *client.QQClient, e *event2.GroupRecall) {
219219
g := c.GetCachedGroupInfo(e.GroupUin)
220220
gid := db.ToGlobalID(int64(e.GroupUin), int32(e.Sequence))
221221
operator := c.GetCachedMemberInfo(c.GetUin(e.OperatorUID, e.GroupUin), e.GroupUin)
222-
Author := c.GetCachedMemberInfo(c.GetUin(e.AuthorUID, e.GroupUin), e.GroupUin)
222+
Author := c.GetCachedMemberInfo(c.GetUin(e.UserUID, e.GroupUin), e.GroupUin)
223223
log.Infof("群 %v 内 %v 撤回了 %v 的消息: %v.",
224224
formatGroupName(g), formatMemberName(operator), formatMemberName(Author), gid)
225225

@@ -239,13 +239,13 @@ func (bot *CQBot) groupNotifyEvent(c *client.QQClient, e event2.INotifyEvent) {
239239
//nolint:gocritic
240240
switch notify := e.(type) {
241241
case *event2.GroupPokeEvent:
242-
sender := c.GetCachedMemberInfo(notify.Sender, e.From())
242+
sender := c.GetCachedMemberInfo(notify.UserUin, e.From())
243243
receiver := c.GetCachedMemberInfo(notify.Receiver, e.From())
244244
log.Infof("群 %v 内 %v 戳了戳 %v", formatGroupName(group), formatMemberName(sender), formatMemberName(receiver))
245245
bot.dispatchEvent("notice/notify/poke", global.MSG{
246246
"group_id": group.GroupUin,
247-
"user_id": notify.Sender,
248-
"sender_id": notify.Sender,
247+
"user_id": notify.UserUin,
248+
"sender_id": notify.UserUin,
249249
"target_id": notify.Receiver,
250250
})
251251
//case *client.GroupRedBagLuckyKingNotifyEvent:
@@ -301,25 +301,25 @@ func (bot *CQBot) friendNotifyEvent(c *client.QQClient, e event2.INotifyEvent) {
301301

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

313313
func (bot *CQBot) friendRecallEvent(c *client.QQClient, e *event2.FriendRecall) {
314314
f := c.GetCachedFriendInfo(c.GetUin(e.FromUID))
315-
gid := db.ToGlobalID(int64(f.Uin), int32(e.Sequence))
316-
//if f != nil {
317-
log.Infof("好友 %v(%v) 撤回了消息: %v", f.Nickname, f.Uin, gid)
318-
//} else {
319-
// log.Infof("好友 %v 撤回了消息: %v", e.FriendUin, gid)
320-
//}
315+
gid := db.ToGlobalID(int64(e.FromUin), int32(e.Sequence))
316+
if f != nil {
317+
log.Infof("好友 %v(%v) 撤回了消息: %v", f.Nickname, f.Uin, gid)
318+
} else {
319+
log.Infof("好友 %v 撤回了消息: %v", e.FromUin, gid)
320+
}
321321
ev := bot.event("notice/friend_recall", global.MSG{
322-
"user_id": f.Uin,
322+
"user_id": e.FromUin,
323323
"message_id": gid,
324324
})
325325
ev.Time = int64(e.Time)
@@ -365,7 +365,7 @@ func (bot *CQBot) memberPermissionChangedEvent(_ *client.QQClient, e *event2.Gro
365365
}
366366
bot.dispatchEvent("notice/group_admin/"+st, global.MSG{
367367
"group_id": e.GroupUin,
368-
"user_id": e.TargetUin,
368+
"user_id": e.UserUin,
369369
})
370370
}
371371

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

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

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

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

461-
// TODO 精华消息
462461
func (bot *CQBot) groupEssenceMsg(c *client.QQClient, e *event2.GroupDigestEvent) {
463462
g := c.GetCachedGroupInfo(e.GroupUin)
464463
gid := db.ToGlobalID(int64(e.GroupUin), int32(e.MessageID))
@@ -467,15 +466,15 @@ func (bot *CQBot) groupEssenceMsg(c *client.QQClient, e *event2.GroupDigestEvent
467466
"群 %v 内 %v 将 %v 的消息(%v)设为了精华消息.",
468467
formatGroupName(g),
469468
formatMemberName(c.GetCachedMemberInfo(e.OperatorUin, e.GroupUin)),
470-
formatMemberName(c.GetCachedMemberInfo(e.SenderUin, e.GroupUin)),
469+
formatMemberName(c.GetCachedMemberInfo(e.UserUin, e.GroupUin)),
471470
gid,
472471
)
473472
} else {
474473
log.Infof(
475474
"群 %v 内 %v 将 %v 的消息(%v)移出了精华消息.",
476475
formatGroupName(g),
477476
formatMemberName(c.GetCachedMemberInfo(e.OperatorUin, e.GroupUin)),
478-
formatMemberName(c.GetCachedMemberInfo(e.SenderUin, e.GroupUin)),
477+
formatMemberName(c.GetCachedMemberInfo(e.UserUin, e.GroupUin)),
479478
gid,
480479
)
481480
}
@@ -488,7 +487,7 @@ func (bot *CQBot) groupEssenceMsg(c *client.QQClient, e *event2.GroupDigestEvent
488487
}
489488
bot.dispatchEvent("notice/essence/"+subtype, global.MSG{
490489
"group_id": e.GroupUin,
491-
"sender_id": e.SenderUin,
490+
"sender_id": e.UserUin,
492491
"operator_id": e.OperatorUin,
493492
"message_id": gid,
494493
})

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.20
44

55
require (
66
github.com/FloatTech/sqlite v1.6.3
7-
github.com/LagrangeDev/LagrangeGo v0.1.3-0.20241129090211-e0fdf8ca5390
7+
github.com/LagrangeDev/LagrangeGo v0.1.3-0.20241129102648-b22bfd7d71ba
88
github.com/Microsoft/go-winio v0.6.2-0.20230724192519-b29bbd58a65a
99
github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7
1010
github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5

go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ github.com/FloatTech/ttl v0.0.0-20230307105452-d6f7b2b647d1 h1:g4pTnDJUW4VbJ9Nvo
44
github.com/FloatTech/ttl v0.0.0-20230307105452-d6f7b2b647d1/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs=
55
github.com/LagrangeDev/LagrangeGo v0.1.3-0.20241129090211-e0fdf8ca5390 h1:NIDdk9Z5ztBhWcLJc8WvXxRSgdSqZlikrFBU5pII78Q=
66
github.com/LagrangeDev/LagrangeGo v0.1.3-0.20241129090211-e0fdf8ca5390/go.mod h1:m7ydyvA8DKOg5c6iTFDfNtfIK9uhqXVJKRXl4mlGkTA=
7+
github.com/LagrangeDev/LagrangeGo v0.1.3-0.20241129102648-b22bfd7d71ba h1:x3ccoK+TJhIcZjO+Ybsv1YwCbowNq9ZHvjOtlKBuCFU=
8+
github.com/LagrangeDev/LagrangeGo v0.1.3-0.20241129102648-b22bfd7d71ba/go.mod h1:m7ydyvA8DKOg5c6iTFDfNtfIK9uhqXVJKRXl4mlGkTA=
79
github.com/Microsoft/go-winio v0.6.2-0.20230724192519-b29bbd58a65a h1:aU1703IHxupjzipvhu16qYKLMR03e+8WuNR+JMsKfGU=
810
github.com/Microsoft/go-winio v0.6.2-0.20230724192519-b29bbd58a65a/go.mod h1:OZqLNXdYJHmx7aqq/T6wAdFEdoGm5nmIfC4kU7M8P8o=
911
github.com/RomiChan/protobuf v0.1.1-0.20230204044148-2ed269a2e54d h1:/Xuj3fIiMY2ls1TwvPKmaqQrtJsPY+c9s+0lOScVHd8=
@@ -162,6 +164,7 @@ golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJ
162164
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
163165
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
164166
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
167+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
165168
gopkg.ilharper.com/x/isatty v1.1.1 h1:RAg32Pxq/nIK4AVtdm9RBqxsxZZX1uRKRSS21E5SHMk=
166169
gopkg.ilharper.com/x/isatty v1.1.1/go.mod h1:ofpv77Td5qQO6R1dmDd3oNt8TZdRo+l5gYAMxopRyS0=
167170
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=

0 commit comments

Comments
 (0)