Skip to content

Commit

Permalink
Merge pull request Mrs4s#202 from Kengxxiao/upstream-dev
Browse files Browse the repository at this point in the history
feat: GetUserRoles
  • Loading branch information
Mrs4s authored Nov 21, 2021
2 parents 0ac2dad + 56d2280 commit dd5435d
Show file tree
Hide file tree
Showing 3 changed files with 403 additions and 222 deletions.
43 changes: 39 additions & 4 deletions client/guild.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ func (s *GuildService) GetGuildRoles(guildId uint64) ([]*GuildRole, error) {
if err = s.c.unpackOIDBPackage(rsp, body); err != nil {
return nil, errors.Wrap(err, "decode packet error")
}
roles := make([]*GuildRole, 0, len(body.Roles))
for _, role := range body.Roles {
roles := make([]*GuildRole, 0, len(body.GetRoles()))
for _, role := range body.GetRoles() {
roles = append(roles, &GuildRole{
RoleId: role.GetRoleId(),
RoleName: role.GetName(),
Expand All @@ -324,6 +324,42 @@ 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 @@ -369,7 +405,6 @@ func (s *GuildService) DeleteGuildRole(guildId uint64, roleId uint64) error {

func (s *GuildService) SetUserRoleInGuild(guildId uint64, set bool, roleId uint64, user []uint64) error { // remove => p2 = false
seq := s.c.nextSeq()
var packet []byte
setOrRemove := binary.DynamicProtoMessage{
1: roleId,
}
Expand All @@ -378,7 +413,7 @@ func (s *GuildService) SetUserRoleInGuild(guildId uint64, set bool, roleId uint6
} else {
setOrRemove[3] = user
}
packet = packets.BuildUniPacket(s.c.Uin, seq, "OidbSvcTrpcTcp.0x101a_1", 1, s.c.OutGoingPacketSessionId, []byte{}, s.c.sigInfo.d2Key,
packet := packets.BuildUniPacket(s.c.Uin, seq, "OidbSvcTrpcTcp.0x101a_1", 1, s.c.OutGoingPacketSessionId, []byte{}, s.c.sigInfo.d2Key,
s.c.packOIDBPackageDynamically(4122, 1, binary.DynamicProtoMessage{
1: guildId,
2: setOrRemove,
Expand Down
Loading

0 comments on commit dd5435d

Please sign in to comment.