diff --git a/client/message.go b/client/message.go index c1d6435d..f41e3979 100644 --- a/client/message.go +++ b/client/message.go @@ -68,12 +68,11 @@ func (c *QQClient) SendGroupMessage(groupUin uint32, elements []message2.IMessag GroupUin: groupUin, GroupName: group.GroupName, Sender: &message2.Sender{ - Uin: c.Uin, - UID: c.GetUID(c.Uin), - Nickname: c.NickName(), - CardName: minfo.MemberCard, - AnonymousInfo: nil, - IsFriend: true, + Uin: c.Uin, + UID: c.GetUID(c.Uin), + Nickname: c.NickName(), + CardName: minfo.MemberCard, + IsFriend: true, }, Time: ret.Timestamp1, Elements: elements, @@ -106,11 +105,10 @@ func (c *QQClient) SendPrivateMessage(uin uint32, elements []message2.IMessageEl Target: uin, Time: ret.Timestamp1, Sender: &message2.Sender{ - Uin: c.Uin, - UID: c.GetUID(c.Uin), - Nickname: c.NickName(), - AnonymousInfo: nil, - IsFriend: true, + Uin: c.Uin, + UID: c.GetUID(c.Uin), + Nickname: c.NickName(), + IsFriend: true, }, Elements: elements, } @@ -137,11 +135,10 @@ func (c *QQClient) SendTempMessage(groupUin uint32, uin uint32, elements []messa GroupName: group.GroupName, Self: c.Uin, Sender: &message2.Sender{ - Uin: c.Uin, - UID: c.GetUID(c.Uin), - Nickname: c.NickName(), - AnonymousInfo: nil, - IsFriend: true, + Uin: c.Uin, + UID: c.GetUID(c.Uin), + Nickname: c.NickName(), + IsFriend: true, }, Elements: elements, } @@ -159,7 +156,7 @@ func (c *QQClient) BuildFakeMessage(msgElems []*message2.ForwardNode) []*message FromUin: elem.SenderID, }, ContentHead: &message.ContentHead{ - Type: uint32(utils.Ternary(elem.GroupID != 0, 82, 9)), + Type: utils.Ternary[uint32](elem.GroupID != 0, 82, 9), MsgId: proto.Uint32(crypto.RandU32()), Sequence: proto.Uint32(crypto.RandU32()), TimeStamp: proto.Uint32(uint32(utils.TimeStamp())), @@ -169,7 +166,7 @@ func (c *QQClient) BuildFakeMessage(msgElems []*message2.ForwardNode) []*message Foward: &message.ForwardHead{ Field1: proto.Uint32(0), Field2: proto.Uint32(0), - Field3: utils.Ternary(elem.GroupID != 0, proto.Uint32(0), proto.Uint32(2)), + Field3: proto.Uint32(utils.Ternary[uint32](elem.GroupID != 0, 0, 2)), UnknownBase64: proto.String(avatar), Avatar: proto.String(avatar), }, diff --git a/client/operation.go b/client/operation.go index 4281d3f4..faef0863 100644 --- a/client/operation.go +++ b/client/operation.go @@ -477,6 +477,19 @@ func (c *QQClient) GetGroupRecordURL(groupUin uint32, node *oidb.IndexNode) (str return oidb2.ParseGroupRecordDownloadResp(resp) } +func (c *QQClient) GenFileNode(name, md5, sha1, uuid string, size uint32, isnt bool) *oidb.IndexNode { + return &oidb.IndexNode{ + Info: &oidb.FileInfo{ + FileName: name, + FileSize: size, + FileSha1: sha1, + FileHash: md5, + }, + FileUuid: uuid, + StoreId: utils.Ternary[uint32](isnt, 1, 0), // 0旧服务器 1为nt服务器 + } +} + // GetPrivateVideoURL 获取私聊视频下载链接 func (c *QQClient) GetPrivateVideoURL(node *oidb.IndexNode) (string, error) { pkt, err := oidb2.BuildPrivateVideoDownloadReq(c.Sig().UID, node) diff --git a/client/packets/message/multi_msg_upload.go b/client/packets/message/multi_msg_upload.go index 12782dc6..726ca2bf 100644 --- a/client/packets/message/multi_msg_upload.go +++ b/client/packets/message/multi_msg_upload.go @@ -24,7 +24,7 @@ func BuildMultiMsgUploadReq(selfUID string, groupUin uint32, msg []*message.Push Info: &message.SendLongMsgInfo{ Type: utils.Ternary[uint32](groupUin == 0, 1, 3), Uid: &message.LongMsgUid{ - Uid: utils.Ternary(groupUin == 0, proto.String(selfUID), proto.String(strconv.Itoa(int(groupUin)))), + Uid: proto.String(utils.Ternary(groupUin == 0, selfUID, strconv.Itoa(int(groupUin)))), }, GroupUin: proto.Uint32(groupUin), Payload: payload, diff --git a/message/build.go b/message/build.go index d1b43c56..04202f93 100644 --- a/message/build.go +++ b/message/build.go @@ -21,7 +21,7 @@ func (e *TextElement) BuildElement() []*message.Elem { func (e *AtElement) BuildElement() []*message.Elem { reserveData, _ := proto.Marshal(&message.MentionExtra{ - Type: proto.Some(int32(utils.Ternary(e.TargetUin == 0, 1, 2))), // atAll + Type: proto.Some(utils.Ternary[int32](e.TargetUin == 0, 1, 2)), // atAll Uin: proto.Some(uint32(0)), Field5: proto.Some(int32(0)), Uid: proto.Some(e.TargetUID), @@ -75,7 +75,7 @@ func (e *ImageElement) BuildElement() []*message.Elem { CommonElem: &message.CommonElem{ ServiceType: 48, PbElem: common, - BusinessType: utils.Ternary(e.IsGroup, uint32(20), uint32(10)), + BusinessType: utils.Ternary[uint32](e.IsGroup, 20, 10), }, }} if e.CompatFace != nil { diff --git a/message/message.go b/message/message.go index f6f57280..0ee1dffd 100644 --- a/message/message.go +++ b/message/message.go @@ -77,17 +77,11 @@ type ( } Sender struct { - Uin uint32 - UID string - Nickname string - CardName string - AnonymousInfo *AnonymousInfo - IsFriend bool - } - - AnonymousInfo struct { - AnonymousID string - AnonymousNick string + Uin uint32 + UID string + Nickname string + CardName string + IsFriend bool } IMessageElement interface { @@ -97,10 +91,6 @@ type ( ElementType int ) -func (s *Sender) IsAnonymous() bool { - return s.Uin == 80000000 -} - func ParsePrivateMessage(msg *message.PushMsgBody) *PrivateMessage { prvMsg := &PrivateMessage{ ID: msg.ContentHead.Sequence.Unwrap(), @@ -161,26 +151,24 @@ func ParseMessageElements(msg []*message.Elem) []IMessageElement { continue } if elem.SrcMsg != nil && len(elem.SrcMsg.OrigSeqs) != 0 { - r := &ReplyElement{ + res = append(res, &ReplyElement{ ReplySeq: elem.SrcMsg.OrigSeqs[0], Time: uint32(elem.SrcMsg.Time.Unwrap()), SenderUin: uint32(elem.SrcMsg.SenderUin), GroupUin: uint32(elem.SrcMsg.ToUin.Unwrap()), Elements: ParseMessageElements(elem.SrcMsg.Elems), - } - res = append(res, r) + }) } if elem.Text != nil { - switch { - case len(elem.Text.Attr6Buf) > 0: + if len(elem.Text.Attr6Buf) > 0 { att6 := binary.NewReader(elem.Text.Attr6Buf) att6.SkipBytes(7) target := att6.ReadU32() at := NewAt(target, elem.Text.Str.Unwrap()) at.SubType = AtTypeGroupMember res = append(res, at) - default: + } else { res = append(res, NewText(func() string { if strings.Contains(elem.Text.Str.Unwrap(), "\r") && !strings.Contains(elem.Text.Str.Unwrap(), "\r\n") { return strings.ReplaceAll(elem.Text.Str.Unwrap(), "\r", "\r\n") @@ -191,24 +179,25 @@ func ParseMessageElements(msg []*message.Elem) []IMessageElement { } if elem.Face != nil { - switch { - case len(elem.Face.Old) > 0: + if len(elem.Face.Old) > 0 { faceID := elem.Face.Index if faceID.IsSome() { res = append(res, &FaceElement{FaceID: uint32(faceID.Unwrap())}) } - case elem.CommonElem != nil && elem.CommonElem.ServiceType == 37 && elem.CommonElem.PbElem != nil: - qFace := message.QFaceExtra{} - if err := proto.Unmarshal(elem.CommonElem.PbElem, &qFace); err == nil { - if qFace.Qsid.IsSome() { - res = append(res, &FaceElement{FaceID: uint32(qFace.Qsid.Unwrap()), isLargeFace: true}) + } else if elem.CommonElem != nil && elem.CommonElem.PbElem != nil { + if elem.CommonElem.ServiceType == 37 { + qFace := message.QFaceExtra{} + if err := proto.Unmarshal(elem.CommonElem.PbElem, &qFace); err == nil { + if qFace.Qsid.IsSome() { + res = append(res, &FaceElement{FaceID: uint32(qFace.Qsid.Unwrap()), isLargeFace: true}) + } + } + } else if elem.CommonElem.ServiceType == 33 { + qFace := message.QSmallFaceExtra{} + err := proto.Unmarshal(elem.CommonElem.PbElem, &qFace) + if err == nil { + res = append(res, &FaceElement{FaceID: qFace.FaceId, isLargeFace: false}) } - } - case elem.CommonElem != nil && elem.CommonElem.ServiceType == 33 && elem.CommonElem.PbElem != nil: - qFace := message.QSmallFaceExtra{} - err := proto.Unmarshal(elem.CommonElem.PbElem, &qFace) - if err == nil { - res = append(res, &FaceElement{FaceID: qFace.FaceId, isLargeFace: false}) } } } @@ -328,7 +317,7 @@ func ParseMessageElements(msg []*message.Elem) []IMessageElement { }) case 11, 21: // video var thumb = new(VideoThumb) - if !(len(extra.MsgInfoBody) < 2) { + if len(extra.MsgInfoBody) > 1 { info := extra.MsgInfoBody[1].Index thumb.Size = info.Info.FileSize thumb.Width = info.Info.Width @@ -408,7 +397,7 @@ func ParseMessageElements(msg []*message.Elem) []IMessageElement { } else { res = append(res, &XMLElement{ ServiceID: 35, - Content: utils.B2S(binary.ZlibUncompress(elem.RichMsg.Template1[1:])), + Content: utils.B2S(xmlData), }) } } @@ -450,8 +439,7 @@ func ParseMessageBody(body *message.MessageBody, isGroup bool) []IMessageElement if body != nil { if body.RichText != nil && body.RichText.Ptt != nil { ptt := body.RichText.Ptt - switch { - case isGroup && ptt.FileId != 0: + if isGroup && ptt.FileId != 0 { res = append(res, &VoiceElement{ Name: ptt.FileName, UUID: ptt.FileUuid, @@ -460,7 +448,7 @@ func ParseMessageBody(body *message.MessageBody, isGroup bool) []IMessageElement FileUuid: ptt.GroupFileKey, }, }) - case !isGroup: + } else if !isGroup { res = append(res, &VoiceElement{ Name: ptt.FileName, UUID: ptt.FileUuid, @@ -654,11 +642,9 @@ func PackElementsToBody(msgElems []IMessageElement) (msgBody *message.MessageBod RichText: &message.RichText{Elems: PackElements(msgElems)}, } for _, elem := range msgElems { - bd, ok := elem.(MsgContentBuilder) - if !ok { - continue + if bd, ok := elem.(MsgContentBuilder); ok { + msgBody.MsgContent = bd.BuildContent() } - msgBody.MsgContent = bd.BuildContent() } return } @@ -669,11 +655,9 @@ func PackElements(msgElems []IMessageElement) []*message.Elem { } elems := make([]*message.Elem, 0, len(msgElems)) for _, elem := range msgElems { - bd, ok := elem.(ElementBuilder) - if !ok { - continue + if bd, ok := elem.(ElementBuilder); ok { + elems = append(elems, bd.BuildElement()...) } - elems = append(elems, bd.BuildElement()...) } return elems }