Skip to content

Commit

Permalink
feat: 获取单个群员信息
Browse files Browse the repository at this point in the history
  • Loading branch information
Redmomn committed Jul 17, 2024
1 parent 78def46 commit 1a50f37
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 4 deletions.
4 changes: 2 additions & 2 deletions client/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,15 @@ func (c *QQClient) GetFriendsData() (map[uint32]*entity.Friend, error) {
// GetGroupMembersData 获取指定群所有成员信息
func (c *QQClient) GetGroupMembersData(groupUin uint32) (map[uint32]*entity.GroupMember, error) {
groupMembers := make(map[uint32]*entity.GroupMember)
members, token, err := c.FetchGroupMember(groupUin, "")
members, token, err := c.FetchGroupMembers(groupUin, "")
if err != nil {
return groupMembers, err
}
for _, member := range members {
groupMembers[member.Uin] = member
}
for token != "" {
members, token, err = c.FetchGroupMember(groupUin, token)
members, token, err = c.FetchGroupMembers(groupUin, token)
if err != nil {
return groupMembers, err
}
Expand Down
21 changes: 19 additions & 2 deletions client/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,25 @@ func (c *QQClient) FetchGroups() ([]*entity.Group, error) {
return groups, nil
}

// FetchGroupMember 获取对应群的群成员信息,使用token可以获取下一页的群成员信息
func (c *QQClient) FetchGroupMember(groupUin uint32, token string) ([]*entity.GroupMember, string, error) {
// FetchGroupMember 获取对应群的群成员信息
func (c *QQClient) FetchGroupMember(groupUin, memberUin uint32) (*entity.GroupMember, error) {
pkt, err := oidb2.BuildFetchMemberReq(groupUin, c.GetUid(memberUin, groupUin))
if err != nil {
return nil, err
}
resp, err := c.sendOidbPacketAndWait(pkt)
if err != nil {
return nil, err
}
members, err := oidb2.ParseFetchMemberResp(resp)
if err != nil {
return nil, err
}
return members, nil
}

// FetchGroupMembers 获取对应群的所有群成员信息,使用token可以获取下一页的群成员信息
func (c *QQClient) FetchGroupMembers(groupUin uint32, token string) ([]*entity.GroupMember, string, error) {
pkt, err := oidb2.BuildFetchMembersReq(groupUin, token)
if err != nil {
return nil, "", err
Expand Down
49 changes: 49 additions & 0 deletions client/packets/oidb/FetchMember.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package oidb

import (
"github.com/LagrangeDev/LagrangeGo/client/entity"
"github.com/LagrangeDev/LagrangeGo/client/packets/pb/service/oidb"
"github.com/LagrangeDev/LagrangeGo/utils"
)

func BuildFetchMemberReq(groupUin uint32, memberUid string) (*OidbPacket, error) {
body := &oidb.OidbSvcTrpcTcp0XFE7_4{
GroupUin: groupUin,
Field2: 3,
Field3: 0,
Body: &oidb.OidbSvcTrpcScp0XFE7_3Body{
MemberName: true,
MemberCard: true,
Level: true,
JoinTimestamp: true,
LastMsgTimestamp: true,
Permission: true,
},
Params: &oidb.OidbSvcTrpcScp0XFE7_4Params{Uid: memberUid},
}
return BuildOidbPacket(0xFE7, 4, body, false, false)
}

func ParseFetchMemberResp(data []byte) (*entity.GroupMember, error) {
var resp oidb.OidbSvcTrpcTcp0XFE7_4Response
_, err := ParseOidbPacket(data, &resp)
if err != nil {
return nil, err
}
interner := utils.NewStringInterner()
member := resp.Member
m := &entity.GroupMember{
Uin: member.Uin.Uin,
Uid: interner.Intern(member.Uin.Uid),
Permission: entity.GroupMemberPermission(member.Permission),
MemberCard: interner.Intern(member.MemberCard.MemberCard.Unwrap()),
MemberName: interner.Intern(member.MemberName),
JoinTime: member.JoinTimestamp,
LastMsgTime: member.LastMsgTimestamp,
Avatar: interner.Intern(entity.FriendAvatar(member.Uin.Uin)),
}
if member.Level != nil {
m.GroupLevel = member.Level.Level
}
return m, nil
}
3 changes: 3 additions & 0 deletions client/packets/oidb/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ func ParseOidbPacket(b []byte, pkt any) (oidbBaseResp oidb.OidbSvcTrpcTcpBase, e
if err != nil {
return
}
if oidbBaseResp.ErrorCode != 0 {
return oidbBaseResp, errors.New(oidbBaseResp.ErrorMsg)
}
if pkt == nil {
return
}
Expand Down
21 changes: 21 additions & 0 deletions client/packets/pb/service/oidb/OidbSvcTrpcTcp0xFE7_3.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions client/packets/pb/service/oidb/OidbSvcTrpcTcp0xFE7_3.proto
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,21 @@ message OidbSvcTrpcTcp0xFE7_2Level {
repeated uint32 Infos = 1;
uint32 Level = 2;
}

message OidbSvcTrpcTcp0xFE7_4 {
uint32 GroupUin = 1;
uint32 Field2 = 2;
uint32 Field3 = 3;
OidbSvcTrpcScp0xFE7_3Body Body = 4;
OidbSvcTrpcScp0xFE7_4Params Params = 5;
}

message OidbSvcTrpcScp0xFE7_4Params {
string Uid = 2;
}

message OidbSvcTrpcTcp0xFE7_4Response {
uint32 GroupUin = 1;
OidbSvcTrpcTcp0xFE7_2Member Member = 2;
uint32 Field3 = 3;
}

0 comments on commit 1a50f37

Please sign in to comment.