forked from Mrs4s/MiraiGo
/
elements.go
373 lines (312 loc) · 7.3 KB
/
elements.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
package message
import (
"fmt"
"strconv"
"strings"
"github.com/Mrs4s/MiraiGo/binary"
"github.com/Mrs4s/MiraiGo/client/pb/msg"
)
//todo: github actions
//go:generate go run generate.go
type TextElement struct {
Content string
}
type ImageElement struct {
Filename string
Size int32
Width int32
Height int32
Url string
Md5 []byte
Data []byte
}
type GroupImageElement struct {
ImageId string
FileId int64
ImageType int32
Size int32
Width int32
Height int32
Md5 []byte
Url string
}
type VoiceElement struct {
Name string
Md5 []byte
Size int32
Url string
// --- sending ---
Data []byte
}
type GroupVoiceElement struct {
Data []byte
Ptt *msg.Ptt
}
type PrivateVoiceElement struct {
Data []byte
Ptt *msg.Ptt
}
type FriendImageElement struct {
ImageId string
Md5 []byte
Url string
}
type FaceElement struct {
Index int32
Name string
}
type AtElement struct {
Target int64
Display string
}
type GroupFileElement struct {
Name string
Size int64
Path string
Busid int32
}
type ReplyElement struct {
ReplySeq int32
Sender int64
Time int32
Elements []IMessageElement
// original []*msg.Elem
}
type ShortVideoElement struct {
Name string
Uuid []byte
Size int32
ThumbSize int32
Md5 []byte
ThumbMd5 []byte
Url string
}
type ServiceElement struct {
Id int32
Content string
ResId string
SubType string
}
type ForwardElement struct {
FileName string
Content string
ResId string
Items []*msg.PbMultiMsgItem
}
type LightAppElement struct {
Content string
}
type RedBagElement struct {
MsgType RedBagMessageType
Title string
}
// MusicShareElement 音乐分享卡片
//
// 请使用 SendGroupMusicShare 或者 SendFriendMusicShare 发送
type MusicShareElement struct {
MusicType int // 音乐类型,请使用 QQMusic 等常量
Title string // 标题(歌曲名)
Brief string
Summary string // 简介(歌手名)
Url string // 点击跳转链接
PictureUrl string // 显示图片链接
MusicUrl string // 音乐播放链接
}
// TODO: 总之就是非常傻逼
type GroupFlashImgElement struct {
ImageElement
}
type GroupFlashPicElement struct {
GroupImageElement
}
type GroupShowPicElement struct {
GroupImageElement
EffectId int32
}
type FriendFlashImgElement struct {
ImageElement
}
type FriendFlashPicElement struct {
FriendImageElement
}
type RedBagMessageType int
// /com/tencent/mobileqq/data/MessageForQQWalletMsg.java
const (
RedBagSimple RedBagMessageType = 2
RedBagLucky RedBagMessageType = 3
RedBagSimpleTheme RedBagMessageType = 4
RedBagLuckyTheme RedBagMessageType = 5
RedBagWord RedBagMessageType = 6
RedBagSimpleSpecify RedBagMessageType = 7
RedBagLuckySpecify RedBagMessageType = 8
RedBagSimpleSpecifyOver3 RedBagMessageType = 11
RedBagLuckySpecifyOver3 RedBagMessageType = 12
RedBagVoice RedBagMessageType = 13
RedBagLook RedBagMessageType = 14 // ?
RedBagVoiceC2C RedBagMessageType = 15
RedBagH5 RedBagMessageType = 17
RedBagKSong RedBagMessageType = 18
RedBagEmoji RedBagMessageType = 19
RedBagDraw RedBagMessageType = 22
RedBagH5Common RedBagMessageType = 20
RedBagWordChain RedBagMessageType = 24
RedBagKeyword RedBagMessageType = 25 // ?
RedBagDrawMultiModel RedBagMessageType = 26 // ??
)
func NewText(s string) *TextElement {
return &TextElement{Content: s}
}
func NewImage(data []byte) *ImageElement {
return &ImageElement{
Data: data,
}
}
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: "http://gchat.qpic.cn/gchatpic_new/1/0-0-" + strings.ReplaceAll(binary.CalculateImageResourceId(md5)[1:37], "-", "") + "/0?term=2",
}
}
func NewFace(index int32) *FaceElement {
name := faceMap[int(index)]
if name == "" {
name = "未知表情"
}
return &FaceElement{
Index: index,
Name: name,
}
}
func NewAt(target int64, display ...string) *AtElement {
dis := "@" + strconv.FormatInt(target, 10)
if target == 0 {
dis = "@全体成员"
}
if len(display) != 0 {
dis = display[0]
}
return &AtElement{
Target: target,
Display: dis,
}
}
func AtAll() *AtElement {
return NewAt(0)
}
func NewReply(m *GroupMessage) *ReplyElement {
return &ReplyElement{
ReplySeq: m.Id,
Sender: m.Sender.Uin,
Time: m.Time,
// original: m.OriginalElements,
Elements: m.Elements,
}
}
func NewPrivateReply(m *PrivateMessage) *ReplyElement {
return &ReplyElement{
ReplySeq: m.Id,
Sender: m.Sender.Uin,
Time: m.Time,
Elements: m.Elements,
}
}
func NewUrlShare(url, title, content, image string) *ServiceElement {
template := fmt.Sprintf(`<?xml version="1.0" encoding="utf-8"?><msg templateID="12345" action="web" brief="[分享] %s" serviceID="1" url="%s"><item layout="2"><picture cover="%v"/><title>%v</title><summary>%v</summary></item><source/></msg>`,
title, url, image, title, content,
)
/*
template := fmt.Sprintf(`<?xml version='1.0' encoding='UTF-8' standalone='yes'?><msg templateID="123" url="%s" serviceID="33" action="web" actionData="" brief="【链接】%s" flag="8"><item layout="2"><picture cover="%s"/><title>%s</title><summary>%s</summary></item></msg>`,
url, url, image, title, content,
)
*/
return &ServiceElement{
Id: 1,
Content: template,
ResId: url,
SubType: "UrlShare",
}
}
func NewRichXml(template string, ResId int64) *ServiceElement {
if ResId == 0 {
ResId = 60 // 默认值60
}
return &ServiceElement{
Id: int32(ResId),
Content: template,
SubType: "xml",
}
}
func NewRichJson(template string) *ServiceElement {
return &ServiceElement{
Id: 1,
Content: template,
SubType: "json",
}
}
func NewLightApp(content string) *LightAppElement {
return &LightAppElement{Content: content}
}
func (e *TextElement) Type() ElementType {
return Text
}
func (e *ImageElement) Type() ElementType {
return Image
}
func (e *GroupFlashImgElement) Type() ElementType {
return Image
}
func (e *FriendFlashImgElement) Type() ElementType {
return Image
}
func (e *FaceElement) Type() ElementType {
return Face
}
func (e *GroupImageElement) Type() ElementType {
return Image
}
func (e *FriendImageElement) Type() ElementType {
return Image
}
func (e *AtElement) Type() ElementType {
return At
}
func (e *ServiceElement) Type() ElementType {
return Service
}
func (e *ReplyElement) Type() ElementType {
return Reply
}
func (e *ForwardElement) Type() ElementType {
return Forward
}
func (e *GroupFileElement) Type() ElementType {
return File
}
func (e *GroupVoiceElement) Type() ElementType {
return Voice
}
func (e *PrivateVoiceElement) Type() ElementType {
return Voice
}
func (e *VoiceElement) Type() ElementType {
return Voice
}
func (e *ShortVideoElement) Type() ElementType {
return Video
}
func (e *LightAppElement) Type() ElementType {
return LightApp
}
// Type implement message.IMessageElement
func (e *MusicShareElement) Type() ElementType {
return LightApp
}
func (e *RedBagElement) Type() ElementType {
return RedBag
}