From 517ddcd50b8d4c66d5645556df51ce50830956cf Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Sat, 17 Oct 2020 16:37:49 +0800 Subject: [PATCH] feature: private recall. --- client/builders.go | 24 ---------- client/client.go | 5 --- client/pb/msg/msg.pb.go | 97 ++++++++++++++++++++++++++++++++++++++--- client/pb/msg/msg.proto | 6 +++ client/ptt.go | 4 ++ client/recall.go | 66 ++++++++++++++++++++++++++++ 6 files changed, 166 insertions(+), 36 deletions(-) create mode 100644 client/recall.go diff --git a/client/builders.go b/client/builders.go index 09408ed6..8c67849a 100644 --- a/client/builders.go +++ b/client/builders.go @@ -888,30 +888,6 @@ func (c *QQClient) buildSystemMsgFriendActionPacket(reqId, requester int64, acce return seq, packet } -// PbMessageSvc.PbMsgWithDraw -func (c *QQClient) buildGroupRecallPacket(groupCode int64, msgSeq, msgRan int32) (uint16, []byte) { - seq := c.nextSeq() - req := &msg.MsgWithDrawReq{ - GroupWithDraw: []*msg.GroupMsgWithDrawReq{ - { - SubCmd: 1, - GroupCode: groupCode, - MsgList: []*msg.GroupMsgInfo{ - { - MsgSeq: msgSeq, - MsgRandom: msgRan, - MsgType: 0, - }, - }, - UserDef: []byte{0x08, 0x00}, - }, - }, - } - payload, _ := proto.Marshal(req) - packet := packets.BuildUniPacket(c.Uin, seq, "PbMessageSvc.PbMsgWithDraw", 1, c.OutGoingPacketSessionId, EmptyBytes, c.sigInfo.d2Key, payload) - return seq, packet -} - // friendlist.ModifyGroupCardReq func (c *QQClient) buildEditGroupTagPacket(groupCode, memberUin int64, newTag string) (uint16, []byte) { seq := c.nextSeq() diff --git a/client/client.go b/client/client.go index 47f77368..6e5f00b6 100644 --- a/client/client.go +++ b/client/client.go @@ -621,11 +621,6 @@ func (c *QQClient) sendGroupPoke(groupCode, target int64) { _, _ = c.sendAndWait(c.buildGroupPokePacket(groupCode, target)) } -func (c *QQClient) RecallGroupMessage(groupCode int64, msgId, msgInternalId int32) { - _, pkt := c.buildGroupRecallPacket(groupCode, msgId, msgInternalId) - _ = c.send(pkt) -} - func (c *QQClient) UploadGroupImage(groupCode int64, img []byte) (*message.GroupImageElement, error) { h := md5.Sum(img) seq, pkt := c.buildGroupImageStorePacket(groupCode, h[:], int32(len(img))) diff --git a/client/pb/msg/msg.pb.go b/client/pb/msg/msg.pb.go index cfef92dd..0c1e58de 100644 --- a/client/pb/msg/msg.pb.go +++ b/client/pb/msg/msg.pb.go @@ -6238,6 +6238,69 @@ func (x *AnimationImageShow) GetAnimationParam() []byte { return nil } +type UinTypeUserDef struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + FromUinType int32 `protobuf:"varint,1,opt,name=fromUinType,proto3" json:"fromUinType,omitempty"` + FromGroupCode int64 `protobuf:"varint,2,opt,name=fromGroupCode,proto3" json:"fromGroupCode,omitempty"` + FileUuid string `protobuf:"bytes,3,opt,name=fileUuid,proto3" json:"fileUuid,omitempty"` +} + +func (x *UinTypeUserDef) Reset() { + *x = UinTypeUserDef{} + if protoimpl.UnsafeEnabled { + mi := &file_msg_proto_msgTypes[60] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UinTypeUserDef) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UinTypeUserDef) ProtoMessage() {} + +func (x *UinTypeUserDef) ProtoReflect() protoreflect.Message { + mi := &file_msg_proto_msgTypes[60] + 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 UinTypeUserDef.ProtoReflect.Descriptor instead. +func (*UinTypeUserDef) Descriptor() ([]byte, []int) { + return file_msg_proto_rawDescGZIP(), []int{60} +} + +func (x *UinTypeUserDef) GetFromUinType() int32 { + if x != nil { + return x.FromUinType + } + return 0 +} + +func (x *UinTypeUserDef) GetFromGroupCode() int64 { + if x != nil { + return x.FromGroupCode + } + return 0 +} + +func (x *UinTypeUserDef) GetFileUuid() string { + if x != nil { + return x.FileUuid + } + return "" +} + var File_msg_proto protoreflect.FileDescriptor var file_msg_proto_rawDesc = []byte{ @@ -7218,11 +7281,18 @@ var file_msg_proto_rawDesc = []byte{ 0x65, 0x66, 0x66, 0x65, 0x63, 0x74, 0x49, 0x64, 0x12, 0x27, 0x0a, 0x0f, 0x61, 0x6e, 0x69, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0e, 0x61, 0x6e, 0x69, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x50, 0x61, 0x72, 0x61, - 0x6d, 0x2a, 0x2e, 0x0a, 0x08, 0x53, 0x79, 0x6e, 0x63, 0x46, 0x6c, 0x61, 0x67, 0x12, 0x09, 0x0a, - 0x05, 0x53, 0x54, 0x41, 0x52, 0x54, 0x10, 0x00, 0x12, 0x0d, 0x0a, 0x09, 0x43, 0x4f, 0x4e, 0x54, - 0x49, 0x4e, 0x55, 0x4d, 0x45, 0x10, 0x01, 0x12, 0x08, 0x0a, 0x04, 0x53, 0x54, 0x4f, 0x50, 0x10, - 0x02, 0x42, 0x07, 0x5a, 0x05, 0x2e, 0x3b, 0x6d, 0x73, 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, + 0x6d, 0x22, 0x74, 0x0a, 0x0e, 0x55, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x55, 0x73, 0x65, 0x72, + 0x44, 0x65, 0x66, 0x12, 0x20, 0x0a, 0x0b, 0x66, 0x72, 0x6f, 0x6d, 0x55, 0x69, 0x6e, 0x54, 0x79, + 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0b, 0x66, 0x72, 0x6f, 0x6d, 0x55, 0x69, + 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x66, 0x72, 0x6f, 0x6d, 0x47, 0x72, 0x6f, + 0x75, 0x70, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0d, 0x66, 0x72, + 0x6f, 0x6d, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x66, + 0x69, 0x6c, 0x65, 0x55, 0x75, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x66, + 0x69, 0x6c, 0x65, 0x55, 0x75, 0x69, 0x64, 0x2a, 0x2e, 0x0a, 0x08, 0x53, 0x79, 0x6e, 0x63, 0x46, + 0x6c, 0x61, 0x67, 0x12, 0x09, 0x0a, 0x05, 0x53, 0x54, 0x41, 0x52, 0x54, 0x10, 0x00, 0x12, 0x0d, + 0x0a, 0x09, 0x43, 0x4f, 0x4e, 0x54, 0x49, 0x4e, 0x55, 0x4d, 0x45, 0x10, 0x01, 0x12, 0x08, 0x0a, + 0x04, 0x53, 0x54, 0x4f, 0x50, 0x10, 0x02, 0x42, 0x07, 0x5a, 0x05, 0x2e, 0x3b, 0x6d, 0x73, 0x67, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -7238,7 +7308,7 @@ func file_msg_proto_rawDescGZIP() []byte { } var file_msg_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 60) +var file_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 61) var file_msg_proto_goTypes = []interface{}{ (SyncFlag)(0), // 0: SyncFlag (*GetMessageRequest)(nil), // 1: GetMessageRequest @@ -7301,6 +7371,7 @@ var file_msg_proto_goTypes = []interface{}{ (*SubMsgType0X4Body)(nil), // 58: SubMsgType0x4Body (*ResvAttr)(nil), // 59: ResvAttr (*AnimationImageShow)(nil), // 60: AnimationImageShow + (*UinTypeUserDef)(nil), // 61: UinTypeUserDef } var file_msg_proto_depIdxs = []int32{ 0, // 0: GetMessageRequest.syncFlag:type_name -> SyncFlag @@ -8099,6 +8170,18 @@ func file_msg_proto_init() { return nil } } + file_msg_proto_msgTypes[60].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UinTypeUserDef); 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{ @@ -8106,7 +8189,7 @@ func file_msg_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_msg_proto_rawDesc, NumEnums: 1, - NumMessages: 60, + NumMessages: 61, NumExtensions: 0, NumServices: 0, }, diff --git a/client/pb/msg/msg.proto b/client/pb/msg/msg.proto index af8b47a2..930ff94c 100644 --- a/client/pb/msg/msg.proto +++ b/client/pb/msg/msg.proto @@ -723,4 +723,10 @@ message ResvAttr { message AnimationImageShow { int32 effect_id = 1; bytes animation_param = 2; +} + +message UinTypeUserDef { + int32 fromUinType = 1; + int64 fromGroupCode = 2; + string fileUuid = 3; } \ No newline at end of file diff --git a/client/ptt.go b/client/ptt.go index 14cad165..52038ae6 100644 --- a/client/ptt.go +++ b/client/ptt.go @@ -14,6 +14,9 @@ import ( "google.golang.org/protobuf/proto" ) +// 语音相关处理逻辑 + +// UploadGroupPtt 将语音数据使用群语音通道上传到服务器, 返回 message.GroupVoiceElement 可直接发送 func (c *QQClient) UploadGroupPtt(groupCode int64, voice []byte) (*message.GroupVoiceElement, error) { h := md5.Sum(voice) seq, pkt := c.buildGroupPttStorePacket(groupCode, h[:], int32(len(voice)), 0, int32(len(voice))) @@ -50,6 +53,7 @@ ok: }}, nil } +// UploadPrivatePtt 将语音数据使用好友语音通道上传到服务器, 返回 message.PrivateVoiceElement 可直接发送 func (c *QQClient) UploadPrivatePtt(target int64, voice []byte) (*message.PrivateVoiceElement, error) { h := md5.Sum(voice) i, err := c.sendAndWait(c.buildPrivatePttStorePacket(target, h[:], int32(len(voice)), int32(len(voice)))) diff --git a/client/recall.go b/client/recall.go new file mode 100644 index 00000000..f4f4602c --- /dev/null +++ b/client/recall.go @@ -0,0 +1,66 @@ +package client + +import ( + "github.com/Mrs4s/MiraiGo/client/pb/msg" + "github.com/Mrs4s/MiraiGo/protocol/packets" + "google.golang.org/protobuf/proto" +) + +// 撤回相关处理逻辑 + +func (c *QQClient) RecallGroupMessage(groupCode int64, msgId, msgInternalId int32) { + _, pkt := c.buildGroupRecallPacket(groupCode, msgId, msgInternalId) + _ = c.send(pkt) +} + +func (c *QQClient) RecallPrivateMessage(uin, ts int64, msgId, msgInternalId int32) { + _, pkt := c.buildPrivateRecallPacket(uin, ts, msgId, msgInternalId) + _ = c.send(pkt) +} + +// PbMessageSvc.PbMsgWithDraw +func (c *QQClient) buildGroupRecallPacket(groupCode int64, msgSeq, msgRan int32) (uint16, []byte) { + seq := c.nextSeq() + req := &msg.MsgWithDrawReq{ + GroupWithDraw: []*msg.GroupMsgWithDrawReq{ + { + SubCmd: 1, + GroupCode: groupCode, + MsgList: []*msg.GroupMsgInfo{ + { + MsgSeq: msgSeq, + MsgRandom: msgRan, + MsgType: 0, + }, + }, + UserDef: []byte{0x08, 0x00}, + }, + }, + } + payload, _ := proto.Marshal(req) + packet := packets.BuildUniPacket(c.Uin, seq, "PbMessageSvc.PbMsgWithDraw", 1, c.OutGoingPacketSessionId, EmptyBytes, c.sigInfo.d2Key, payload) + return seq, packet +} + +func (c *QQClient) buildPrivateRecallPacket(uin, ts int64, msgSeq, random int32) (uint16, []byte) { + seq := c.nextSeq() + req := &msg.MsgWithDrawReq{C2CWithDraw: []*msg.C2CMsgWithDrawReq{ + { + MsgInfo: []*msg.C2CMsgInfo{ + { + FromUin: c.Uin, + ToUin: uin, + MsgTime: ts, + MsgUid: int64(random), + MsgSeq: msgSeq, + MsgRandom: random, + }, + }, + Reserved: []byte{0x08, 0x00}, + SubCmd: 1, + }, + }} + payload, _ := proto.Marshal(req) + packet := packets.BuildUniPacket(c.Uin, seq, "PbMessageSvc.PbMsgWithDraw", 1, c.OutGoingPacketSessionId, EmptyBytes, c.sigInfo.d2Key, payload) + return seq, packet +}