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