1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-04 19:17:38 +08:00

feat: update FetchGuildMemberProfileInfo api

This commit is contained in:
Mrs4s 2021-12-11 02:34:32 +08:00
parent be7293b1c0
commit a206b0077c
No known key found for this signature in database
GPG Key ID: 3186E98FA19CE3A7
3 changed files with 95 additions and 45 deletions

View File

@ -59,6 +59,7 @@ type (
OwnerId uint64 OwnerId uint64
} }
// GuildMemberInfo 频道成员信息, 仅通过频道成员列表API获取
GuildMemberInfo struct { GuildMemberInfo struct {
TinyId uint64 TinyId uint64
Title string Title string
@ -74,6 +75,7 @@ type (
Nickname string Nickname string
AvatarUrl string AvatarUrl string
JoinTime int64 // 只有 GetGuildMemberProfileInfo 函数才会有 JoinTime int64 // 只有 GetGuildMemberProfileInfo 函数才会有
Roles []*GuildRole
} }
// GuildRole 频道身份组信息 // GuildRole 频道身份组信息
@ -266,7 +268,8 @@ func (s *GuildService) FetchGuildMemberListWithRole(guildId, channelId uint64, s
}, nil }, nil
} }
func (s *GuildService) GetGuildMemberProfileInfo(guildId, tinyId uint64) (*GuildUserProfile, error) { // FetchGuildMemberProfileInfo 获取单个频道成员资料
func (s *GuildService) FetchGuildMemberProfileInfo(guildId, tinyId uint64) (*GuildUserProfile, error) {
seq := s.c.nextSeq() seq := s.c.nextSeq()
flags := binary.DynamicProtoMessage{} flags := binary.DynamicProtoMessage{}
for i := 3; i <= 29; i++ { for i := 3; i <= 29; i++ {
@ -288,12 +291,17 @@ func (s *GuildService) GetGuildMemberProfileInfo(guildId, tinyId uint64) (*Guild
if err = s.c.unpackOIDBPackage(rsp, body); err != nil { if err = s.c.unpackOIDBPackage(rsp, body); err != nil {
return nil, errors.Wrap(err, "decode packet error") 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: 解析个性档案 // todo: 解析个性档案
return &GuildUserProfile{ return &GuildUserProfile{
TinyId: tinyId, TinyId: tinyId,
Nickname: body.Profile.GetNickname(), Nickname: body.Profile.GetNickname(),
AvatarUrl: body.Profile.GetAvatarUrl(), AvatarUrl: body.Profile.GetAvatarUrl(),
JoinTime: body.Profile.GetJoinTime(), JoinTime: body.Profile.GetJoinTime(),
Roles: roles,
}, nil }, nil
} }
@ -325,42 +333,6 @@ func (s *GuildService) GetGuildRoles(guildId uint64) ([]*GuildRole, error) {
return roles, nil 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) { func (s *GuildService) CreateGuildRole(guildId uint64, name string, color uint32, independent bool, initialUsers []uint64) (uint64, error) {
seq := s.c.nextSeq() seq := s.c.nextSeq()
u1 := uint32(1) u1 := uint32(1)
@ -656,6 +628,42 @@ func (s *GuildService) PostTopicChannelFeed(guildId, channelId uint64, feed *top
return errors.New("post feed error") 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 /* need analysis
func (s *GuildService) fetchChannelListState(guildId uint64, channels []*ChannelInfo) { func (s *GuildService) fetchChannelListState(guildId uint64, channels []*ChannelInfo) {
seq := s.c.nextSeq() seq := s.c.nextSeq()

View File

@ -138,18 +138,18 @@ func (x *ChannelOidb0X1017Rsp) GetP1() *P10X1017 {
} }
type P10X1017 struct { type P10X1017 struct {
UserId *uint64 `protobuf:"varint,1,opt"` TinyId *uint64 `protobuf:"varint,1,opt"`
Roles []*GuildRole `protobuf:"bytes,3,rep"` Roles []*GuildUserRole `protobuf:"bytes,3,rep"`
} }
func (x *P10X1017) GetUserId() uint64 { func (x *P10X1017) GetTinyId() uint64 {
if x != nil && x.UserId != nil { if x != nil && x.TinyId != nil {
return *x.UserId return *x.TinyId
} }
return 0 return 0
} }
func (x *P10X1017) GetRoles() []*GuildRole { func (x *P10X1017) GetRoles() []*GuildUserRole {
if x != nil { if x != nil {
return x.Roles return x.Roles
} }
@ -407,6 +407,41 @@ func (x *GuildRole) GetMaxNum() int32 {
return 0 return 0
} }
type GuildUserRole struct {
RoleId *uint64 `protobuf:"varint,1,opt"`
Name *string `protobuf:"bytes,2,opt"`
ArgbColor *uint32 `protobuf:"varint,3,opt"`
Independent *int32 `protobuf:"varint,4,opt"`
}
func (x *GuildUserRole) GetRoleId() uint64 {
if x != nil && x.RoleId != nil {
return *x.RoleId
}
return 0
}
func (x *GuildUserRole) GetName() string {
if x != nil && x.Name != nil {
return *x.Name
}
return ""
}
func (x *GuildUserRole) GetArgbColor() uint32 {
if x != nil && x.ArgbColor != nil {
return *x.ArgbColor
}
return 0
}
func (x *GuildUserRole) GetIndependent() int32 {
if x != nil && x.Independent != nil {
return *x.Independent
}
return 0
}
type GuildMeta struct { type GuildMeta struct {
GuildCode *uint64 `protobuf:"varint,2,opt"` GuildCode *uint64 `protobuf:"varint,2,opt"`
CreateTime *int64 `protobuf:"varint,4,opt"` CreateTime *int64 `protobuf:"varint,4,opt"`

View File

@ -42,8 +42,8 @@ message ChannelOidb0x1017Rsp {
} }
message P10x1017 { message P10x1017 {
optional uint64 userId = 1; optional uint64 tinyId = 1;
repeated GuildRole roles = 3; repeated GuildUserRole roles = 3;
} }
message ChannelOidb0x1019Rsp { message ChannelOidb0x1019Rsp {
@ -131,6 +131,13 @@ message GuildRole {
// 9: ? // 9: ?
} }
message GuildUserRole {
optional uint64 roleId = 1;
optional string name = 2;
optional uint32 argbColor = 3;
optional int32 independent = 4;
}
/* /*
message SetGuildRole { message SetGuildRole {
optional uint64 roleId = 1; optional uint64 roleId = 1;