From 566cbd22ddb7b0dbbfd45464e7c3660fdc4ebea8 Mon Sep 17 00:00:00 2001 From: Redmomn <109732988+Redmomn@users.noreply.github.com> Date: Sat, 23 Nov 2024 09:58:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20xml=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- message/build.go | 9 +++++++++ message/elements.go | 23 +++++++++++++++++++++++ message/message.go | 9 +++++++++ 3 files changed, 41 insertions(+) diff --git a/message/build.go b/message/build.go index 268b042..d75a9a5 100644 --- a/message/build.go +++ b/message/build.go @@ -144,6 +144,15 @@ func (e *LightAppElement) BuildElement() []*message.Elem { }} } +func (e *XMLElement) BuildElement() []*message.Elem { + return []*message.Elem{{ + RichMsg: &message.RichMsg{ + ServiceId: proto.Some(int32(e.ServiceID)), + Template1: append([]byte{0x01}, binary.ZlibCompress([]byte(e.Content))...), + }, + }} +} + func (e *ForwardMessage) BuildElement() []*message.Elem { fileID := utils.NewUUID() extra := MultiMsgLightAppExtra{ diff --git a/message/elements.go b/message/elements.go index 9a7dce8..bb6c5e5 100644 --- a/message/elements.go +++ b/message/elements.go @@ -138,6 +138,11 @@ type ( Content string } + XMLElement struct { + ServiceID int + Content string + } + ForwardMessage struct { IsGroup bool SelfID uint32 @@ -333,6 +338,20 @@ func NewLightApp(content string) *LightAppElement { } } +func NewXML(content string) *XMLElement { + return &XMLElement{ + ServiceID: 35, + Content: content, + } +} + +func NewXMLWithID(id int, content string) *XMLElement { + return &XMLElement{ + ServiceID: id, + Content: content, + } +} + func NewForward(resid string, nodes []*ForwardNode) *ForwardMessage { return &ForwardMessage{ ResID: resid, @@ -429,6 +448,10 @@ func (e *LightAppElement) Type() ElementType { return LightApp } +func (e *XMLElement) Type() ElementType { + return Service +} + func (e *ForwardMessage) Type() ElementType { return Forward } diff --git a/message/message.go b/message/message.go index df08dec..fb7282e 100644 --- a/message/message.go +++ b/message/message.go @@ -367,6 +367,15 @@ func ParseMessageElements(msg []*message.Elem) []IMessageElement { }) } + if elem.RichMsg != nil && elem.RichMsg.ServiceId.Unwrap() == 35 { + if elem.RichMsg.Template1 != nil { + res = append(res, &XMLElement{ + ServiceID: 35, + Content: utils.B2S(binary.ZlibUncompress(elem.LightAppElem.Data[1:])), + }) + } + } + if elem.LightAppElem != nil && len(elem.LightAppElem.Data) > 1 { var content []byte if elem.LightAppElem.Data[0] == 0 {