diff --git a/client/highway.go b/client/highway.go index 9cd9931a..8f609729 100644 --- a/client/highway.go +++ b/client/highway.go @@ -65,12 +65,14 @@ func (c *QQClient) UploadSrcByStreamAsync(commonId int, stream io.ReadSeeker, ti // Get server URL _, server := c.GetServiceServer() if server == nil { + fmt.Println("Failed to get server") return false } success := true var upBlocks []UpBlock data, err := io.ReadAll(stream) if err != nil { + fmt.Println("Failed to read stream") return false } @@ -78,6 +80,7 @@ func (c *QQClient) UploadSrcByStreamAsync(commonId int, stream io.ReadSeeker, ti offset := uint64(0) _, err = stream.Seek(0, io.SeekStart) if err != nil { + fmt.Println("Failed to seek stream") return false } @@ -91,6 +94,7 @@ func (c *QQClient) UploadSrcByStreamAsync(commonId int, stream io.ReadSeeker, ti buffer := make([]byte, buffersize) payload, err := io.ReadFull(stream, buffer) if err != nil { + fmt.Println("Failed to read stream") return false } reqBody := UpBlock{ @@ -111,6 +115,10 @@ func (c *QQClient) UploadSrcByStreamAsync(commonId int, stream io.ReadSeeker, ti if len(upBlocks) >= 4 || offset == fileSize { for _, block := range upBlocks { success = success && c.SendUpBlockAsync(block, server[1][0]) + if !success { + fmt.Println("Failed to send block") + return false + } } upBlocks = nil } @@ -154,10 +162,12 @@ func (c *QQClient) SendUpBlockAsync(block UpBlock, server string) bool { packet.WriteBytes(block.Block, false) payload, err := SendPacketAsync(highwayHead, packet, server, isEnd) if err != nil { + fmt.Println("Failed to send packet ", err) return false } resphead, respbody, err := ParsePacket(payload) if err != nil { + fmt.Println("Failed to parse packet ", err) return false } networkLogger.Infof("Highway Block Result: %d | %d | %x | %v", resphead.ErrorCode, resphead.MsgSegHead.RetCode, resphead.BytesRspExtendInfo, respbody) @@ -169,14 +179,14 @@ func ParsePacket(data []byte) (head *highway.RespDataHighwayHead, body *binary.R if reader.ReadBytes(1)[0] == 0x28 { headlength := reader.ReadU32() bodylength := reader.ReadU32() - err = proto.Unmarshal(reader.ReadBytes(int(headlength)), &head) - if err != nil { - return nil, nil, err - } - err = proto.Unmarshal(reader.ReadBytes(int(bodylength)), body) + head = &highway.RespDataHighwayHead{} + headraw := reader.ReadBytes(int(int64(headlength))) + fmt.Println("headraw", headraw) + err = proto.Unmarshal(headraw, head) if err != nil { return nil, nil, err } + body = binary.NewReader(reader.ReadBytes(int(bodylength))) if reader.ReadBytes(1)[0] == 0x29 { return head, body, nil } diff --git a/client/message.go b/client/message.go index 82a6724d..7cfa6812 100644 --- a/client/message.go +++ b/client/message.go @@ -1,6 +1,7 @@ package client import ( + "fmt" message2 "github.com/LagrangeDev/LagrangeGo/message" "github.com/LagrangeDev/LagrangeGo/packets/pb/action" "github.com/LagrangeDev/LagrangeGo/packets/pb/message" @@ -35,6 +36,7 @@ func (c *QQClient) SendRawMessage(route *message.RoutingHead, body *message.Mess if err != nil { return } + resp = &action.SendMessageResponse{} err = proto.Unmarshal(packet.Data, resp) if err != nil { return @@ -85,6 +87,16 @@ func preprocessMessage(client *QQClient, groupUin uint32, elements []message2.IM elem.Display = "@" + member.MemberName } } + case *message2.GroupImageElement: + _, err := client.ImageUploadGroup(groupUin, elem) + if err != nil { + fmt.Println(err) + } + if elem.MsgInfo == nil { + fmt.Println("ImageUploadGroup failed") + continue + } + fmt.Println("Image MsgInfo: ", elem.MsgInfo) default: } } diff --git a/message/elements.go b/message/elements.go index 6f8764f0..e4981f7d 100644 --- a/message/elements.go +++ b/message/elements.go @@ -1,6 +1,7 @@ package message import ( + "fmt" "strconv" "github.com/LagrangeDev/LagrangeGo/packets/pb/message" @@ -108,11 +109,11 @@ func (e *ShortVideoElement) Type() ElementType { return Video } -func (e *TextElement) BuildElement() *message.Elem { - return &message.Elem{Text: &message.Text{Str: proto.Some(e.Content)}} +func (e *TextElement) BuildElement() []*message.Elem { + return []*message.Elem{{Text: &message.Text{Str: proto.Some(e.Content)}}} } -func (e *AtElement) BuildElement() *message.Elem { +func (e *AtElement) BuildElement() []*message.Elem { var atAll int32 = 2 if e.Target == 0 { atAll = 1 @@ -124,13 +125,13 @@ func (e *AtElement) BuildElement() *message.Elem { Uid: proto.Some(e.UID), } reserveData, _ := proto.Marshal(&reserve) - return &message.Elem{Text: &message.Text{ + return []*message.Elem{{Text: &message.Text{ Str: proto.Some(e.Display), PbReserve: reserveData, - }} + }}} } -func (e *FaceElement) BuildElement() *message.Elem { +func (e *FaceElement) BuildElement() []*message.Elem { faceId := int32(e.FaceID) if e.isLargeFace { qFace := message.QFaceExtra{ @@ -144,36 +145,48 @@ func (e *FaceElement) BuildElement() *message.Elem { Field9: proto.Some(int32(1)), } qFaceData, _ := proto.Marshal(&qFace) - return &message.Elem{ + return []*message.Elem{{ CommonElem: &message.CommonElem{ ServiceType: 37, PbElem: qFaceData, BusinessType: 1, }, - } + }} } else { - return &message.Elem{ + return []*message.Elem{{ Face: &message.Face{Index: proto.Some(faceId)}, - } + }} } } -func (e *GroupImageElement) BuildElement() *message.Elem { - return nil +func (e *GroupImageElement) BuildElement() []*message.Elem { + common, err := proto.Marshal(e.MsgInfo) + if err != nil { + fmt.Println("ImageBuild Common Proto Marshall failed:", err) + return nil + } + msg := []*message.Elem{{ + CommonElem: &message.CommonElem{ + ServiceType: 48, + PbElem: common, + BusinessType: 10, + }, + }} + return msg } -func (e *FriendImageElement) BuildElement() *message.Elem { +func (e *FriendImageElement) BuildElement() []*message.Elem { return nil } -func (e *ReplyElement) BuildElement() *message.Elem { +func (e *ReplyElement) BuildElement() []*message.Elem { return nil } -func (e *VoiceElement) BuildElement() *message.Elem { +func (e *VoiceElement) BuildElement() []*message.Elem { return nil } -func (e *ShortVideoElement) BuildElement() *message.Elem { +func (e *ShortVideoElement) BuildElement() []*message.Elem { return nil } diff --git a/message/message.go b/message/message.go index 67a69a72..9b62be76 100644 --- a/message/message.go +++ b/message/message.go @@ -324,7 +324,7 @@ func BuildMessageElements(msgElems []IMessageElement) (msgBody *message.MessageB } elems := make([]*message.Elem, 0, len(msgElems)) for _, elem := range msgElems { - var pb *message.Elem + var pb []*message.Elem switch e := elem.(type) { case *TextElement: pb = e.BuildElement() @@ -337,7 +337,7 @@ func BuildMessageElements(msgElems []IMessageElement) (msgBody *message.MessageB default: continue } - elems = append(elems, pb) + elems = append(elems, pb...) } msgBody = &message.MessageBody{ RichText: &message.RichText{Elems: elems},