mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 19:17:38 +08:00
extract DownloadForwardMessage
用来转发forward套娃
This commit is contained in:
parent
dd94cc86c5
commit
b58629ffbf
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/Mrs4s/MiraiGo/binary/jce"
|
"github.com/Mrs4s/MiraiGo/binary/jce"
|
||||||
"image"
|
"image"
|
||||||
"io"
|
"io"
|
||||||
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
@ -137,8 +138,6 @@ var decoders = map[string]func(*QQClient, uint16, []byte) (interface{}, error){
|
|||||||
"LongConn.OffPicUp": decodeOffPicUpResponse,
|
"LongConn.OffPicUp": decodeOffPicUpResponse,
|
||||||
"ProfileService.Pb.ReqSystemMsgNew.Group": decodeSystemMsgGroupPacket,
|
"ProfileService.Pb.ReqSystemMsgNew.Group": decodeSystemMsgGroupPacket,
|
||||||
"ProfileService.Pb.ReqSystemMsgNew.Friend": decodeSystemMsgFriendPacket,
|
"ProfileService.Pb.ReqSystemMsgNew.Friend": decodeSystemMsgFriendPacket,
|
||||||
"MultiMsg.ApplyUp": decodeMultiApplyUpResponse,
|
|
||||||
"MultiMsg.ApplyDown": decodeMultiApplyDownResponse,
|
|
||||||
"OidbSvc.0xe07_0": decodeImageOcrResponse,
|
"OidbSvc.0xe07_0": decodeImageOcrResponse,
|
||||||
"OidbSvc.0xd79": decodeWordSegmentation,
|
"OidbSvc.0xd79": decodeWordSegmentation,
|
||||||
"OidbSvc.0x990": decodeTranslateResponse,
|
"OidbSvc.0x990": decodeTranslateResponse,
|
||||||
@ -503,23 +502,20 @@ func (c *QQClient) SendTempMessage(groupCode, target int64, m *message.SendingMe
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *QQClient) GetForwardMessage(resId string) *message.ForwardMessage {
|
func (c *QQClient) GetForwardMessage(resId string) *message.ForwardMessage {
|
||||||
i, err := c.sendAndWait(c.buildMultiApplyDownPacket(resId))
|
m := c.DownloadForwardMessage(resId)
|
||||||
if err != nil {
|
if m == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
multiMsg := i.(*msg.PbMultiMsgTransmit)
|
var (
|
||||||
ret := &message.ForwardMessage{}
|
item *msg.PbMultiMsgItem
|
||||||
if multiMsg.GetPbItemList() == nil {
|
ret = &message.ForwardMessage{Nodes: []*message.ForwardNode{}}
|
||||||
return nil
|
)
|
||||||
}
|
for _, iter := range m.Items {
|
||||||
var item *msg.PbMultiMsgItem
|
if iter.GetFileName() == "MultiMsg" {
|
||||||
for _, m := range multiMsg.GetPbItemList() {
|
item = iter
|
||||||
if m.GetFileName() == "MultiMsg" {
|
|
||||||
item = m
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if item == nil || item.GetBuffer() == nil || item.GetBuffer().GetMsg() == nil {
|
if item == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for _, m := range item.GetBuffer().GetMsg() {
|
for _, m := range item.GetBuffer().GetMsg() {
|
||||||
@ -538,6 +534,38 @@ func (c *QQClient) GetForwardMessage(resId string) *message.ForwardMessage {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *QQClient) DownloadForwardMessage(resId string) *message.ForwardElement {
|
||||||
|
i, err := c.sendAndWait(c.buildMultiApplyDownPacket(resId))
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
multiMsg := i.(*msg.PbMultiMsgTransmit)
|
||||||
|
if multiMsg.GetPbItemList() == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
var pv string
|
||||||
|
for i := 0; i < int(math.Min(4, float64(len(multiMsg.GetMsg())))); i++ {
|
||||||
|
m := multiMsg.Msg[i]
|
||||||
|
pv += fmt.Sprintf(`<title size="26" color="#777777">%s: %s</title>`,
|
||||||
|
func() string {
|
||||||
|
if m.Head.GetMsgType() == 82 && m.Head.GroupInfo != nil {
|
||||||
|
return m.Head.GroupInfo.GetGroupCard()
|
||||||
|
}
|
||||||
|
return m.Head.GetFromNick()
|
||||||
|
}(),
|
||||||
|
message.ToReadableString(
|
||||||
|
message.ParseMessageElems(multiMsg.Msg[i].GetBody().GetRichText().Elems),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return genForwardTemplate(
|
||||||
|
resId, pv, "群聊的聊天记录", "[聊天记录]", "聊天记录",
|
||||||
|
fmt.Sprintf("查看 %d 条转发消息", len(multiMsg.GetMsg())),
|
||||||
|
time.Now().UnixNano(),
|
||||||
|
multiMsg.GetPbItemList(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *QQClient) sendGroupPoke(groupCode, target int64) {
|
func (c *QQClient) sendGroupPoke(groupCode, target int64) {
|
||||||
_, _ = c.sendAndWait(c.buildGroupPokePacket(groupCode, target))
|
_, _ = c.sendAndWait(c.buildGroupPokePacket(groupCode, target))
|
||||||
}
|
}
|
||||||
|
@ -580,18 +580,14 @@ func genForwardTemplate(resId, preview, title, brief, source, summary string, ts
|
|||||||
template := fmt.Sprintf(`<?xml version='1.0' encoding='UTF-8'?><msg serviceID="35" templateID="1" action="viewMultiMsg" brief="%s" m_resid="%s" m_fileName="%d" tSum="3" sourceMsgId="0" url="" flag="3" adverSign="0" multiMsgFlag="0"><item layout="1"><title color="#000000" size="34">%s</title> %s<hr></hr><summary size="26" color="#808080">%s</summary></item><source name="%s"></source></msg>`,
|
template := fmt.Sprintf(`<?xml version='1.0' encoding='UTF-8'?><msg serviceID="35" templateID="1" action="viewMultiMsg" brief="%s" m_resid="%s" m_fileName="%d" tSum="3" sourceMsgId="0" url="" flag="3" adverSign="0" multiMsgFlag="0"><item layout="1"><title color="#000000" size="34">%s</title> %s<hr></hr><summary size="26" color="#808080">%s</summary></item><source name="%s"></source></msg>`,
|
||||||
brief, resId, ts, title, preview, summary, source,
|
brief, resId, ts, title, preview, summary, source,
|
||||||
)
|
)
|
||||||
for index, item := range items {
|
for _, item := range items {
|
||||||
if item.GetFileName() == "MultiMsg" {
|
if item.GetFileName() == "MultiMsg" {
|
||||||
items[index].FileName = proto.String(strconv.FormatInt(ts, 10))
|
*item.FileName = strconv.FormatInt(ts, 10)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &message.ForwardElement{
|
return &message.ForwardElement{
|
||||||
ServiceElement: message.ServiceElement{
|
|
||||||
Id: 35,
|
|
||||||
Content: template,
|
Content: template,
|
||||||
ResId: resId,
|
ResId: resId,
|
||||||
SubType: "Forward",
|
|
||||||
},
|
|
||||||
Items: items,
|
Items: items,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,6 +99,10 @@ func (c *QQClient) sendGroupMessage(groupCode int64, forward bool, m *message.Se
|
|||||||
_, ok := e.(*message.GroupVoiceElement)
|
_, ok := e.(*message.GroupVoiceElement)
|
||||||
_, ok2 := e.(*message.ServiceElement)
|
_, ok2 := e.(*message.ServiceElement)
|
||||||
_, ok3 := e.(*message.ReplyElement)
|
_, ok3 := e.(*message.ReplyElement)
|
||||||
|
if _, ok4 := e.(*message.ForwardElement); ok4 {
|
||||||
|
forward = true
|
||||||
|
return true
|
||||||
|
}
|
||||||
return ok || ok2 || ok3
|
return ok || ok2 || ok3
|
||||||
}) {
|
}) {
|
||||||
div := int32(rand.Uint32())
|
div := int32(rand.Uint32())
|
||||||
|
@ -13,6 +13,11 @@ import (
|
|||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
decoders["MultiMsg.ApplyUp"] = decodeMultiApplyUpResponse
|
||||||
|
decoders["MultiMsg.ApplyDown"] = decodeMultiApplyDownResponse
|
||||||
|
}
|
||||||
|
|
||||||
// MultiMsg.ApplyUp
|
// MultiMsg.ApplyUp
|
||||||
func (c *QQClient) buildMultiApplyUpPacket(data, hash []byte, buType int32, groupUin int64) (uint16, []byte) {
|
func (c *QQClient) buildMultiApplyUpPacket(data, hash []byte, buType int32, groupUin int64) (uint16, []byte) {
|
||||||
seq := c.nextSeq()
|
seq := c.nextSeq()
|
||||||
|
@ -103,7 +103,8 @@ type ServiceElement struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ForwardElement struct {
|
type ForwardElement struct {
|
||||||
ServiceElement
|
Content string
|
||||||
|
ResId string
|
||||||
Items []*msg.PbMultiMsgItem
|
Items []*msg.PbMultiMsgItem
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -456,7 +456,7 @@ func ParseMessageElems(elems []*msg.Elem) []IMessageElement {
|
|||||||
reg := regexp.MustCompile(`m_resid="(\w+?.*?)"`)
|
reg := regexp.MustCompile(`m_resid="(\w+?.*?)"`)
|
||||||
sub := reg.FindAllStringSubmatch(content, -1)
|
sub := reg.FindAllStringSubmatch(content, -1)
|
||||||
if len(sub) > 0 && len(sub[0]) > 1 {
|
if len(sub) > 0 && len(sub[0]) > 1 {
|
||||||
res = append(res, &ForwardElement{ServiceElement: ServiceElement{ResId: reg.FindAllStringSubmatch(content, -1)[0][1]}})
|
res = append(res, &ForwardElement{ResId: reg.FindAllStringSubmatch(content, -1)[0][1]})
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ func (e *ForwardElement) Pack() (r []*msg.Elem) {
|
|||||||
r = append(r, &msg.Elem{
|
r = append(r, &msg.Elem{
|
||||||
RichMsg: &msg.RichMsg{
|
RichMsg: &msg.RichMsg{
|
||||||
Template1: append([]byte{1}, binary.ZlibCompress([]byte(e.Content))...),
|
Template1: append([]byte{1}, binary.ZlibCompress([]byte(e.Content))...),
|
||||||
ServiceId: &e.Id,
|
ServiceId: proto.Int32(35),
|
||||||
MsgResId: []byte{},
|
MsgResId: []byte{},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user