mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 11:07:40 +08:00
url share supported.
This commit is contained in:
parent
298c1bb911
commit
9997afd301
@ -1,6 +1,7 @@
|
||||
package message
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@ -123,6 +124,18 @@ func NewReply(m *GroupMessage) *ReplyElement {
|
||||
}
|
||||
}
|
||||
|
||||
func NewUrlShare(url, title, content, image string) *ServiceElement {
|
||||
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: 33,
|
||||
Content: template,
|
||||
ResId: url,
|
||||
SubType: "UrlShare",
|
||||
}
|
||||
}
|
||||
|
||||
func (e *TextElement) Type() ElementType {
|
||||
return Text
|
||||
}
|
||||
|
@ -301,6 +301,18 @@ func ToProtoElems(elems []IMessageElement, generalFlags bool) (r []*msg.Elem) {
|
||||
},
|
||||
})
|
||||
}
|
||||
if e.Id == 33 {
|
||||
r = append(r, &msg.Elem{
|
||||
Text: &msg.Text{Str: e.ResId},
|
||||
})
|
||||
r = append(r, &msg.Elem{
|
||||
RichMsg: &msg.RichMsg{
|
||||
Template1: append([]byte{1}, binary.ZlibCompress([]byte(e.Content))...),
|
||||
ServiceId: e.Id,
|
||||
MsgResId: []byte{},
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
if generalFlags {
|
||||
@ -404,6 +416,9 @@ func ParseMessageElems(elems []*msg.Elem) []IMessageElement {
|
||||
res = append(res, &ForwardElement{ResId: reg.FindAllStringSubmatch(content, -1)[0][1]})
|
||||
continue
|
||||
}
|
||||
if elem.RichMsg.ServiceId == 33 {
|
||||
continue // 前面一个 elem 已经解析到链接
|
||||
}
|
||||
res = append(res, NewText(content))
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user