mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 11:07:40 +08:00
reply supported.
This commit is contained in:
parent
5ead51215a
commit
a45ad2e147
@ -11,7 +11,6 @@ import (
|
||||
"google.golang.org/protobuf/proto"
|
||||
"math/rand"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type DeviceInfo struct {
|
||||
@ -190,7 +189,7 @@ func (c *QQClient) parsePrivateMessage(msg *msg.Message) *message.PrivateMessage
|
||||
Uin: friend.Uin,
|
||||
Nickname: friend.Nickname,
|
||||
},
|
||||
Elements: parseMessageElems(msg.Body.RichText.Elems),
|
||||
Elements: message.ParseMessageElems(msg.Body.RichText.Elems),
|
||||
}
|
||||
}
|
||||
|
||||
@ -206,7 +205,7 @@ func (c *QQClient) parseTempMessage(msg *msg.Message) *message.TempMessage {
|
||||
Nickname: mem.Nickname,
|
||||
CardName: mem.CardName,
|
||||
},
|
||||
Elements: parseMessageElems(msg.Body.RichText.Elems),
|
||||
Elements: message.ParseMessageElems(msg.Body.RichText.Elems),
|
||||
}
|
||||
}
|
||||
|
||||
@ -245,80 +244,13 @@ func (c *QQClient) parseGroupMessage(m *msg.Message) *message.GroupMessage {
|
||||
GroupCode: group.Code,
|
||||
GroupName: string(m.Head.GroupInfo.GroupName),
|
||||
Sender: sender,
|
||||
Elements: parseMessageElems(m.Body.RichText.Elems),
|
||||
Time: m.Head.MsgTime,
|
||||
Elements: message.ParseMessageElems(m.Body.RichText.Elems),
|
||||
//OriginalElements: m.Body.RichText.Elems,
|
||||
}
|
||||
return g
|
||||
}
|
||||
|
||||
func parseMessageElems(elems []*msg.Elem) []message.IMessageElement {
|
||||
var res []message.IMessageElement
|
||||
for _, elem := range elems {
|
||||
if elem.SrcMsg != nil {
|
||||
if len(elem.SrcMsg.OrigSeqs) != 0 {
|
||||
r := &message.ReplyElement{
|
||||
ReplySeq: elem.SrcMsg.OrigSeqs[0],
|
||||
Elements: parseMessageElems(elem.SrcMsg.Elems),
|
||||
}
|
||||
res = append(res, r)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if elem.Text != nil {
|
||||
if len(elem.Text.Attr6Buf) == 0 {
|
||||
res = append(res, message.NewText(elem.Text.Str))
|
||||
} else {
|
||||
att6 := binary.NewReader(elem.Text.Attr6Buf)
|
||||
att6.ReadBytes(7)
|
||||
target := int64(uint32(att6.ReadInt32()))
|
||||
res = append(res, message.NewAt(target, elem.Text.Str))
|
||||
}
|
||||
}
|
||||
if elem.RichMsg != nil {
|
||||
var content string
|
||||
if elem.RichMsg.Template1[0] == 0 {
|
||||
content = string(elem.RichMsg.Template1[1:])
|
||||
}
|
||||
if elem.RichMsg.Template1[0] == 1 {
|
||||
content = string(binary.ZlibUncompress(elem.RichMsg.Template1[1:]))
|
||||
}
|
||||
if content != "" {
|
||||
res = append(res, message.NewText(content))
|
||||
}
|
||||
}
|
||||
if elem.CustomFace != nil {
|
||||
res = append(res, &message.ImageElement{
|
||||
Filename: elem.CustomFace.FilePath,
|
||||
Size: elem.CustomFace.Size,
|
||||
Url: func() string {
|
||||
if elem.CustomFace.OrigUrl == "" {
|
||||
return "http://gchat.qpic.cn/gchatpic_new/0/0-0-" + strings.ReplaceAll(binary.CalculateImageResourceId(elem.CustomFace.Md5)[1:37], "-", "") + "/0?term=2"
|
||||
}
|
||||
return "http://gchat.qpic.cn" + elem.CustomFace.OrigUrl
|
||||
}(),
|
||||
Md5: elem.CustomFace.Md5,
|
||||
})
|
||||
}
|
||||
if elem.NotOnlineImage != nil {
|
||||
var img string
|
||||
if elem.NotOnlineImage.OrigUrl != "" {
|
||||
img = "http://c2cpicdw.qpic.cn" + elem.NotOnlineImage.OrigUrl
|
||||
} else {
|
||||
img = "http://c2cpicdw.qpic.cn/offpic_new/0/" + elem.NotOnlineImage.ResId + "/0?term=2"
|
||||
}
|
||||
res = append(res, &message.ImageElement{
|
||||
Filename: elem.NotOnlineImage.FilePath,
|
||||
Size: elem.NotOnlineImage.FileLen,
|
||||
Url: img,
|
||||
Md5: elem.NotOnlineImage.PicMd5,
|
||||
})
|
||||
}
|
||||
if elem.Face != nil {
|
||||
res = append(res, message.NewFace(elem.Face.Index))
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func (b *groupMessageBuilder) build() *msg.Message {
|
||||
sort.Slice(b.MessageSlices, func(i, j int) bool {
|
||||
return b.MessageSlices[i].Content.PkgIndex < b.MessageSlices[i].Content.PkgIndex
|
||||
|
@ -35,7 +35,11 @@ type AtElement struct {
|
||||
|
||||
type ReplyElement struct {
|
||||
ReplySeq int32
|
||||
Sender int64
|
||||
Time int32
|
||||
Elements []IMessageElement
|
||||
|
||||
//original []*msg.Elem
|
||||
}
|
||||
|
||||
func NewText(s string) *TextElement {
|
||||
@ -85,6 +89,16 @@ 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 (e *TextElement) Type() ElementType {
|
||||
return Text
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"github.com/Mrs4s/MiraiGo/binary"
|
||||
"github.com/Mrs4s/MiraiGo/client/pb/msg"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type PrivateMessage struct {
|
||||
@ -25,7 +26,9 @@ type GroupMessage struct {
|
||||
GroupCode int64
|
||||
GroupName string
|
||||
Sender *Sender
|
||||
Time int32
|
||||
Elements []IMessageElement
|
||||
//OriginalElements []*msg.Elem
|
||||
}
|
||||
|
||||
type SendingMessage struct {
|
||||
@ -126,6 +129,23 @@ func (s *Sender) DisplayName() string {
|
||||
}
|
||||
|
||||
func ToProtoElems(elems []IMessageElement) (r []*msg.Elem) {
|
||||
for _, elem := range elems {
|
||||
if reply, ok := elem.(*ReplyElement); ok {
|
||||
r = append(r, &msg.Elem{
|
||||
SrcMsg: &msg.SourceMsg{
|
||||
OrigSeqs: []int32{reply.ReplySeq},
|
||||
SenderUin: reply.Sender,
|
||||
Time: reply.Time,
|
||||
Flag: 1,
|
||||
Elems: ToProtoElems(reply.Elements),
|
||||
RichMsg: []byte{},
|
||||
PbReserve: []byte{},
|
||||
SrcMsg: []byte{},
|
||||
TroopName: []byte{},
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
for _, elem := range elems {
|
||||
switch e := elem.(type) {
|
||||
case *TextElement:
|
||||
@ -177,3 +197,74 @@ func ToProtoElems(elems []IMessageElement) (r []*msg.Elem) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func ParseMessageElems(elems []*msg.Elem) []IMessageElement {
|
||||
var res []IMessageElement
|
||||
for _, elem := range elems {
|
||||
if elem.SrcMsg != nil {
|
||||
if len(elem.SrcMsg.OrigSeqs) != 0 {
|
||||
r := &ReplyElement{
|
||||
ReplySeq: elem.SrcMsg.OrigSeqs[0],
|
||||
Time: elem.SrcMsg.Time,
|
||||
Sender: elem.SrcMsg.SenderUin,
|
||||
Elements: ParseMessageElems(elem.SrcMsg.Elems),
|
||||
}
|
||||
res = append(res, r)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if elem.Text != nil {
|
||||
if len(elem.Text.Attr6Buf) == 0 {
|
||||
res = append(res, NewText(elem.Text.Str))
|
||||
} else {
|
||||
att6 := binary.NewReader(elem.Text.Attr6Buf)
|
||||
att6.ReadBytes(7)
|
||||
target := int64(uint32(att6.ReadInt32()))
|
||||
res = append(res, NewAt(target, elem.Text.Str))
|
||||
}
|
||||
}
|
||||
if elem.RichMsg != nil {
|
||||
var content string
|
||||
if elem.RichMsg.Template1[0] == 0 {
|
||||
content = string(elem.RichMsg.Template1[1:])
|
||||
}
|
||||
if elem.RichMsg.Template1[0] == 1 {
|
||||
content = string(binary.ZlibUncompress(elem.RichMsg.Template1[1:]))
|
||||
}
|
||||
if content != "" {
|
||||
res = append(res, NewText(content))
|
||||
}
|
||||
}
|
||||
if elem.CustomFace != nil {
|
||||
res = append(res, &ImageElement{
|
||||
Filename: elem.CustomFace.FilePath,
|
||||
Size: elem.CustomFace.Size,
|
||||
Url: func() string {
|
||||
if elem.CustomFace.OrigUrl == "" {
|
||||
return "http://gchat.qpic.cn/gchatpic_new/0/0-0-" + strings.ReplaceAll(binary.CalculateImageResourceId(elem.CustomFace.Md5)[1:37], "-", "") + "/0?term=2"
|
||||
}
|
||||
return "http://gchat.qpic.cn" + elem.CustomFace.OrigUrl
|
||||
}(),
|
||||
Md5: elem.CustomFace.Md5,
|
||||
})
|
||||
}
|
||||
if elem.NotOnlineImage != nil {
|
||||
var img string
|
||||
if elem.NotOnlineImage.OrigUrl != "" {
|
||||
img = "http://c2cpicdw.qpic.cn" + elem.NotOnlineImage.OrigUrl
|
||||
} else {
|
||||
img = "http://c2cpicdw.qpic.cn/offpic_new/0/" + elem.NotOnlineImage.ResId + "/0?term=2"
|
||||
}
|
||||
res = append(res, &ImageElement{
|
||||
Filename: elem.NotOnlineImage.FilePath,
|
||||
Size: elem.NotOnlineImage.FileLen,
|
||||
Url: img,
|
||||
Md5: elem.NotOnlineImage.PicMd5,
|
||||
})
|
||||
}
|
||||
if elem.Face != nil {
|
||||
res = append(res, NewFace(elem.Face.Index))
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user