Skip to content

Commit

Permalink
feat: face element
Browse files Browse the repository at this point in the history
  • Loading branch information
JustAnotherID committed Apr 16, 2024
1 parent ed03302 commit b4fcd1e
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 1 deletion.
37 changes: 37 additions & 0 deletions message/elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ type (
SubType AtType
}

FaceElement struct {
FaceID uint16
isLargeFace bool
}

ReplyElement struct {
ReplySeq int32
Sender uint64
Expand Down Expand Up @@ -79,6 +84,10 @@ func (e *AtElement) Type() ElementType {
return At
}

func (e *FaceElement) Type() ElementType {
return Face
}

func (e *GroupImageElement) Type() ElementType {
return Image
}
Expand Down Expand Up @@ -121,6 +130,34 @@ func (e *AtElement) BuildElement() *message.Elem {
}}
}

func (e *FaceElement) BuildElement() *message.Elem {
faceId := int32(e.FaceID)
if e.isLargeFace {
qFace := message.QFaceExtra{
Field1: proto.Some("1"),
Field2: proto.Some("8"),
FaceId: proto.Some(faceId),
Field4: proto.Some(int32(1)),
Field5: proto.Some(int32(1)),
Field6: proto.Some(""),
Preview: proto.Some(""),
Field9: proto.Some(int32(1)),
}
qFaceData, _ := proto.Marshal(&qFace)
return &message.Elem{
CommonElem: &message.CommonElem{
ServiceType: 37,
PbElem: qFaceData,
BusinessType: 1,
},
}
} else {
return &message.Elem{
Face: &message.Face{Index: proto.Some(faceId)},
}
}
}

func (e *GroupImageElement) BuildElement() *message.Elem {
return nil
}
Expand Down
38 changes: 38 additions & 0 deletions message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/LagrangeDev/LagrangeGo/packets/pb/message"
"github.com/LagrangeDev/LagrangeGo/utils/binary"
"github.com/LagrangeDev/LagrangeGo/utils/proto"
)

type IMessage interface {
Expand Down Expand Up @@ -159,6 +160,30 @@ func parseMessageElements(msg []*message.Elem) []IMessageElement {
}
}

if elem.Face != nil {
if len(elem.Face.Old) > 0 {
faceId := elem.Face.Index
if faceId.IsSome() {
res = append(res, &FaceElement{FaceID: uint16(faceId.Unwrap())})
}
} else if elem.CommonElem.ServiceType == 37 && elem.CommonElem.PbElem != nil {
qFace := message.QFaceExtra{}
err := proto.Unmarshal(elem.CommonElem.PbElem, &qFace)
if err == nil {
faceId := qFace.FaceId
if faceId.IsSome() {
res = append(res, &FaceElement{FaceID: uint16(faceId.Unwrap()), isLargeFace: true})
}
}
} else if elem.CommonElem.ServiceType == 33 && elem.CommonElem.PbElem != nil {
qFace := message.QSmallFaceExtra{}
err := proto.Unmarshal(elem.CommonElem.PbElem, &qFace)
if err == nil {
res = append(res, &FaceElement{FaceID: uint16(qFace.FaceId), isLargeFace: false})
}
}
}

if elem.VideoFile != nil {
return []IMessageElement{
&ShortVideoElement{
Expand Down Expand Up @@ -235,6 +260,13 @@ func (msg *GroupMessage) ToString() (res string) {
strBuilder.WriteString("[Reply: ")
strBuilder.WriteString(strconv.FormatInt(int64(e.ReplySeq), 10))
strBuilder.WriteString("]")
case *FaceElement:
strBuilder.WriteString("[Face: ")
strBuilder.WriteString(strconv.FormatInt(int64(e.FaceID), 10))
if e.isLargeFace {
strBuilder.WriteString(", isLargeFace: true]")
}
strBuilder.WriteString("]")
}
}
res = strBuilder.String()
Expand All @@ -250,6 +282,12 @@ func ToReadableString(m []IMessageElement) string {
sb.WriteString("[图片]")
case *AtElement:
sb.WriteString(e.Display)
case *ReplyElement:
sb.WriteString("[回复]")
case *FaceElement:
sb.WriteString("[表情:")
sb.WriteString(strconv.FormatInt(int64(e.FaceID), 10))
sb.WriteString("]")
}
}
return sb.String()
Expand Down
7 changes: 7 additions & 0 deletions packets/pb/message/element.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion packets/pb/message/element.proto
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ message VideoFile {
repeated bytes BytesThumbFileUrls = 20;
repeated bytes BytesVideoFileUrls = 21;
int32 ThumbDownloadFlag = 22;
int32 VideoDownloadFlag =23;
int32 VideoDownloadFlag = 23;
bytes PbReserve = 24;
}

Expand Down Expand Up @@ -386,3 +386,8 @@ message QFaceExtra {
optional int32 Field9 = 9;
}

message QSmallFaceExtra {
uint32 FaceId = 1;
string Preview = 2;
string Preview2 = 3;
}

0 comments on commit b4fcd1e

Please sign in to comment.