diff --git a/client/client.go b/client/client.go index 13f7efcb..fdb34ed6 100644 --- a/client/client.go +++ b/client/client.go @@ -152,6 +152,7 @@ func NewClientMd5(uin int64, passwordMd5 [16]byte) *QQClient { "SummaryCard.ReqSummaryCard": decodeSummaryCardResponse, "PttCenterSvr.ShortVideoDownReq": decodePttShortVideoDownResponse, "LightAppSvc.mini_app_info.GetAppInfoById": decodeAppInfoResponse, + "OidbSvc.0x990": decodeTranslateResponse, }, sigInfo: &loginSigInfo{}, requestPacketRequestId: 1921334513, diff --git a/client/pb/oidb/oidb0x990.pb.go b/client/pb/oidb/oidb0x990.pb.go new file mode 100644 index 00000000..1d0391b1 --- /dev/null +++ b/client/pb/oidb/oidb0x990.pb.go @@ -0,0 +1,417 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.25.0 +// protoc v3.13.0 +// source: oidb0x990.proto + +package oidb + +import ( + proto "github.com/golang/protobuf/proto" + 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) +) + +// This is a compile-time assertion that a sufficiently up-to-date version +// of the legacy proto package is being used. +const _ = proto.ProtoPackageIsVersion4 + +type TranslateReqBody struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // TranslateReq translate_req = 1; + BatchTranslateReq *BatchTranslateReq `protobuf:"bytes,2,opt,name=batch_translate_req,json=batchTranslateReq,proto3" json:"batch_translate_req,omitempty"` +} + +func (x *TranslateReqBody) Reset() { + *x = TranslateReqBody{} + if protoimpl.UnsafeEnabled { + mi := &file_oidb0x990_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TranslateReqBody) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TranslateReqBody) ProtoMessage() {} + +func (x *TranslateReqBody) ProtoReflect() protoreflect.Message { + mi := &file_oidb0x990_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 TranslateReqBody.ProtoReflect.Descriptor instead. +func (*TranslateReqBody) Descriptor() ([]byte, []int) { + return file_oidb0x990_proto_rawDescGZIP(), []int{0} +} + +func (x *TranslateReqBody) GetBatchTranslateReq() *BatchTranslateReq { + if x != nil { + return x.BatchTranslateReq + } + return nil +} + +type TranslateRspBody struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // TranslateRsp translate_rsp = 1; + BatchTranslateRsp *BatchTranslateRsp `protobuf:"bytes,2,opt,name=batch_translate_rsp,json=batchTranslateRsp,proto3" json:"batch_translate_rsp,omitempty"` +} + +func (x *TranslateRspBody) Reset() { + *x = TranslateRspBody{} + if protoimpl.UnsafeEnabled { + mi := &file_oidb0x990_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TranslateRspBody) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TranslateRspBody) ProtoMessage() {} + +func (x *TranslateRspBody) ProtoReflect() protoreflect.Message { + mi := &file_oidb0x990_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 TranslateRspBody.ProtoReflect.Descriptor instead. +func (*TranslateRspBody) Descriptor() ([]byte, []int) { + return file_oidb0x990_proto_rawDescGZIP(), []int{1} +} + +func (x *TranslateRspBody) GetBatchTranslateRsp() *BatchTranslateRsp { + if x != nil { + return x.BatchTranslateRsp + } + return nil +} + +type BatchTranslateReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + SrcLanguage string `protobuf:"bytes,1,opt,name=src_language,json=srcLanguage,proto3" json:"src_language,omitempty"` + DstLanguage string `protobuf:"bytes,2,opt,name=dst_language,json=dstLanguage,proto3" json:"dst_language,omitempty"` + SrcTextList []string `protobuf:"bytes,3,rep,name=src_text_list,json=srcTextList,proto3" json:"src_text_list,omitempty"` +} + +func (x *BatchTranslateReq) Reset() { + *x = BatchTranslateReq{} + if protoimpl.UnsafeEnabled { + mi := &file_oidb0x990_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BatchTranslateReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BatchTranslateReq) ProtoMessage() {} + +func (x *BatchTranslateReq) ProtoReflect() protoreflect.Message { + mi := &file_oidb0x990_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 BatchTranslateReq.ProtoReflect.Descriptor instead. +func (*BatchTranslateReq) Descriptor() ([]byte, []int) { + return file_oidb0x990_proto_rawDescGZIP(), []int{2} +} + +func (x *BatchTranslateReq) GetSrcLanguage() string { + if x != nil { + return x.SrcLanguage + } + return "" +} + +func (x *BatchTranslateReq) GetDstLanguage() string { + if x != nil { + return x.DstLanguage + } + return "" +} + +func (x *BatchTranslateReq) GetSrcTextList() []string { + if x != nil { + return x.SrcTextList + } + return nil +} + +type BatchTranslateRsp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ErrorCode int32 `protobuf:"varint,1,opt,name=error_code,json=errorCode,proto3" json:"error_code,omitempty"` + ErrorMsg []byte `protobuf:"bytes,2,opt,name=error_msg,json=errorMsg,proto3" json:"error_msg,omitempty"` + SrcLanguage string `protobuf:"bytes,3,opt,name=src_language,json=srcLanguage,proto3" json:"src_language,omitempty"` + DstLanguage string `protobuf:"bytes,4,opt,name=dst_language,json=dstLanguage,proto3" json:"dst_language,omitempty"` + SrcTextList []string `protobuf:"bytes,5,rep,name=src_text_list,json=srcTextList,proto3" json:"src_text_list,omitempty"` + DstTextList []string `protobuf:"bytes,6,rep,name=dst_text_list,json=dstTextList,proto3" json:"dst_text_list,omitempty"` +} + +func (x *BatchTranslateRsp) Reset() { + *x = BatchTranslateRsp{} + if protoimpl.UnsafeEnabled { + mi := &file_oidb0x990_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BatchTranslateRsp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BatchTranslateRsp) ProtoMessage() {} + +func (x *BatchTranslateRsp) ProtoReflect() protoreflect.Message { + mi := &file_oidb0x990_proto_msgTypes[3] + 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 BatchTranslateRsp.ProtoReflect.Descriptor instead. +func (*BatchTranslateRsp) Descriptor() ([]byte, []int) { + return file_oidb0x990_proto_rawDescGZIP(), []int{3} +} + +func (x *BatchTranslateRsp) GetErrorCode() int32 { + if x != nil { + return x.ErrorCode + } + return 0 +} + +func (x *BatchTranslateRsp) GetErrorMsg() []byte { + if x != nil { + return x.ErrorMsg + } + return nil +} + +func (x *BatchTranslateRsp) GetSrcLanguage() string { + if x != nil { + return x.SrcLanguage + } + return "" +} + +func (x *BatchTranslateRsp) GetDstLanguage() string { + if x != nil { + return x.DstLanguage + } + return "" +} + +func (x *BatchTranslateRsp) GetSrcTextList() []string { + if x != nil { + return x.SrcTextList + } + return nil +} + +func (x *BatchTranslateRsp) GetDstTextList() []string { + if x != nil { + return x.DstTextList + } + return nil +} + +var File_oidb0x990_proto protoreflect.FileDescriptor + +var file_oidb0x990_proto_rawDesc = []byte{ + 0x0a, 0x0f, 0x6f, 0x69, 0x64, 0x62, 0x30, 0x78, 0x39, 0x39, 0x30, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x22, 0x56, 0x0a, 0x10, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x6c, 0x61, 0x74, 0x65, 0x52, 0x65, + 0x71, 0x42, 0x6f, 0x64, 0x79, 0x12, 0x42, 0x0a, 0x13, 0x62, 0x61, 0x74, 0x63, 0x68, 0x5f, 0x74, + 0x72, 0x61, 0x6e, 0x73, 0x6c, 0x61, 0x74, 0x65, 0x5f, 0x72, 0x65, 0x71, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x42, 0x61, 0x74, 0x63, 0x68, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x6c, + 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x52, 0x11, 0x62, 0x61, 0x74, 0x63, 0x68, 0x54, 0x72, 0x61, + 0x6e, 0x73, 0x6c, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x22, 0x56, 0x0a, 0x10, 0x54, 0x72, 0x61, + 0x6e, 0x73, 0x6c, 0x61, 0x74, 0x65, 0x52, 0x73, 0x70, 0x42, 0x6f, 0x64, 0x79, 0x12, 0x42, 0x0a, + 0x13, 0x62, 0x61, 0x74, 0x63, 0x68, 0x5f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x6c, 0x61, 0x74, 0x65, + 0x5f, 0x72, 0x73, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x42, 0x61, 0x74, + 0x63, 0x68, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x6c, 0x61, 0x74, 0x65, 0x52, 0x73, 0x70, 0x52, 0x11, + 0x62, 0x61, 0x74, 0x63, 0x68, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x6c, 0x61, 0x74, 0x65, 0x52, 0x73, + 0x70, 0x22, 0x7d, 0x0a, 0x11, 0x42, 0x61, 0x74, 0x63, 0x68, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x6c, + 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x12, 0x21, 0x0a, 0x0c, 0x73, 0x72, 0x63, 0x5f, 0x6c, 0x61, + 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x72, + 0x63, 0x4c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x64, 0x73, 0x74, + 0x5f, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x64, 0x73, 0x74, 0x4c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x12, 0x22, 0x0a, 0x0d, + 0x73, 0x72, 0x63, 0x5f, 0x74, 0x65, 0x78, 0x74, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x18, 0x03, 0x20, + 0x03, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x72, 0x63, 0x54, 0x65, 0x78, 0x74, 0x4c, 0x69, 0x73, 0x74, + 0x22, 0xdd, 0x01, 0x0a, 0x11, 0x42, 0x61, 0x74, 0x63, 0x68, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x6c, + 0x61, 0x74, 0x65, 0x52, 0x73, 0x70, 0x12, 0x1d, 0x0a, 0x0a, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x5f, + 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x65, 0x72, 0x72, 0x6f, + 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x5f, 0x6d, + 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x4d, + 0x73, 0x67, 0x12, 0x21, 0x0a, 0x0c, 0x73, 0x72, 0x63, 0x5f, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, + 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x72, 0x63, 0x4c, 0x61, 0x6e, + 0x67, 0x75, 0x61, 0x67, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x64, 0x73, 0x74, 0x5f, 0x6c, 0x61, 0x6e, + 0x67, 0x75, 0x61, 0x67, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x73, 0x74, + 0x4c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x12, 0x22, 0x0a, 0x0d, 0x73, 0x72, 0x63, 0x5f, + 0x74, 0x65, 0x78, 0x74, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x18, 0x05, 0x20, 0x03, 0x28, 0x09, 0x52, + 0x0b, 0x73, 0x72, 0x63, 0x54, 0x65, 0x78, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x22, 0x0a, 0x0d, + 0x64, 0x73, 0x74, 0x5f, 0x74, 0x65, 0x78, 0x74, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x18, 0x06, 0x20, + 0x03, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x73, 0x74, 0x54, 0x65, 0x78, 0x74, 0x4c, 0x69, 0x73, 0x74, + 0x42, 0x08, 0x5a, 0x06, 0x2e, 0x3b, 0x6f, 0x69, 0x64, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, +} + +var ( + file_oidb0x990_proto_rawDescOnce sync.Once + file_oidb0x990_proto_rawDescData = file_oidb0x990_proto_rawDesc +) + +func file_oidb0x990_proto_rawDescGZIP() []byte { + file_oidb0x990_proto_rawDescOnce.Do(func() { + file_oidb0x990_proto_rawDescData = protoimpl.X.CompressGZIP(file_oidb0x990_proto_rawDescData) + }) + return file_oidb0x990_proto_rawDescData +} + +var file_oidb0x990_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_oidb0x990_proto_goTypes = []interface{}{ + (*TranslateReqBody)(nil), // 0: TranslateReqBody + (*TranslateRspBody)(nil), // 1: TranslateRspBody + (*BatchTranslateReq)(nil), // 2: BatchTranslateReq + (*BatchTranslateRsp)(nil), // 3: BatchTranslateRsp +} +var file_oidb0x990_proto_depIdxs = []int32{ + 2, // 0: TranslateReqBody.batch_translate_req:type_name -> BatchTranslateReq + 3, // 1: TranslateRspBody.batch_translate_rsp:type_name -> BatchTranslateRsp + 2, // [2:2] is the sub-list for method output_type + 2, // [2:2] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name +} + +func init() { file_oidb0x990_proto_init() } +func file_oidb0x990_proto_init() { + if File_oidb0x990_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_oidb0x990_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TranslateReqBody); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_oidb0x990_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TranslateRspBody); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_oidb0x990_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BatchTranslateReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_oidb0x990_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BatchTranslateRsp); 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_oidb0x990_proto_rawDesc, + NumEnums: 0, + NumMessages: 4, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_oidb0x990_proto_goTypes, + DependencyIndexes: file_oidb0x990_proto_depIdxs, + MessageInfos: file_oidb0x990_proto_msgTypes, + }.Build() + File_oidb0x990_proto = out.File + file_oidb0x990_proto_rawDesc = nil + file_oidb0x990_proto_goTypes = nil + file_oidb0x990_proto_depIdxs = nil +} diff --git a/client/pb/oidb/oidb0x990.proto b/client/pb/oidb/oidb0x990.proto new file mode 100644 index 00000000..4010d862 --- /dev/null +++ b/client/pb/oidb/oidb0x990.proto @@ -0,0 +1,28 @@ +syntax = "proto3"; + +option go_package = ".;oidb"; + +message TranslateReqBody { + // TranslateReq translate_req = 1; + BatchTranslateReq batch_translate_req = 2; +} + +message TranslateRspBody { + // TranslateRsp translate_rsp = 1; + BatchTranslateRsp batch_translate_rsp = 2; +} + +message BatchTranslateReq { + string src_language = 1; + string dst_language = 2; + repeated string src_text_list = 3; +} + +message BatchTranslateRsp { + int32 error_code = 1; + bytes error_msg = 2; + string src_language = 3; + string dst_language = 4; + repeated string src_text_list = 5; + repeated string dst_text_list = 6; +} \ No newline at end of file diff --git a/client/translate.go b/client/translate.go new file mode 100644 index 00000000..cd0e8c32 --- /dev/null +++ b/client/translate.go @@ -0,0 +1,55 @@ +package client + +import ( + "errors" + "github.com/Mrs4s/MiraiGo/client/pb/oidb" + "github.com/Mrs4s/MiraiGo/protocol/packets" + "github.com/golang/protobuf/proto" +) + +func (c *QQClient)buildTranslatePacket(src, dst, text string) (uint16, []byte) { + seq := c.nextSeq() + body := &oidb.TranslateReqBody{ + BatchTranslateReq: &oidb.BatchTranslateReq{ + SrcLanguage: src, + DstLanguage: dst, + SrcTextList: []string{text}, + }, + } + b, _ := proto.Marshal(body) + req := &oidb.OIDBSSOPkg{ + Command: 2448, + ServiceType: 2, + Bodybuffer: b, + } + payload, _ := proto.Marshal(req) + packet := packets.BuildUniPacket(c.Uin, seq, "OidbSvc.0x990", 1, c.OutGoingPacketSessionId, EmptyBytes, c.sigInfo.d2Key, payload) + return seq, packet +} + +func (c *QQClient)Translate(src, dst, text string) (string, error) { + rsp, err := c.sendAndWait(c.buildTranslatePacket(src, dst, text)) + if err != nil { + return "",err + } + if data, ok := rsp.(*oidb.BatchTranslateRsp); ok { + if data.ErrorCode != 0{ + return "", errors.New(string(data.ErrorMsg)) + } + return data.DstTextList[0], nil + } + return "", errors.New("decode error") +} + +// OidbSvc.0x990 +func decodeTranslateResponse(c *QQClient, _ uint16, payload []byte) (interface{}, error) { + pkg := oidb.OIDBSSOPkg{} + rsp := oidb.TranslateRspBody{} + if err := proto.Unmarshal(payload, &pkg); err != nil { + return nil, err + } + if err := proto.Unmarshal(pkg.Bodybuffer, &rsp); err != nil { + return nil, err + } + return rsp.BatchTranslateRsp, nil +}