1
0
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:
wdvxdr 2020-12-31 16:01:13 +08:00
parent dd94cc86c5
commit b58629ffbf
7 changed files with 62 additions and 28 deletions

View File

@ -9,6 +9,7 @@ import (
"github.com/Mrs4s/MiraiGo/binary/jce"
"image"
"io"
"math"
"math/rand"
"net"
"runtime/debug"
@ -137,8 +138,6 @@ var decoders = map[string]func(*QQClient, uint16, []byte) (interface{}, error){
"LongConn.OffPicUp": decodeOffPicUpResponse,
"ProfileService.Pb.ReqSystemMsgNew.Group": decodeSystemMsgGroupPacket,
"ProfileService.Pb.ReqSystemMsgNew.Friend": decodeSystemMsgFriendPacket,
"MultiMsg.ApplyUp": decodeMultiApplyUpResponse,
"MultiMsg.ApplyDown": decodeMultiApplyDownResponse,
"OidbSvc.0xe07_0": decodeImageOcrResponse,
"OidbSvc.0xd79": decodeWordSegmentation,
"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 {
i, err := c.sendAndWait(c.buildMultiApplyDownPacket(resId))
if err != nil {
m := c.DownloadForwardMessage(resId)
if m == nil {
return nil
}
multiMsg := i.(*msg.PbMultiMsgTransmit)
ret := &message.ForwardMessage{}
if multiMsg.GetPbItemList() == nil {
return nil
}
var item *msg.PbMultiMsgItem
for _, m := range multiMsg.GetPbItemList() {
if m.GetFileName() == "MultiMsg" {
item = m
break
var (
item *msg.PbMultiMsgItem
ret = &message.ForwardMessage{Nodes: []*message.ForwardNode{}}
)
for _, iter := range m.Items {
if iter.GetFileName() == "MultiMsg" {
item = iter
}
}
if item == nil || item.GetBuffer() == nil || item.GetBuffer().GetMsg() == nil {
if item == nil {
return nil
}
for _, m := range item.GetBuffer().GetMsg() {
@ -538,6 +534,38 @@ func (c *QQClient) GetForwardMessage(resId string) *message.ForwardMessage {
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) {
_, _ = c.sendAndWait(c.buildGroupPokePacket(groupCode, target))
}

View File

@ -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>`,
brief, resId, ts, title, preview, summary, source,
)
for index, item := range items {
for _, item := range items {
if item.GetFileName() == "MultiMsg" {
items[index].FileName = proto.String(strconv.FormatInt(ts, 10))
*item.FileName = strconv.FormatInt(ts, 10)
}
}
return &message.ForwardElement{
ServiceElement: message.ServiceElement{
Id: 35,
Content: template,
ResId: resId,
SubType: "Forward",
},
Items: items,
}
}

View File

@ -99,6 +99,10 @@ func (c *QQClient) sendGroupMessage(groupCode int64, forward bool, m *message.Se
_, ok := e.(*message.GroupVoiceElement)
_, ok2 := e.(*message.ServiceElement)
_, ok3 := e.(*message.ReplyElement)
if _, ok4 := e.(*message.ForwardElement); ok4 {
forward = true
return true
}
return ok || ok2 || ok3
}) {
div := int32(rand.Uint32())

View File

@ -13,6 +13,11 @@ import (
"google.golang.org/protobuf/proto"
)
func init() {
decoders["MultiMsg.ApplyUp"] = decodeMultiApplyUpResponse
decoders["MultiMsg.ApplyDown"] = decodeMultiApplyDownResponse
}
// MultiMsg.ApplyUp
func (c *QQClient) buildMultiApplyUpPacket(data, hash []byte, buType int32, groupUin int64) (uint16, []byte) {
seq := c.nextSeq()

View File

@ -103,7 +103,8 @@ type ServiceElement struct {
}
type ForwardElement struct {
ServiceElement
Content string
ResId string
Items []*msg.PbMultiMsgItem
}

View File

@ -456,7 +456,7 @@ func ParseMessageElems(elems []*msg.Elem) []IMessageElement {
reg := regexp.MustCompile(`m_resid="(\w+?.*?)"`)
sub := reg.FindAllStringSubmatch(content, -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
}
}

View File

@ -153,7 +153,7 @@ func (e *ForwardElement) Pack() (r []*msg.Elem) {
r = append(r, &msg.Elem{
RichMsg: &msg.RichMsg{
Template1: append([]byte{1}, binary.ZlibCompress([]byte(e.Content))...),
ServiceId: &e.Id,
ServiceId: proto.Int32(35),
MsgResId: []byte{},
},
})