github.com/Mrs4s/MiraiGo@v0.0.0-20240226124653-54bdd873e3fe/message/pack.go (about) 1 package message 2 3 import ( 4 "fmt" 5 6 "github.com/Mrs4s/MiraiGo/binary" 7 "github.com/Mrs4s/MiraiGo/client/pb/msg" 8 "github.com/Mrs4s/MiraiGo/internal/proto" 9 ) 10 11 /* 12 var imgOld = []byte{ 13 0x15, 0x36, 0x20, 0x39, 0x32, 0x6B, 0x41, 0x31, 0x00, 0x38, 0x37, 0x32, 0x66, 0x30, 0x36, 0x36, 0x30, 0x33, 0x61, 0x65, 0x31, 0x30, 0x33, 0x62, 0x37, 0x20, 0x20, 0x20, 0x20, 0x20, 14 0x20, 0x35, 0x30, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7B, 0x30, 0x31, 0x45, 0x39, 0x34, 0x35, 0x31, 0x42, 0x2D, 0x37, 0x30, 0x45, 0x44, 15 0x2D, 0x45, 0x41, 0x45, 0x33, 0x2D, 0x42, 0x33, 0x37, 0x43, 0x2D, 0x31, 0x30, 0x31, 0x46, 0x31, 0x45, 0x45, 0x42, 0x46, 0x35, 0x42, 0x35, 0x7D, 0x2E, 0x70, 0x6E, 0x67, 0x41, 16 } 17 */ 18 19 func (e *TextElement) Pack() (r []*msg.Elem) { 20 r = append(r, &msg.Elem{ 21 Text: &msg.Text{ 22 Str: proto.Some(e.Content), 23 }, 24 }) 25 return 26 } 27 28 func (e *FaceElement) Pack() (r []*msg.Elem) { 29 r = []*msg.Elem{} 30 if e.Index >= 260 { 31 elem := &msg.MsgElemInfoServtype33{ 32 Index: proto.Uint32(uint32(e.Index)), 33 Text: []byte("/" + e.Name), 34 Compat: []byte("/" + e.Name), 35 } 36 b, _ := proto.Marshal(elem) 37 r = append(r, &msg.Elem{ 38 CommonElem: &msg.CommonElem{ 39 ServiceType: proto.Int32(33), 40 PbElem: b, 41 BusinessType: proto.Int32(1), 42 }, 43 }) 44 } else { 45 r = append(r, &msg.Elem{ 46 Face: &msg.Face{ 47 Index: proto.Some(e.Index), 48 Old: binary.ToBytes(int16(0x1445 - 4 + e.Index)), 49 Buf: []byte{0x00, 0x01, 0x00, 0x04, 0x52, 0xCC, 0xF5, 0xD0}, 50 }, 51 }) 52 } 53 return 54 } 55 56 func (e *AtElement) Pack() (r []*msg.Elem) { 57 r = []*msg.Elem{} 58 switch e.SubType { 59 case AtTypeGroupMember: 60 r = append(r, &msg.Elem{ 61 Text: &msg.Text{ 62 Str: proto.Some(e.Display), 63 Attr6Buf: binary.NewWriterF(func(w *binary.Writer) { 64 w.WriteUInt16(1) 65 w.WriteUInt16(0) 66 w.WriteUInt16(uint16(len([]rune(e.Display)))) 67 if e.Target == 0 { 68 w.WriteByte(1) 69 } else { 70 w.WriteByte(0) 71 } 72 w.WriteUInt32(uint32(e.Target)) 73 w.WriteUInt16(0) 74 }), 75 }, 76 }) 77 case AtTypeGuildMember: 78 pb, _ := proto.Marshal(&msg.TextResvAttr{AtType: proto.Uint32(2), AtMemberTinyid: proto.Uint64(uint64(e.Target))}) 79 r = append(r, &msg.Elem{ 80 Text: &msg.Text{ 81 Str: proto.Some(e.Display), 82 PbReserve: pb, 83 }, 84 }) 85 } 86 r = append(r, &msg.Elem{Text: &msg.Text{Str: proto.String(" ")}}) 87 return 88 } 89 90 func (e *ServiceElement) Pack() (r []*msg.Elem) { 91 r = []*msg.Elem{} 92 // id =35 已移至 ForwardElement 93 if e.Id == 1 { 94 r = append(r, &msg.Elem{ 95 Text: &msg.Text{Str: proto.Some(e.ResId)}, 96 }) 97 } 98 r = append(r, &msg.Elem{ 99 RichMsg: &msg.RichMsg{ 100 Template1: append([]byte{1}, binary.ZlibCompress([]byte(e.Content))...), 101 ServiceId: proto.Some(e.Id), 102 }, 103 }) 104 return 105 } 106 107 func (e *LightAppElement) Pack() (r []*msg.Elem) { 108 r = []*msg.Elem{} 109 r = append(r, &msg.Elem{ 110 LightApp: &msg.LightAppElem{ 111 Data: append([]byte{1}, binary.ZlibCompress([]byte(e.Content))...), 112 // MsgResid: []byte{1}, 113 }, 114 }) 115 return 116 } 117 118 func (e *ShortVideoElement) Pack() (r []*msg.Elem) { 119 r = append(r, &msg.Elem{ 120 Text: &msg.Text{ 121 Str: proto.String("你的QQ暂不支持查看视频短片,请期待后续版本。"), 122 }, 123 }) 124 125 video := &msg.VideoFile{ 126 FileUuid: e.Uuid, 127 FileMd5: e.Md5, 128 FileName: []byte(fmt.Sprintf("%x.mp4", e.Md5)), 129 FileFormat: proto.Int32(3), 130 FileTime: proto.Int32(10), 131 FileSize: proto.Int32(e.Size), 132 ThumbWidth: proto.Int32(1280), 133 ThumbHeight: proto.Int32(720), 134 ThumbFileMd5: e.ThumbMd5, 135 ThumbFileSize: proto.Int32(e.ThumbSize), 136 BusiType: proto.Int32(0), 137 FromChatType: proto.Int32(-1), 138 ToChatType: proto.Int32(-1), 139 BoolSupportProgressive: proto.Bool(true), 140 FileWidth: proto.Int32(1280), 141 FileHeight: proto.Int32(720), 142 } 143 144 if e.Guild { 145 video.BusiType = proto.Int32(4601) 146 video.SubBusiType = proto.Int32(4601) 147 video.FileWidth = proto.Int32(0) 148 video.FileHeight = proto.Int32(0) 149 video.VideoAttr = proto.Int32(0) 150 } 151 152 r = append(r, &msg.Elem{VideoFile: video}) 153 return 154 } 155 156 func (e *AnimatedSticker) Pack() []*msg.Elem { 157 if e.Name == "" { 158 e.Name = faceMap[int(e.ID)] 159 } 160 name := "/" + e.Name 161 business := int32(1) 162 if e.ID == 114 { 163 // 对篮球适配,否则篮球不会投出 164 business = 2 165 } 166 167 pbElem, _ := proto.Marshal(&msg.MsgElemInfoServtype37{ 168 Packid: []byte("1"), 169 Stickerid: []byte(stickerMap[int(e.ID)]), 170 Qsid: proto.Uint32(uint32(e.ID)), 171 Sourcetype: proto.Uint32(1), 172 Stickertype: proto.Uint32(uint32(business)), 173 Resultid: []byte{}, 174 Text: []byte(name), 175 Surpriseid: []byte{}, 176 Randomtype: proto.Uint32(1), 177 }) 178 common := &msg.Elem{ 179 CommonElem: &msg.CommonElem{ 180 ServiceType: proto.Int32(37), 181 PbElem: pbElem, 182 BusinessType: proto.Some(business), 183 }, 184 } 185 186 pbReverse, _ := proto.Marshal(&msg.Text{Str: proto.String(fmt.Sprintf("[%s]请使用最新版手机QQ体验新功能", e.Name))}) 187 text := &msg.Elem{ 188 Text: &msg.Text{ 189 Str: proto.Some(name), 190 PbReserve: pbReverse, 191 }, 192 } 193 194 return []*msg.Elem{common, text} 195 }