github.com/Mrs4s/MiraiGo@v0.0.0-20240226124653-54bdd873e3fe/message/elements.go (about) 1 package message 2 3 import ( 4 "fmt" 5 "strconv" 6 7 "github.com/Mrs4s/MiraiGo/client/pb/msg" 8 ) 9 10 //go:generate go run generate.go 11 12 type TextElement struct { 13 Content string 14 } 15 16 type VoiceElement struct { 17 Name string 18 Md5 []byte 19 Size int32 20 Url string 21 22 // --- sending --- 23 Data []byte 24 } 25 26 type GroupVoiceElement struct { 27 Data []byte 28 Ptt *msg.Ptt 29 } 30 31 type PrivateVoiceElement = GroupVoiceElement 32 33 type FaceElement struct { 34 Index int32 35 Name string 36 } 37 38 type AtElement struct { 39 Target int64 40 Display string 41 SubType AtType 42 } 43 44 type GroupFileElement struct { 45 Name string 46 Size int64 47 Path string 48 Busid int32 49 } 50 51 type ReplyElement struct { 52 ReplySeq int32 53 Sender int64 54 GroupID int64 // 私聊回复群聊时 55 Time int32 56 Elements []IMessageElement 57 58 // original []*msg.Elem 59 } 60 61 type ShortVideoElement struct { 62 Name string 63 Uuid []byte 64 Size int32 65 ThumbSize int32 66 Md5 []byte 67 ThumbMd5 []byte 68 Url string 69 Guild bool 70 } 71 72 type ServiceElement struct { 73 Id int32 74 Content string 75 ResId string 76 SubType string 77 } 78 79 type LightAppElement struct { 80 Content string 81 } 82 83 type RedBagElement struct { 84 MsgType RedBagMessageType 85 Title string 86 } 87 88 // MusicShareElement 音乐分享卡片 89 // 90 // 请使用 SendGroupMusicShare 或者 SendFriendMusicShare 发送 91 type MusicShareElement struct { 92 MusicType int // 音乐类型,请使用 QQMusic 等常量 93 Title string // 标题(歌曲名) 94 Brief string 95 Summary string // 简介(歌手名) 96 Url string // 点击跳转链接 97 PictureUrl string // 显示图片链接 98 MusicUrl string // 音乐播放链接 99 } 100 101 type AnimatedSticker struct { 102 ID int32 103 Name string 104 } 105 106 type ( 107 RedBagMessageType int 108 AtType int 109 ) 110 111 // /com/tencent/mobileqq/data/MessageForQQWalletMsg.java 112 const ( 113 RedBagSimple RedBagMessageType = 2 114 RedBagLucky RedBagMessageType = 3 115 RedBagSimpleTheme RedBagMessageType = 4 116 RedBagLuckyTheme RedBagMessageType = 5 117 RedBagWord RedBagMessageType = 6 118 RedBagSimpleSpecify RedBagMessageType = 7 119 RedBagLuckySpecify RedBagMessageType = 8 120 RedBagSimpleSpecifyOver3 RedBagMessageType = 11 121 RedBagLuckySpecifyOver3 RedBagMessageType = 12 122 RedBagVoice RedBagMessageType = 13 123 RedBagLook RedBagMessageType = 14 // ? 124 RedBagVoiceC2C RedBagMessageType = 15 125 RedBagH5 RedBagMessageType = 17 126 RedBagKSong RedBagMessageType = 18 127 RedBagEmoji RedBagMessageType = 19 128 RedBagDraw RedBagMessageType = 22 129 RedBagH5Common RedBagMessageType = 20 130 RedBagWordChain RedBagMessageType = 24 131 RedBagKeyword RedBagMessageType = 25 // ? 132 RedBagDrawMultiModel RedBagMessageType = 26 // ?? 133 134 AtTypeGroupMember = 0 // At群成员 135 AtTypeGuildMember = 1 // At频道成员 136 AtTypeGuildChannel = 2 // At频道 137 ) 138 139 func NewText(s string) *TextElement { 140 return &TextElement{Content: s} 141 } 142 143 func NewFace(index int32) *FaceElement { 144 name := faceMap[int(index)] 145 if name == "" { 146 name = "未知表情" 147 } 148 return &FaceElement{ 149 Index: index, 150 Name: name, 151 } 152 } 153 154 func NewAt(target int64, display ...string) *AtElement { 155 dis := "@" + strconv.FormatInt(target, 10) 156 if target == 0 { 157 dis = "@全体成员" 158 } 159 if len(display) != 0 { 160 dis = display[0] 161 } 162 return &AtElement{ 163 Target: target, 164 Display: dis, 165 } 166 } 167 168 func AtAll() *AtElement { 169 return NewAt(0) 170 } 171 172 func NewReply(m *GroupMessage) *ReplyElement { 173 return &ReplyElement{ 174 ReplySeq: m.Id, 175 Sender: m.Sender.Uin, 176 Time: m.Time, 177 // original: m.OriginalElements, 178 Elements: m.Elements, 179 } 180 } 181 182 func NewPrivateReply(m *PrivateMessage) *ReplyElement { 183 return &ReplyElement{ 184 ReplySeq: m.Id, 185 Sender: m.Sender.Uin, 186 Time: m.Time, 187 Elements: m.Elements, 188 } 189 } 190 191 func NewUrlShare(url, title, content, image string) *ServiceElement { 192 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>`, 193 title, url, image, title, content) 194 /* 195 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>`, 196 url, url, image, title, content, 197 ) 198 */ 199 return &ServiceElement{ 200 Id: 1, 201 Content: template, 202 ResId: url, 203 SubType: "UrlShare", 204 } 205 } 206 207 func NewRichXml(template string, resID int64) *ServiceElement { 208 if resID == 0 { 209 resID = 60 // 默认值60 210 } 211 return &ServiceElement{ 212 Id: int32(resID), 213 Content: template, 214 SubType: "xml", 215 } 216 } 217 218 func NewRichJson(template string) *ServiceElement { 219 return &ServiceElement{ 220 Id: 1, 221 Content: template, 222 SubType: "json", 223 } 224 } 225 226 func NewLightApp(content string) *LightAppElement { 227 return &LightAppElement{Content: content} 228 } 229 230 func (e *TextElement) Type() ElementType { 231 return Text 232 } 233 234 func (e *FaceElement) Type() ElementType { 235 return Face 236 } 237 238 func (e *AtElement) Type() ElementType { 239 return At 240 } 241 242 func (e *ServiceElement) Type() ElementType { 243 return Service 244 } 245 246 func (e *ReplyElement) Type() ElementType { 247 return Reply 248 } 249 250 func (e *GroupFileElement) Type() ElementType { 251 return File 252 } 253 254 func (e *GroupVoiceElement) Type() ElementType { 255 return Voice 256 } 257 258 func (e *VoiceElement) Type() ElementType { 259 return Voice 260 } 261 262 func (e *ShortVideoElement) Type() ElementType { 263 return Video 264 } 265 266 func (e *LightAppElement) Type() ElementType { 267 return LightApp 268 } 269 270 // Type implement message.IMessageElement 271 func (e *MusicShareElement) Type() ElementType { 272 return LightApp 273 } 274 275 func (e *RedBagElement) Type() ElementType { 276 return RedBag 277 } 278 279 func (e *AnimatedSticker) Type() ElementType { 280 return Face 281 }