mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-05 03:23:50 +08:00
374 lines
7.3 KiB
Go
374 lines
7.3 KiB
Go
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
|
|
}
|