mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 19:17:38 +08:00
style: use unpackOIDBPackage decode oidb response
This commit is contained in:
parent
68956c83bc
commit
261edb101e
@ -5,7 +5,6 @@ import (
|
|||||||
|
|
||||||
"github.com/Mrs4s/MiraiGo/binary"
|
"github.com/Mrs4s/MiraiGo/binary"
|
||||||
"github.com/Mrs4s/MiraiGo/client/pb/channel"
|
"github.com/Mrs4s/MiraiGo/client/pb/channel"
|
||||||
"github.com/Mrs4s/MiraiGo/client/pb/oidb"
|
|
||||||
"github.com/Mrs4s/MiraiGo/internal/packets"
|
"github.com/Mrs4s/MiraiGo/internal/packets"
|
||||||
"github.com/Mrs4s/MiraiGo/utils"
|
"github.com/Mrs4s/MiraiGo/utils"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -168,20 +167,16 @@ func (s *GuildService) GetUserProfile(tinyId uint64) (*GuildUserProfile, error)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "send packet error")
|
return nil, errors.Wrap(err, "send packet error")
|
||||||
}
|
}
|
||||||
pkg := new(oidb.OIDBSSOPkg)
|
body := new(channel.ChannelOidb0Xfc9Rsp)
|
||||||
oidbRsp := new(channel.ChannelOidb0Xfc9Rsp)
|
if err = s.c.unpackOIDBPackage(rsp, body); err != nil {
|
||||||
if err = proto.Unmarshal(rsp, pkg); err != nil {
|
return nil, errors.Wrap(err, "decode packet error")
|
||||||
return nil, errors.Wrap(err, "failed to unmarshal protobuf message")
|
|
||||||
}
|
|
||||||
if err = proto.Unmarshal(pkg.Bodybuffer, oidbRsp); err != nil {
|
|
||||||
return nil, errors.Wrap(err, "failed to unmarshal protobuf message")
|
|
||||||
}
|
}
|
||||||
// todo: 解析个性档案
|
// todo: 解析个性档案
|
||||||
return &GuildUserProfile{
|
return &GuildUserProfile{
|
||||||
TinyId: tinyId,
|
TinyId: tinyId,
|
||||||
Nickname: oidbRsp.Profile.GetNickname(),
|
Nickname: body.Profile.GetNickname(),
|
||||||
AvatarUrl: oidbRsp.Profile.GetAvatarUrl(),
|
AvatarUrl: body.Profile.GetAvatarUrl(),
|
||||||
JoinTime: oidbRsp.Profile.GetJoinTime(),
|
JoinTime: body.Profile.GetJoinTime(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,13 +200,9 @@ func (s *GuildService) GetGuildMembers(guildId uint64) (bots []*GuildMemberInfo,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, errors.Wrap(err, "send packet error")
|
return nil, nil, nil, errors.Wrap(err, "send packet error")
|
||||||
}
|
}
|
||||||
pkg := new(oidb.OIDBSSOPkg)
|
body := new(channel.ChannelOidb0Xf5BRsp)
|
||||||
oidbRsp := new(channel.ChannelOidb0Xf5BRsp)
|
if err = s.c.unpackOIDBPackage(rsp, body); err != nil {
|
||||||
if err = proto.Unmarshal(rsp, pkg); err != nil {
|
return nil, nil, nil, errors.Wrap(err, "decode packet error")
|
||||||
return nil, nil, nil, errors.Wrap(err, "failed to unmarshal protobuf message")
|
|
||||||
}
|
|
||||||
if err = proto.Unmarshal(pkg.Bodybuffer, oidbRsp); err != nil {
|
|
||||||
return nil, nil, nil, errors.Wrap(err, "failed to unmarshal protobuf message")
|
|
||||||
}
|
}
|
||||||
protoToMemberInfo := func(mem *channel.GuildMemberInfo) *GuildMemberInfo {
|
protoToMemberInfo := func(mem *channel.GuildMemberInfo) *GuildMemberInfo {
|
||||||
return &GuildMemberInfo{
|
return &GuildMemberInfo{
|
||||||
@ -222,13 +213,13 @@ func (s *GuildService) GetGuildMembers(guildId uint64) (bots []*GuildMemberInfo,
|
|||||||
Role: mem.GetRole(),
|
Role: mem.GetRole(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, mem := range oidbRsp.Bots {
|
for _, mem := range body.Bots {
|
||||||
bots = append(bots, protoToMemberInfo(mem))
|
bots = append(bots, protoToMemberInfo(mem))
|
||||||
}
|
}
|
||||||
for _, mem := range oidbRsp.Members {
|
for _, mem := range body.Members {
|
||||||
members = append(members, protoToMemberInfo(mem))
|
members = append(members, protoToMemberInfo(mem))
|
||||||
}
|
}
|
||||||
for _, mem := range oidbRsp.AdminInfo.Admins {
|
for _, mem := range body.AdminInfo.Admins {
|
||||||
admins = append(admins, protoToMemberInfo(mem))
|
admins = append(admins, protoToMemberInfo(mem))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -252,20 +243,16 @@ func (s *GuildService) GetGuildMemberProfileInfo(guildId, tinyId uint64) (*Guild
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "send packet error")
|
return nil, errors.Wrap(err, "send packet error")
|
||||||
}
|
}
|
||||||
pkg := new(oidb.OIDBSSOPkg)
|
body := new(channel.ChannelOidb0Xf88Rsp)
|
||||||
oidbRsp := new(channel.ChannelOidb0Xf88Rsp)
|
if err = s.c.unpackOIDBPackage(rsp, body); err != nil {
|
||||||
if err = proto.Unmarshal(rsp, pkg); err != nil {
|
return nil, errors.Wrap(err, "decode packet error")
|
||||||
return nil, errors.Wrap(err, "failed to unmarshal protobuf message")
|
|
||||||
}
|
|
||||||
if err = proto.Unmarshal(pkg.Bodybuffer, oidbRsp); err != nil {
|
|
||||||
return nil, errors.Wrap(err, "failed to unmarshal protobuf message")
|
|
||||||
}
|
}
|
||||||
// todo: 解析个性档案
|
// todo: 解析个性档案
|
||||||
return &GuildUserProfile{
|
return &GuildUserProfile{
|
||||||
TinyId: tinyId,
|
TinyId: tinyId,
|
||||||
Nickname: oidbRsp.Profile.GetNickname(),
|
Nickname: body.Profile.GetNickname(),
|
||||||
AvatarUrl: oidbRsp.Profile.GetAvatarUrl(),
|
AvatarUrl: body.Profile.GetAvatarUrl(),
|
||||||
JoinTime: oidbRsp.Profile.GetJoinTime(),
|
JoinTime: body.Profile.GetJoinTime(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,23 +278,19 @@ func (s *GuildService) FetchGuestGuild(guildId uint64) (*GuildMeta, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "send packet error")
|
return nil, errors.Wrap(err, "send packet error")
|
||||||
}
|
}
|
||||||
pkg := new(oidb.OIDBSSOPkg)
|
body := new(channel.ChannelOidb0Xf57Rsp)
|
||||||
oidbRsp := new(channel.ChannelOidb0Xf57Rsp)
|
if err = s.c.unpackOIDBPackage(rsp, body); err != nil {
|
||||||
if err = proto.Unmarshal(rsp, pkg); err != nil {
|
return nil, errors.Wrap(err, "decode packet error")
|
||||||
return nil, errors.Wrap(err, "failed to unmarshal protobuf message")
|
|
||||||
}
|
|
||||||
if err = proto.Unmarshal(pkg.Bodybuffer, oidbRsp); err != nil {
|
|
||||||
return nil, errors.Wrap(err, "failed to unmarshal protobuf message")
|
|
||||||
}
|
}
|
||||||
return &GuildMeta{
|
return &GuildMeta{
|
||||||
GuildName: oidbRsp.Rsp.Meta.GetName(),
|
GuildName: body.Rsp.Meta.GetName(),
|
||||||
GuildProfile: oidbRsp.Rsp.Meta.GetProfile(),
|
GuildProfile: body.Rsp.Meta.GetProfile(),
|
||||||
MaxMemberCount: oidbRsp.Rsp.Meta.GetMaxMemberCount(),
|
MaxMemberCount: body.Rsp.Meta.GetMaxMemberCount(),
|
||||||
MemberCount: oidbRsp.Rsp.Meta.GetMemberCount(),
|
MemberCount: body.Rsp.Meta.GetMemberCount(),
|
||||||
CreateTime: oidbRsp.Rsp.Meta.GetCreateTime(),
|
CreateTime: body.Rsp.Meta.GetCreateTime(),
|
||||||
MaxRobotCount: oidbRsp.Rsp.Meta.GetRobotMaxNum(),
|
MaxRobotCount: body.Rsp.Meta.GetRobotMaxNum(),
|
||||||
MaxAdminCount: oidbRsp.Rsp.Meta.GetAdminMaxNum(),
|
MaxAdminCount: body.Rsp.Meta.GetAdminMaxNum(),
|
||||||
OwnerId: oidbRsp.Rsp.Meta.GetOwnerId(),
|
OwnerId: body.Rsp.Meta.GetOwnerId(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user