From 8427db5347af1e736100cc4ce4f641df1c7916f4 Mon Sep 17 00:00:00 2001 From: Mrs4s Date: Sun, 14 Nov 2021 17:16:01 +0800 Subject: [PATCH] feat: support guild at message decode --- client/pb/msg/TextMsgExt.pb.go | 372 +++++++++++++++++++++++++++++++++ client/pb/msg/TextMsgExt.proto | 25 +++ message/message.go | 21 +- 3 files changed, 412 insertions(+), 6 deletions(-) create mode 100644 client/pb/msg/TextMsgExt.pb.go create mode 100644 client/pb/msg/TextMsgExt.proto diff --git a/client/pb/msg/TextMsgExt.pb.go b/client/pb/msg/TextMsgExt.pb.go new file mode 100644 index 00000000..0a7eee4d --- /dev/null +++ b/client/pb/msg/TextMsgExt.pb.go @@ -0,0 +1,372 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.1 +// protoc v3.14.0 +// source: TextMsgExt.proto + +package msg + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type ExtChannelInfo struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + GuildId *uint64 `protobuf:"varint,1,opt,name=guildId" json:"guildId,omitempty"` + ChannelId *uint64 `protobuf:"varint,2,opt,name=channelId" json:"channelId,omitempty"` +} + +func (x *ExtChannelInfo) Reset() { + *x = ExtChannelInfo{} + if protoimpl.UnsafeEnabled { + mi := &file_TextMsgExt_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ExtChannelInfo) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ExtChannelInfo) ProtoMessage() {} + +func (x *ExtChannelInfo) ProtoReflect() protoreflect.Message { + mi := &file_TextMsgExt_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ExtChannelInfo.ProtoReflect.Descriptor instead. +func (*ExtChannelInfo) Descriptor() ([]byte, []int) { + return file_TextMsgExt_proto_rawDescGZIP(), []int{0} +} + +func (x *ExtChannelInfo) GetGuildId() uint64 { + if x != nil && x.GuildId != nil { + return *x.GuildId + } + return 0 +} + +func (x *ExtChannelInfo) GetChannelId() uint64 { + if x != nil && x.ChannelId != nil { + return *x.ChannelId + } + return 0 +} + +type TextResvAttr struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Wording []byte `protobuf:"bytes,1,opt,name=wording" json:"wording,omitempty"` + TextAnalysisResult *uint32 `protobuf:"varint,2,opt,name=textAnalysisResult" json:"textAnalysisResult,omitempty"` + AtType *uint32 `protobuf:"varint,3,opt,name=atType" json:"atType,omitempty"` + AtMemberUin *uint64 `protobuf:"varint,4,opt,name=atMemberUin" json:"atMemberUin,omitempty"` + AtMemberTinyid *uint64 `protobuf:"varint,5,opt,name=atMemberTinyid" json:"atMemberTinyid,omitempty"` + AtMemberRoleInfo *ExtRoleInfo `protobuf:"bytes,6,opt,name=atMemberRoleInfo" json:"atMemberRoleInfo,omitempty"` + AtRoleInfo *ExtRoleInfo `protobuf:"bytes,7,opt,name=atRoleInfo" json:"atRoleInfo,omitempty"` + AtChannelInfo *ExtChannelInfo `protobuf:"bytes,8,opt,name=atChannelInfo" json:"atChannelInfo,omitempty"` +} + +func (x *TextResvAttr) Reset() { + *x = TextResvAttr{} + if protoimpl.UnsafeEnabled { + mi := &file_TextMsgExt_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TextResvAttr) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TextResvAttr) ProtoMessage() {} + +func (x *TextResvAttr) ProtoReflect() protoreflect.Message { + mi := &file_TextMsgExt_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TextResvAttr.ProtoReflect.Descriptor instead. +func (*TextResvAttr) Descriptor() ([]byte, []int) { + return file_TextMsgExt_proto_rawDescGZIP(), []int{1} +} + +func (x *TextResvAttr) GetWording() []byte { + if x != nil { + return x.Wording + } + return nil +} + +func (x *TextResvAttr) GetTextAnalysisResult() uint32 { + if x != nil && x.TextAnalysisResult != nil { + return *x.TextAnalysisResult + } + return 0 +} + +func (x *TextResvAttr) GetAtType() uint32 { + if x != nil && x.AtType != nil { + return *x.AtType + } + return 0 +} + +func (x *TextResvAttr) GetAtMemberUin() uint64 { + if x != nil && x.AtMemberUin != nil { + return *x.AtMemberUin + } + return 0 +} + +func (x *TextResvAttr) GetAtMemberTinyid() uint64 { + if x != nil && x.AtMemberTinyid != nil { + return *x.AtMemberTinyid + } + return 0 +} + +func (x *TextResvAttr) GetAtMemberRoleInfo() *ExtRoleInfo { + if x != nil { + return x.AtMemberRoleInfo + } + return nil +} + +func (x *TextResvAttr) GetAtRoleInfo() *ExtRoleInfo { + if x != nil { + return x.AtRoleInfo + } + return nil +} + +func (x *TextResvAttr) GetAtChannelInfo() *ExtChannelInfo { + if x != nil { + return x.AtChannelInfo + } + return nil +} + +type ExtRoleInfo struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id *uint64 `protobuf:"varint,1,opt,name=id" json:"id,omitempty"` + Info []byte `protobuf:"bytes,2,opt,name=info" json:"info,omitempty"` + Flag *uint32 `protobuf:"varint,3,opt,name=flag" json:"flag,omitempty"` +} + +func (x *ExtRoleInfo) Reset() { + *x = ExtRoleInfo{} + if protoimpl.UnsafeEnabled { + mi := &file_TextMsgExt_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ExtRoleInfo) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ExtRoleInfo) ProtoMessage() {} + +func (x *ExtRoleInfo) ProtoReflect() protoreflect.Message { + mi := &file_TextMsgExt_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ExtRoleInfo.ProtoReflect.Descriptor instead. +func (*ExtRoleInfo) Descriptor() ([]byte, []int) { + return file_TextMsgExt_proto_rawDescGZIP(), []int{2} +} + +func (x *ExtRoleInfo) GetId() uint64 { + if x != nil && x.Id != nil { + return *x.Id + } + return 0 +} + +func (x *ExtRoleInfo) GetInfo() []byte { + if x != nil { + return x.Info + } + return nil +} + +func (x *ExtRoleInfo) GetFlag() uint32 { + if x != nil && x.Flag != nil { + return *x.Flag + } + return 0 +} + +var File_TextMsgExt_proto protoreflect.FileDescriptor + +var file_TextMsgExt_proto_rawDesc = []byte{ + 0x0a, 0x10, 0x54, 0x65, 0x78, 0x74, 0x4d, 0x73, 0x67, 0x45, 0x78, 0x74, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x22, 0x48, 0x0a, 0x0e, 0x45, 0x78, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, + 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x18, 0x0a, 0x07, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x49, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x07, 0x67, 0x75, 0x69, 0x6c, 0x64, 0x49, 0x64, 0x12, 0x1c, + 0x0a, 0x09, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x04, 0x52, 0x09, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x49, 0x64, 0x22, 0xd9, 0x02, 0x0a, + 0x0c, 0x54, 0x65, 0x78, 0x74, 0x52, 0x65, 0x73, 0x76, 0x41, 0x74, 0x74, 0x72, 0x12, 0x18, 0x0a, + 0x07, 0x77, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, + 0x77, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x67, 0x12, 0x2e, 0x0a, 0x12, 0x74, 0x65, 0x78, 0x74, 0x41, + 0x6e, 0x61, 0x6c, 0x79, 0x73, 0x69, 0x73, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0d, 0x52, 0x12, 0x74, 0x65, 0x78, 0x74, 0x41, 0x6e, 0x61, 0x6c, 0x79, 0x73, 0x69, + 0x73, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x74, 0x54, 0x79, 0x70, + 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x61, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, + 0x20, 0x0a, 0x0b, 0x61, 0x74, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x55, 0x69, 0x6e, 0x18, 0x04, + 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x61, 0x74, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x55, 0x69, + 0x6e, 0x12, 0x26, 0x0a, 0x0e, 0x61, 0x74, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x54, 0x69, 0x6e, + 0x79, 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0e, 0x61, 0x74, 0x4d, 0x65, 0x6d, + 0x62, 0x65, 0x72, 0x54, 0x69, 0x6e, 0x79, 0x69, 0x64, 0x12, 0x38, 0x0a, 0x10, 0x61, 0x74, 0x4d, + 0x65, 0x6d, 0x62, 0x65, 0x72, 0x52, 0x6f, 0x6c, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x18, 0x06, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x45, 0x78, 0x74, 0x52, 0x6f, 0x6c, 0x65, 0x49, 0x6e, 0x66, + 0x6f, 0x52, 0x10, 0x61, 0x74, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x52, 0x6f, 0x6c, 0x65, 0x49, + 0x6e, 0x66, 0x6f, 0x12, 0x2c, 0x0a, 0x0a, 0x61, 0x74, 0x52, 0x6f, 0x6c, 0x65, 0x49, 0x6e, 0x66, + 0x6f, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x45, 0x78, 0x74, 0x52, 0x6f, 0x6c, + 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x0a, 0x61, 0x74, 0x52, 0x6f, 0x6c, 0x65, 0x49, 0x6e, 0x66, + 0x6f, 0x12, 0x35, 0x0a, 0x0d, 0x61, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x49, 0x6e, + 0x66, 0x6f, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x45, 0x78, 0x74, 0x43, 0x68, + 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x0d, 0x61, 0x74, 0x43, 0x68, 0x61, + 0x6e, 0x6e, 0x65, 0x6c, 0x49, 0x6e, 0x66, 0x6f, 0x22, 0x45, 0x0a, 0x0b, 0x45, 0x78, 0x74, 0x52, + 0x6f, 0x6c, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x04, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x12, 0x12, 0x0a, 0x04, 0x66, + 0x6c, 0x61, 0x67, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x66, 0x6c, 0x61, 0x67, 0x42, + 0x08, 0x5a, 0x06, 0x2e, 0x2f, 0x3b, 0x6d, 0x73, 0x67, +} + +var ( + file_TextMsgExt_proto_rawDescOnce sync.Once + file_TextMsgExt_proto_rawDescData = file_TextMsgExt_proto_rawDesc +) + +func file_TextMsgExt_proto_rawDescGZIP() []byte { + file_TextMsgExt_proto_rawDescOnce.Do(func() { + file_TextMsgExt_proto_rawDescData = protoimpl.X.CompressGZIP(file_TextMsgExt_proto_rawDescData) + }) + return file_TextMsgExt_proto_rawDescData +} + +var file_TextMsgExt_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_TextMsgExt_proto_goTypes = []interface{}{ + (*ExtChannelInfo)(nil), // 0: ExtChannelInfo + (*TextResvAttr)(nil), // 1: TextResvAttr + (*ExtRoleInfo)(nil), // 2: ExtRoleInfo +} +var file_TextMsgExt_proto_depIdxs = []int32{ + 2, // 0: TextResvAttr.atMemberRoleInfo:type_name -> ExtRoleInfo + 2, // 1: TextResvAttr.atRoleInfo:type_name -> ExtRoleInfo + 0, // 2: TextResvAttr.atChannelInfo:type_name -> ExtChannelInfo + 3, // [3:3] is the sub-list for method output_type + 3, // [3:3] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name +} + +func init() { file_TextMsgExt_proto_init() } +func file_TextMsgExt_proto_init() { + if File_TextMsgExt_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_TextMsgExt_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ExtChannelInfo); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_TextMsgExt_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TextResvAttr); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_TextMsgExt_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ExtRoleInfo); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_TextMsgExt_proto_rawDesc, + NumEnums: 0, + NumMessages: 3, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_TextMsgExt_proto_goTypes, + DependencyIndexes: file_TextMsgExt_proto_depIdxs, + MessageInfos: file_TextMsgExt_proto_msgTypes, + }.Build() + File_TextMsgExt_proto = out.File + file_TextMsgExt_proto_rawDesc = nil + file_TextMsgExt_proto_goTypes = nil + file_TextMsgExt_proto_depIdxs = nil +} diff --git a/client/pb/msg/TextMsgExt.proto b/client/pb/msg/TextMsgExt.proto new file mode 100644 index 00000000..131c8c29 --- /dev/null +++ b/client/pb/msg/TextMsgExt.proto @@ -0,0 +1,25 @@ +syntax = "proto2"; + +option go_package = "./;msg"; + +message ExtChannelInfo { + optional uint64 guildId = 1; + optional uint64 channelId = 2; +} + +message TextResvAttr { + optional bytes wording = 1; + optional uint32 textAnalysisResult = 2; + optional uint32 atType = 3; + optional uint64 atMemberUin = 4; + optional uint64 atMemberTinyid = 5; + optional ExtRoleInfo atMemberRoleInfo = 6; + optional ExtRoleInfo atRoleInfo = 7; + optional ExtChannelInfo atChannelInfo = 8; +} + +message ExtRoleInfo { + optional uint64 id = 1; + optional bytes info = 2; + optional uint32 flag = 3; +} \ No newline at end of file diff --git a/message/message.go b/message/message.go index 81cc1ccd..5c547622 100644 --- a/message/message.go +++ b/message/message.go @@ -392,7 +392,21 @@ func ParseMessageElems(elems []*msg.Elem) []IMessageElement { } } if elem.Text != nil { - if len(elem.Text.Attr6Buf) == 0 { + switch { + case len(elem.Text.Attr6Buf) > 0: + att6 := binary.NewReader(elem.Text.Attr6Buf) + att6.ReadBytes(7) + target := int64(uint32(att6.ReadInt32())) + res = append(res, NewAt(target, elem.Text.GetStr())) + case len(elem.Text.PbReserve) > 0: + resv := new(msg.TextResvAttr) + _ = proto.Unmarshal(elem.Text.PbReserve, resv) + if resv.GetAtType() == 2 { + res = append(res, NewAt(int64(resv.GetAtMemberTinyid()), elem.Text.GetStr())) + break + } + fallthrough + default: res = append(res, NewText(func() string { // 这么处理应该没问题 if strings.Contains(elem.Text.GetStr(), "\r") && !strings.Contains(elem.Text.GetStr(), "\r\n") { @@ -400,11 +414,6 @@ func ParseMessageElems(elems []*msg.Elem) []IMessageElement { } return elem.Text.GetStr() }())) - } else { - att6 := binary.NewReader(elem.Text.Attr6Buf) - att6.ReadBytes(7) - target := int64(uint32(att6.ReadInt32())) - res = append(res, NewAt(target, elem.Text.GetStr())) } } if elem.RichMsg != nil {