github.com/Mrs4s/MiraiGo@v0.0.0-20240226124653-54bdd873e3fe/message/image.go (about) 1 package message 2 3 import ( 4 "fmt" 5 6 "github.com/Mrs4s/MiraiGo/client/pb/msg" 7 "github.com/Mrs4s/MiraiGo/internal/proto" 8 ) 9 10 /* -------- Definitions -------- */ 11 12 type GroupImageElement struct { 13 ImageId string 14 FileId int64 15 ImageType int32 16 ImageBizType ImageBizType 17 Size int32 18 Width int32 19 Height int32 20 Md5 []byte 21 Url string 22 23 // EffectID show pic effect id. 24 EffectID int32 25 Flash bool 26 } 27 28 type FriendImageElement struct { 29 ImageId string 30 Md5 []byte 31 Size int32 32 Width int32 33 Height int32 34 Url string 35 36 Flash bool 37 } 38 39 type GuildImageElement struct { 40 FileId int64 41 FilePath string 42 ImageType int32 43 Size int32 44 Width int32 45 Height int32 46 DownloadIndex string 47 Md5 []byte 48 Url string 49 } 50 51 type ImageBizType uint32 52 53 const ( 54 UnknownBizType ImageBizType = 0 55 CustomFaceImage ImageBizType = 1 56 HotImage ImageBizType = 2 57 DouImage ImageBizType = 3 // 斗图 58 ZhiTuImage ImageBizType = 4 59 StickerImage ImageBizType = 7 60 SelfieImage ImageBizType = 8 61 StickerAdImage ImageBizType = 9 62 RelatedEmoImage ImageBizType = 10 63 HotSearchImage ImageBizType = 13 64 ) 65 66 /* ------ Implementations ------ */ 67 68 func NewGroupImage(id string, md5 []byte, fid int64, size, width, height, imageType int32) *GroupImageElement { 69 return &GroupImageElement{ 70 ImageId: id, 71 FileId: fid, 72 Md5: md5, 73 Size: size, 74 ImageType: imageType, 75 Width: width, 76 Height: height, 77 Url: fmt.Sprintf("https://gchat.qpic.cn/gchatpic_new/1/0-0-%X/0?term=2", md5), 78 } 79 } 80 81 func (e *GroupImageElement) Type() ElementType { 82 return Image 83 } 84 85 func (e *FriendImageElement) Type() ElementType { 86 return Image 87 } 88 89 func (e *GuildImageElement) Type() ElementType { 90 return Image 91 } 92 93 func (e *GroupImageElement) Pack() (r []*msg.Elem) { 94 // width and height are required, set 720*480 if not set 95 if e.Width == 0 { 96 e.Width = 720 97 } 98 if e.Height == 0 { 99 e.Height = 480 100 } 101 102 cface := &msg.CustomFace{ 103 FileType: proto.Int32(66), 104 Useful: proto.Int32(1), 105 // Origin: 1, 106 BizType: proto.Int32(5), 107 Width: proto.Some(e.Width), 108 Height: proto.Some(e.Height), 109 FileId: proto.Int32(int32(e.FileId)), 110 FilePath: proto.Some(e.ImageId), 111 ImageType: proto.Some(e.ImageType), 112 Size: proto.Some(e.Size), 113 Md5: e.Md5, 114 Flag: make([]byte, 4), 115 // OldData: imgOld, 116 } 117 118 if e.Flash { // resolve flash pic 119 flash := &msg.MsgElemInfoServtype3{FlashTroopPic: cface} 120 data, _ := proto.Marshal(flash) 121 flashElem := &msg.Elem{ 122 CommonElem: &msg.CommonElem{ 123 ServiceType: proto.Int32(3), 124 PbElem: data, 125 }, 126 } 127 textHint := &msg.Elem{ 128 Text: &msg.Text{ 129 Str: proto.String("[闪照]请使用新版手机QQ查看闪照。"), 130 }, 131 } 132 return []*msg.Elem{flashElem, textHint} 133 } 134 res := &msg.ResvAttr{} 135 if e.EffectID != 0 { // resolve show pic 136 res.ImageShow = &msg.AnimationImageShow{ 137 EffectId: proto.Some(e.EffectID), 138 AnimationParam: []byte("{}"), 139 } 140 cface.Flag = []byte{0x11, 0x00, 0x00, 0x00} 141 } 142 if e.ImageBizType != UnknownBizType { 143 res.ImageBizType = proto.Uint32(uint32(e.ImageBizType)) 144 } 145 cface.PbReserve, _ = proto.Marshal(res) 146 elem := &msg.Elem{CustomFace: cface} 147 return []*msg.Elem{elem} 148 } 149 150 func (e *FriendImageElement) Pack() []*msg.Elem { 151 image := &msg.NotOnlineImage{ 152 FilePath: proto.Some(e.ImageId), 153 ResId: proto.Some(e.ImageId), 154 OldPicMd5: proto.Some(false), 155 PicMd5: e.Md5, 156 PicHeight: proto.Some(e.Height), 157 PicWidth: proto.Some(e.Width), 158 DownloadPath: proto.Some(e.ImageId), 159 Original: proto.Int32(1), 160 } 161 162 if e.Flash { 163 flash := &msg.MsgElemInfoServtype3{FlashC2CPic: image} 164 data, _ := proto.Marshal(flash) 165 flashElem := &msg.Elem{ 166 CommonElem: &msg.CommonElem{ 167 ServiceType: proto.Int32(3), 168 PbElem: data, 169 }, 170 } 171 textHint := &msg.Elem{ 172 Text: &msg.Text{ 173 Str: proto.String("[闪照]请使用新版手机QQ查看闪照。"), 174 }, 175 } 176 return []*msg.Elem{flashElem, textHint} 177 } 178 179 elem := &msg.Elem{NotOnlineImage: image} 180 return []*msg.Elem{elem} 181 } 182 183 func (e *GuildImageElement) Pack() (r []*msg.Elem) { 184 cface := &msg.CustomFace{ 185 FileType: proto.Int32(66), 186 Useful: proto.Int32(1), 187 BizType: proto.Int32(0), 188 Width: proto.Some(e.Width), 189 Height: proto.Some(e.Height), 190 FileId: proto.Int32(int32(e.FileId)), 191 FilePath: proto.Some(e.FilePath), 192 ImageType: proto.Some(e.ImageType), 193 Size: proto.Some(e.Size), 194 Md5: e.Md5, 195 PbReserve: proto.DynamicMessage{ 196 1: 0, 2: 0, 6: "", 10: 0, 15: 8, 197 20: e.DownloadIndex, 198 }.Encode(), 199 } 200 elem := &msg.Elem{CustomFace: cface} 201 return []*msg.Elem{elem} 202 }