MCPcopy Create free account
hub / github.com/LagrangeDev/LagrangeGo / ParseMessageElements

Function ParseMessageElements

message/message.go:144–437  ·  view source on GitHub ↗
(msg []*message.Elem)

Source from the content-addressed store, hash-verified

142}
143
144func ParseMessageElements(msg []*message.Elem) []IMessageElement {
145 var res []IMessageElement
146 skipNext := false
147
148 for _, elem := range msg {
149 if skipNext {
150 skipNext = false
151 continue
152 }
153 if elem.SrcMsg != nil && len(elem.SrcMsg.OrigSeqs) != 0 {
154 res = append(res, &ReplyElement{
155 ReplySeq: elem.SrcMsg.OrigSeqs[0],
156 Time: uint32(elem.SrcMsg.Time.Unwrap()),
157 SenderUin: uint32(elem.SrcMsg.SenderUin),
158 GroupUin: uint32(elem.SrcMsg.ToUin.Unwrap()),
159 Elements: ParseMessageElements(elem.SrcMsg.Elems),
160 })
161 }
162
163 if elem.Text != nil {
164 if len(elem.Text.Attr6Buf) > 0 {
165 att6 := binary.NewReader(elem.Text.Attr6Buf)
166 att6.SkipBytes(7)
167 target := att6.ReadU32()
168 at := NewAt(target, elem.Text.Str.Unwrap())
169 at.SubType = AtTypeGroupMember
170 res = append(res, at)
171 } else {
172 res = append(res, NewText(func() string {
173 if strings.Contains(elem.Text.Str.Unwrap(), "\r") && !strings.Contains(elem.Text.Str.Unwrap(), "\r\n") {
174 return strings.ReplaceAll(elem.Text.Str.Unwrap(), "\r", "\r\n")
175 }
176 return elem.Text.Str.Unwrap()
177 }()))
178 }
179 }
180
181 if elem.Face != nil {
182 if len(elem.Face.Old) > 0 {
183 faceID := elem.Face.Index
184 if faceID.IsSome() {
185 res = append(res, &FaceElement{FaceID: uint32(faceID.Unwrap())})
186 }
187 } else if elem.CommonElem != nil && elem.CommonElem.PbElem != nil {
188 if elem.CommonElem.ServiceType == 37 {
189 qFace := message.QFaceExtra{}
190 if err := proto.Unmarshal(elem.CommonElem.PbElem, &qFace); err == nil {
191 if qFace.Qsid.IsSome() {
192 res = append(res, &FaceElement{FaceID: uint32(qFace.Qsid.Unwrap()), isLargeFace: true})
193 }
194 }
195 } else if elem.CommonElem.ServiceType == 33 {
196 qFace := message.QSmallFaceExtra{}
197 err := proto.Unmarshal(elem.CommonElem.PbElem, &qFace)
198 if err == nil {
199 res = append(res, &FaceElement{FaceID: qFace.FaceId, isLargeFace: false})
200 }
201 }

Callers 3

ParsePrivateMessageFunction · 0.85
ParseGroupMessageFunction · 0.85
ParseTempMessageFunction · 0.85

Calls 15

SkipBytesMethod · 0.95
ReadU32Method · 0.95
ReadUvarintMethod · 0.95
ReadBytesMethod · 0.95
ReadBytesWithLengthMethod · 0.95
NewReaderFunction · 0.92
UnmarshalFunction · 0.92
TernaryFunction · 0.92
MustParseHexStrFunction · 0.92
ZlibUncompressFunction · 0.92
B2SFunction · 0.92
NewAtFunction · 0.85

Tested by

no test coverage detected