github.com/LagrangeDev/LagrangeGo@v0.0.0-20240512064304-ad4a85e10cb4/message/build.go (about)

     1  package message
     2  
     3  import (
     4  	"github.com/LagrangeDev/LagrangeGo/client/packets/pb/message"
     5  	"github.com/LagrangeDev/LagrangeGo/internal/proto"
     6  )
     7  
     8  type ElementBuilder interface {
     9  	BuildElement() []*message.Elem
    10  }
    11  
    12  func (e *TextElement) BuildElement() []*message.Elem {
    13  	return []*message.Elem{{Text: &message.Text{Str: proto.Some(e.Content)}}}
    14  }
    15  
    16  func (e *AtElement) BuildElement() []*message.Elem {
    17  	var atAll int32 = 2
    18  	if e.Target == 0 {
    19  		atAll = 1
    20  	}
    21  	reserve := message.MentionExtra{
    22  		Type:   proto.Some(atAll),
    23  		Uin:    proto.Some(uint32(0)),
    24  		Field5: proto.Some(int32(0)),
    25  		Uid:    proto.Some(e.UID),
    26  	}
    27  	reserveData, _ := proto.Marshal(&reserve)
    28  	return []*message.Elem{{Text: &message.Text{
    29  		Str:       proto.Some(e.Display),
    30  		PbReserve: reserveData,
    31  	}}}
    32  }
    33  
    34  func (e *FaceElement) BuildElement() []*message.Elem {
    35  	faceId := int32(e.FaceID)
    36  	if e.isLargeFace {
    37  		qFace := message.QFaceExtra{
    38  			Field1:  proto.Some("1"),
    39  			Field2:  proto.Some("8"),
    40  			FaceId:  proto.Some(faceId),
    41  			Field4:  proto.Some(int32(1)),
    42  			Field5:  proto.Some(int32(1)),
    43  			Field6:  proto.Some(""),
    44  			Preview: proto.Some(""),
    45  			Field9:  proto.Some(int32(1)),
    46  		}
    47  		qFaceData, _ := proto.Marshal(&qFace)
    48  		return []*message.Elem{{
    49  			CommonElem: &message.CommonElem{
    50  				ServiceType:  37,
    51  				PbElem:       qFaceData,
    52  				BusinessType: 1,
    53  			},
    54  		}}
    55  	} else {
    56  		return []*message.Elem{{
    57  			Face: &message.Face{Index: proto.Some(faceId)},
    58  		}}
    59  	}
    60  }
    61  
    62  func (e *GroupImageElement) BuildElement() []*message.Elem {
    63  	common, err := proto.Marshal(e.MsgInfo)
    64  	if err != nil {
    65  		return nil
    66  	}
    67  	msg := []*message.Elem{{
    68  		CommonElem: &message.CommonElem{
    69  			ServiceType:  48,
    70  			PbElem:       common,
    71  			BusinessType: 10,
    72  		},
    73  	}}
    74  	return msg
    75  }
    76  
    77  func (e *FriendImageElement) BuildElement() []*message.Elem {
    78  	common, err := proto.Marshal(e.MsgInfo)
    79  	if err != nil {
    80  		return nil
    81  	}
    82  	var msg []*message.Elem
    83  	if e.CompatImage != nil {
    84  		msg = []*message.Elem{{
    85  			NotOnlineImage: e.CompatImage,
    86  		}}
    87  	}
    88  	msg = append(msg, &message.Elem{
    89  		CommonElem: &message.CommonElem{
    90  			ServiceType:  48,
    91  			PbElem:       common,
    92  			BusinessType: 10,
    93  		},
    94  	})
    95  	return msg
    96  }
    97  
    98  func (e *ReplyElement) BuildElement() []*message.Elem {
    99  	return nil
   100  }
   101  
   102  func (e *VoiceElement) BuildElement() []*message.Elem {
   103  	return nil
   104  }
   105  
   106  func (e *ShortVideoElement) BuildElement() []*message.Elem {
   107  	return nil
   108  }