Skip to content

Commit

Permalink
feat: 补充系统消息
Browse files Browse the repository at this point in the history
  • Loading branch information
Redmomn committed Nov 28, 2024
1 parent a0f44ef commit 24a36a3
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 32 deletions.
56 changes: 27 additions & 29 deletions client/entity/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,44 +67,42 @@ type (
}

UserJoinGroupRequest struct {
GroupUin uint32
InvitorUin uint32
InvitorUID string
TargetUin uint32
TargetUID string
OperatorUin uint32
OperatorUID string
Sequence uint64
State EventState
EventType EventType
Comment string
IsFiltered bool
GroupName string `json:"group_name"`
GroupUin uint32 `json:"group_id"`
InvitorUin uint32 `json:"invitor_uin"`
InvitorUID string `json:"-"`
TargetNick string `json:"requester_nick"`
TargetUin uint32 `json:"requester_uin"`
TargetUID string `json:"-"`
OperatorUin uint32 `json:"actor"`
OperatorUID string `json:"-"`
Sequence uint64 `json:"request_id"`
Checked bool `json:"checked"`
State EventState `json:"-"`
EventType EventType `json:"-"`
Comment string `json:"message"`
IsFiltered bool `json:"is_filtered"`
}

GroupInvitedRequest struct {
GroupUin uint32
InvitorUin uint32
InvitorUID string
Sequence uint64
State EventState
EventType EventType
IsFiltered bool
GroupUin uint32 `json:"group_id"`
GroupName string `json:"group_name"`
InvitorNick string `json:"invitor_nick"`
InvitorUin uint32 `json:"invitor_uin"`
InvitorUID string `json:"-"`
Sequence uint64 `json:"request_id"`
Checked bool `json:"checked"`
State EventState `json:"-"`
EventType EventType `json:"-"`
IsFiltered bool `json:"is_filtered"`
}

GroupSystemMessages struct {
InvitedRequests []*GroupInvitedRequest
JoinRequests []*UserJoinGroupRequest
InvitedRequests []*GroupInvitedRequest `json:"invited_requests"`
JoinRequests []*UserJoinGroupRequest `json:"join_requests"`
}
)

func (r *UserJoinGroupRequest) Checked() bool {
return r.State != Unprocessed
}

func (r *GroupInvitedRequest) Checked() bool {
return r.State != Unprocessed
}

func (g *Group) Avatar() string {
return fmt.Sprintf("https://p.qlogo.cn/gh/%d/%d/0/", g.GroupUin, g.GroupUin)
}
4 changes: 2 additions & 2 deletions client/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func decodeOlPushServicePacket(c *QQClient, pkt *network.Packet) (any, error) {
filteredRequests, freqErr := c.GetGroupSystemMessages(true, 20, ev.GroupUin)
if reqErr == nil && freqErr == nil {
for _, request := range append(commonRequests.JoinRequests, filteredRequests.JoinRequests...) {
if request.TargetUID == ev.TargetUID && !request.Checked() {
if request.TargetUID == ev.TargetUID && !request.Checked {
ev.RequestSeq = request.Sequence
ev.Answer = request.Comment
}
Expand Down Expand Up @@ -180,7 +180,7 @@ func decodeOlPushServicePacket(c *QQClient, pkt *network.Packet) (any, error) {
filteredRequests, freqErr := c.GetGroupSystemMessages(true, 20, ev.GroupUin)
if reqErr == nil && freqErr == nil {
for _, request := range append(commonRequests.InvitedRequests, filteredRequests.InvitedRequests...) {
if !request.Checked() {
if !request.Checked {
ev.RequestSeq = request.Sequence
break
}
Expand Down
22 changes: 21 additions & 1 deletion client/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,27 @@ func (c *QQClient) GetGroupSystemMessages(isFiltered bool, count uint32, groupUi
if err != nil {
return nil, err
}
return oidb2.ParseFetchGroupSystemMessagesReq(isFiltered, resp, groupUin...)
msgs, err := oidb2.ParseFetchGroupSystemMessagesReq(isFiltered, resp, groupUin...)
if err != nil {
return nil, err
}
for _, req := range msgs.InvitedRequests {
if g, err := c.FetchGroupInfo(req.GroupUin, true); err == nil {
req.GroupName = g.GroupName
}
if u, err := c.FetchUserInfoUin(req.InvitorUin); err == nil {
req.InvitorNick = u.Nickname
}
}
for _, req := range msgs.JoinRequests {
if g, err := c.FetchGroupInfo(req.GroupUin, false); err == nil {
req.GroupName = g.GroupName
}
if u, err := c.FetchUserInfoUin(req.TargetUin); err == nil {
req.TargetNick = u.Nickname
}
}
return msgs, nil
}

// SetGroupRequest 处理加群请求
Expand Down
2 changes: 2 additions & 0 deletions client/packets/oidb/fetch_group_system_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func ParseFetchGroupSystemMessagesReq(isFiltered bool, data []byte, groupUin ...
return ""
}),
Sequence: r.Sequence,
Checked: entity.EventState(r.State) != entity.Unprocessed,
State: entity.EventState(r.State),
EventType: entity.EventType(r.EventType),
Comment: r.Comment,
Expand All @@ -55,6 +56,7 @@ func ParseFetchGroupSystemMessagesReq(isFiltered bool, data []byte, groupUin ...
return ""
}),
Sequence: r.Sequence,
Checked: entity.EventState(r.State) != entity.Unprocessed,
State: entity.EventState(r.State),
EventType: entity.EventType(r.EventType),
IsFiltered: isFiltered,
Expand Down

0 comments on commit 24a36a3

Please sign in to comment.