Skip to content

Commit

Permalink
feat: update FetchGuildMemberProfileInfo api
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrs4s committed Dec 10, 2021
1 parent be7293b commit a206b00
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 45 deletions.
82 changes: 45 additions & 37 deletions client/guild.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type (
OwnerId uint64
}

// GuildMemberInfo 频道成员信息, 仅通过频道成员列表API获取
GuildMemberInfo struct {
TinyId uint64
Title string
Expand All @@ -74,6 +75,7 @@ type (
Nickname string
AvatarUrl string
JoinTime int64 // 只有 GetGuildMemberProfileInfo 函数才会有
Roles []*GuildRole
}

// GuildRole 频道身份组信息
Expand Down Expand Up @@ -266,7 +268,8 @@ func (s *GuildService) FetchGuildMemberListWithRole(guildId, channelId uint64, s
}, nil
}

func (s *GuildService) GetGuildMemberProfileInfo(guildId, tinyId uint64) (*GuildUserProfile, error) {
// FetchGuildMemberProfileInfo 获取单个频道成员资料
func (s *GuildService) FetchGuildMemberProfileInfo(guildId, tinyId uint64) (*GuildUserProfile, error) {
seq := s.c.nextSeq()
flags := binary.DynamicProtoMessage{}
for i := 3; i <= 29; i++ {
Expand All @@ -288,12 +291,17 @@ func (s *GuildService) GetGuildMemberProfileInfo(guildId, tinyId uint64) (*Guild
if err = s.c.unpackOIDBPackage(rsp, body); err != nil {
return nil, errors.Wrap(err, "decode packet error")
}
roles, err := s.fetchMemberRoles(guildId, tinyId)
if err != nil {
return nil, errors.Wrap(err, "fetch roles error")
}
// todo: 解析个性档案
return &GuildUserProfile{
TinyId: tinyId,
Nickname: body.Profile.GetNickname(),
AvatarUrl: body.Profile.GetAvatarUrl(),
JoinTime: body.Profile.GetJoinTime(),
Roles: roles,
}, nil
}

Expand Down Expand Up @@ -325,42 +333,6 @@ func (s *GuildService) GetGuildRoles(guildId uint64) ([]*GuildRole, error) {
return roles, nil
}

func (s *GuildService) GetUserRoles(guildId uint64, userId uint64) ([]*GuildRole, error) {
seq := s.c.nextSeq()
u1 := uint32(1)
packet := packets.BuildUniPacket(s.c.Uin, seq, "OidbSvcTrpcTcp.0x1017_1", 1, s.c.OutGoingPacketSessionId, []byte{}, s.c.sigInfo.d2Key,
s.c.packOIDBPackageDynamically(4119, 1, binary.DynamicProtoMessage{
1: guildId,
2: userId,
4: binary.DynamicProtoMessage{
1: u1,
2: u1,
3: u1,
},
}))
rsp, err := s.c.sendAndWaitDynamic(seq, packet)
if err != nil {
return nil, errors.Wrap(err, "send packet error")
}
body := new(channel.ChannelOidb0X1017Rsp)
if err = s.c.unpackOIDBPackage(rsp, body); err != nil {
return nil, errors.Wrap(err, "decode packet error")
}
p1 := body.GetP1()
if p1 == nil {
return nil, errors.New("packet OidbSvcTrpcTcp.0x1017_1: decode p1 error")
}
roles := make([]*GuildRole, 0, len(p1.GetRoles()))
for _, role := range p1.GetRoles() {
roles = append(roles, &GuildRole{
RoleId: role.GetRoleId(),
RoleName: role.GetName(),
ArgbColor: role.GetArgbColor(),
})
}
return roles, nil
}

func (s *GuildService) CreateGuildRole(guildId uint64, name string, color uint32, independent bool, initialUsers []uint64) (uint64, error) {
seq := s.c.nextSeq()
u1 := uint32(1)
Expand Down Expand Up @@ -656,6 +628,42 @@ func (s *GuildService) PostTopicChannelFeed(guildId, channelId uint64, feed *top
return errors.New("post feed error")
}

func (s *GuildService) fetchMemberRoles(guildId uint64, tinyId uint64) ([]*GuildRole, error) {
seq := s.c.nextSeq()
u1 := uint32(1)
packet := packets.BuildUniPacket(s.c.Uin, seq, "OidbSvcTrpcTcp.0x1017_1", 1, s.c.OutGoingPacketSessionId, []byte{}, s.c.sigInfo.d2Key,
s.c.packOIDBPackageDynamically(4119, 1, binary.DynamicProtoMessage{
1: guildId,
2: tinyId,
4: binary.DynamicProtoMessage{
1: u1,
2: u1,
3: u1,
},
}))
rsp, err := s.c.sendAndWaitDynamic(seq, packet)
if err != nil {
return nil, errors.Wrap(err, "send packet error")
}
body := new(channel.ChannelOidb0X1017Rsp)
if err = s.c.unpackOIDBPackage(rsp, body); err != nil {
return nil, errors.Wrap(err, "decode packet error")
}
p1 := body.GetP1()
if p1 == nil {
return nil, errors.New("packet OidbSvcTrpcTcp.0x1017_1: decode p1 error")
}
roles := make([]*GuildRole, 0, len(p1.GetRoles()))
for _, role := range p1.GetRoles() {
roles = append(roles, &GuildRole{
RoleId: role.GetRoleId(),
RoleName: role.GetName(),
ArgbColor: role.GetArgbColor(),
})
}
return roles, nil
}

/* need analysis
func (s *GuildService) fetchChannelListState(guildId uint64, channels []*ChannelInfo) {
seq := s.c.nextSeq()
Expand Down
47 changes: 41 additions & 6 deletions client/pb/channel/unknown.pb.go

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

11 changes: 9 additions & 2 deletions client/pb/channel/unknown.proto
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ message ChannelOidb0x1017Rsp {
}

message P10x1017 {
optional uint64 userId = 1;
repeated GuildRole roles = 3;
optional uint64 tinyId = 1;
repeated GuildUserRole roles = 3;
}

message ChannelOidb0x1019Rsp {
Expand Down Expand Up @@ -131,6 +131,13 @@ message GuildRole {
// 9: ?
}

message GuildUserRole {
optional uint64 roleId = 1;
optional string name = 2;
optional uint32 argbColor = 3;
optional int32 independent = 4;
}

/*
message SetGuildRole {
optional uint64 roleId = 1;
Expand Down

0 comments on commit a206b00

Please sign in to comment.