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

feat: FetchChannelInfo

This commit is contained in:
Mrs4s 2021-11-11 17:51:59 +08:00
parent 75d6d547d2
commit d7c66bf26a
No known key found for this signature in database
GPG Key ID: 3186E98FA19CE3A7
4 changed files with 728 additions and 169 deletions

View File

@ -663,6 +663,20 @@ func (c *QQClient) packOIDBPackageProto(cmd, serviceType int32, msg proto.Messag
return c.packOIDBPackage(cmd, serviceType, b) return c.packOIDBPackage(cmd, serviceType, b)
} }
func (c *QQClient) unpackOIDBPackage(buff []byte, payload proto.Message) error {
pkg := new(oidb.OIDBSSOPkg)
if err := proto.Unmarshal(buff, pkg); err != nil {
return errors.Wrap(err, "failed to unmarshal protobuf message")
}
if pkg.GetResult() != 0 {
return errors.Errorf("oidb result unsuccessful: %v msg: %v", pkg.GetResult(), pkg.GetErrorMsg())
}
if err := proto.Unmarshal(pkg.Bodybuffer, payload); err != nil {
return errors.Wrap(err, "failed to unmarshal protobuf message")
}
return nil
}
func (c *QQClient) Error(msg string, args ...interface{}) { func (c *QQClient) Error(msg string, args ...interface{}) {
c.dispatchLogEvent(&LogEvent{ c.dispatchLogEvent(&LogEvent{
Type: "ERROR", Type: "ERROR",

View File

@ -2,7 +2,6 @@ package client
import ( import (
"fmt" "fmt"
"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/client/pb/oidb"
@ -74,9 +73,39 @@ type (
Time uint64 Time uint64
EventTime uint32 EventTime uint32
NotifyType uint32 NotifyType uint32
ChannelType uint32 ChannelType ChannelType
AtAllSeq uint64 AtAllSeq uint64
Meta *ChannelMeta
} }
ChannelMeta struct {
CreatorUin int64
CreatorTinyId uint64
CreateTime int64
GuildId uint64
VisibleType int32
TopMessageSeq uint64
TopMessageTime int64
TopMessageOperatorId uint64
CurrentSlowMode int32
TalkPermission int32
SlowModes []*ChannelSlowModeInfo
}
ChannelSlowModeInfo struct {
SlowModeKey int32
SpeakFrequency int32
SlowModeCircle int32
SlowModeText string
}
ChannelType int32
)
const (
ChannelTypeText ChannelType = 1
ChannelTypeVoice ChannelType = 2
ChannelTypeLive ChannelType = 5
) )
func init() { func init() {
@ -281,6 +310,49 @@ func (s *GuildService) FetchGuestGuild(guildId uint64) (*GuildMeta, error) {
}, nil }, nil
} }
func (s *GuildService) FetchChannelInfo(guildId, channelId uint64) (*ChannelInfo, error) {
seq := s.c.nextSeq()
packet := packets.BuildUniPacket(s.c.Uin, seq, "OidbSvcTrpcTcp.0xf55_1", 1, s.c.OutGoingPacketSessionId, []byte{}, s.c.sigInfo.d2Key,
s.c.packOIDBPackageDynamically(3925, 1, binary.DynamicProtoMessage{1: guildId, 2: channelId}))
rsp, err := s.c.sendAndWaitDynamic(seq, packet)
if err != nil {
return nil, errors.Wrap(err, "send packet error")
}
body := new(channel.ChannelOidb0Xf55Rsp)
if err = s.c.unpackOIDBPackage(rsp, body); err != nil {
return nil, errors.Wrap(err, "decode packet error")
}
meta := &ChannelMeta{
CreatorUin: body.Info.GetCreatorUin(),
CreatorTinyId: body.Info.GetCreatorTinyId(),
CreateTime: body.Info.GetCreateTime(),
GuildId: body.Info.GetGuildId(),
VisibleType: body.Info.GetVisibleType(),
CurrentSlowMode: body.Info.GetCurrentSlowModeKey(),
TalkPermission: body.Info.GetTalkPermission(),
}
if body.Info.TopMsg != nil {
meta.TopMessageSeq = body.Info.TopMsg.GetTopMsgSeq()
meta.TopMessageTime = body.Info.TopMsg.GetTopMsgTime()
meta.TopMessageOperatorId = body.Info.TopMsg.GetTopMsgOperatorTinyId()
}
for _, slow := range body.Info.SlowModeInfos {
meta.SlowModes = append(meta.SlowModes, &ChannelSlowModeInfo{
SlowModeKey: slow.GetSlowModeKey(),
SpeakFrequency: slow.GetSpeakFrequency(),
SlowModeCircle: slow.GetSlowModeCircle(),
SlowModeText: slow.GetSlowModeText(),
})
}
return &ChannelInfo{
ChannelId: body.Info.GetChannelId(),
ChannelName: body.Info.GetChannelName(),
NotifyType: uint32(body.Info.GetFinalNotifyType()),
ChannelType: ChannelType(body.Info.GetChannelType()),
Meta: meta,
}, 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()
@ -362,7 +434,7 @@ func decodeGuildPushFirstView(c *QQClient, _ *incomingPacketInfo, payload []byte
Time: node.GetTime(), Time: node.GetTime(),
EventTime: node.GetEventTime(), EventTime: node.GetEventTime(),
NotifyType: node.GetNotifyType(), NotifyType: node.GetNotifyType(),
ChannelType: node.GetChannelType(), ChannelType: ChannelType(node.GetChannelType()),
AtAllSeq: meta.GetAtAllSeq(), AtAllSeq: meta.GetAtAllSeq(),
}) })
} }

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,7 @@ syntax = "proto2";
package channel; package channel;
option go_package = "./;channel"; option go_package = "pb/channel;channel";
message ChannelOidb0xf5bRsp { message ChannelOidb0xf5bRsp {
optional uint64 guildId = 1; optional uint64 guildId = 1;
@ -24,6 +24,10 @@ message ChannelOidb0xf57Rsp {
optional GuildMetaRsp rsp = 1; optional GuildMetaRsp rsp = 1;
} }
message ChannelOidb0xf55Rsp {
optional GuildChannelInfo info = 1;
}
message GuildMetaRsp { message GuildMetaRsp {
optional uint64 guildId = 3; optional uint64 guildId = 3;
optional GuildMeta meta = 4; optional GuildMeta meta = 4;
@ -68,6 +72,36 @@ message GuildMeta {
optional int32 clientId = 20; optional int32 clientId = 20;
} }
message GuildChannelInfo {
optional uint64 channelId = 1;
optional string channelName = 2;
optional int64 creatorUin = 3;
optional int64 createTime = 4;
optional uint64 guildId = 5;
optional int32 finalNotifyType = 6;
optional int32 channelType = 7;
optional int32 talkPermission = 8;
// 11 - 14 : MsgInfo
optional uint64 creatorTinyId = 15;
// 16: Member info ?
optional int32 visibleType = 22;
optional GuildChannelTopMsgInfo topMsg = 28;
optional int32 currentSlowModeKey = 31;
repeated GuildChannelSlowModeInfo slowModeInfos = 32;
}
message GuildChannelSlowModeInfo {
optional int32 slowModeKey = 1;
optional int32 speakFrequency = 2;
optional int32 slowModeCircle = 3;
optional string slowModeText = 4;
}
message GuildChannelTopMsgInfo {
optional uint64 topMsgSeq = 1;
optional int64 topMsgTime = 2;
optional uint64 topMsgOperatorTinyId = 3;
}
/* /*
// //
message GuildMemberProfileCard { message GuildMemberProfileCard {