forked from Mrs4s/MiraiGo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
elements.go
281 lines (236 loc) · 5.77 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
package message
import (
"fmt"
"strconv"
"github.com/grayrail000/MiraiGo/client/pb/msg"
)
//go:generate go run generate.go
type TextElement struct {
Content 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 = GroupVoiceElement
type FaceElement struct {
Index int32
Name string
}
type AtElement struct {
Target int64
Display string
SubType AtType
}
type GroupFileElement struct {
Name string
Size int64
Path string
Busid int32
}
type ReplyElement struct {
ReplySeq int32
Sender int64
GroupID 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
Guild bool
}
type ServiceElement struct {
Id int32
Content string
ResId string
SubType string
}
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 // 音乐播放链接
}
type AnimatedSticker struct {
ID int32
Name string
}
type (
RedBagMessageType int
AtType 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 // ??
AtTypeGroupMember = 0 // At群成员
AtTypeGuildMember = 1 // At频道成员
AtTypeGuildChannel = 2 // At频道
)
func NewText(s string) *TextElement {
return &TextElement{Content: s}
}
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 *FaceElement) Type() ElementType {
return Face
}
func (e *AtElement) Type() ElementType {
return At
}
func (e *ServiceElement) Type() ElementType {
return Service
}
func (e *ReplyElement) Type() ElementType {
return Reply
}
func (e *GroupFileElement) Type() ElementType {
return File
}
func (e *GroupVoiceElement) 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
}
func (e *AnimatedSticker) Type() ElementType {
return Face
}