Skip to content

Commit

Permalink
perf: 表情字段类型更换为uint32
Browse files Browse the repository at this point in the history
  • Loading branch information
Redmomn committed Jan 23, 2025
1 parent fca3411 commit 8f4b374
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion client/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ func (c *QQClient) FetchEssenceMessage(groupUin uint32) ([]*message2.GroupEssenc
case 1:
elements = append(elements, &message2.TextElement{Content: e.Get("text").String()})
case 2:
elements = append(elements, &message2.FaceElement{FaceID: uint16(e.Get("face_index").Int())})
elements = append(elements, &message2.FaceElement{FaceID: uint32(e.Get("face_index").Int())})
case 3:
elements = append(elements, &message2.ImageElement{URL: e.Get("image_url").String()})
case 4:
Expand Down
14 changes: 7 additions & 7 deletions message/elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ type (
}

FaceElement struct {
FaceID uint16
ResultID uint16 // 猜拳和骰子的值
FaceID uint32
ResultID uint32 // 猜拳和骰子的值
isLargeFace bool
}

Expand Down Expand Up @@ -371,13 +371,13 @@ func NewForwardWithNodes(nodes []*ForwardNode) *ForwardMessage {
}
}

func NewFace(id uint16) *FaceElement {
func NewFace(id uint32) *FaceElement {
return &FaceElement{FaceID: id}
}

func NewDice(value uint16) *FaceElement {
func NewDice(value uint32) *FaceElement {
if value > 6 {
value = uint16(crypto.RandU32()%3) + 1
value = crypto.RandU32()%3 + 1
}
return &FaceElement{
FaceID: 358,
Expand All @@ -386,7 +386,7 @@ func NewDice(value uint16) *FaceElement {
}
}

type FingerGuessingType uint16
type FingerGuessingType uint32

const (
FingerGuessingRock FingerGuessingType = 3 // 石头
Expand All @@ -409,7 +409,7 @@ func (m FingerGuessingType) String() string {
func NewFingerGuessing(value FingerGuessingType) *FaceElement {
return &FaceElement{
FaceID: 359,
ResultID: uint16(value),
ResultID: uint32(value),
isLargeFace: true,
}
}
Expand Down
12 changes: 6 additions & 6 deletions message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,20 @@ func ParseMessageElements(msg []*message.Elem) []IMessageElement {
case len(elem.Face.Old) > 0:
faceID := elem.Face.Index
if faceID.IsSome() {
res = append(res, &FaceElement{FaceID: uint16(faceID.Unwrap())})
res = append(res, &FaceElement{FaceID: uint32(faceID.Unwrap())})
}
case elem.CommonElem != nil && elem.CommonElem.ServiceType == 37 && elem.CommonElem.PbElem != nil:
qFace := message.QFaceExtra{}
if err := proto.Unmarshal(elem.CommonElem.PbElem, &qFace); err == nil {
if qFace.Qsid.IsSome() {
res = append(res, &FaceElement{FaceID: uint16(qFace.Qsid.Unwrap()), isLargeFace: true})
res = append(res, &FaceElement{FaceID: uint32(qFace.Qsid.Unwrap()), isLargeFace: true})
}
}
case elem.CommonElem != nil && 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})
res = append(res, &FaceElement{FaceID: qFace.FaceId, isLargeFace: false})
}
}
}
Expand Down Expand Up @@ -337,14 +337,14 @@ func ParseMessageElements(msg []*message.Elem) []IMessageElement {
case 33:
var newSysFaceMsg message.QSmallFaceExtra
_ = proto.Unmarshal(elem.CommonElem.PbElem, &newSysFaceMsg)
res = append(res, NewFace(uint16(newSysFaceMsg.FaceId)))
res = append(res, NewFace(newSysFaceMsg.FaceId))
case 37:
var faceExtra message.QFaceExtra
_ = proto.Unmarshal(elem.CommonElem.PbElem, &faceExtra)
result, _ := strconv.ParseInt(faceExtra.ResultId.Unwrap(), 10, 32)
res = append(res, &FaceElement{
FaceID: uint16(faceExtra.Qsid.Unwrap()),
ResultID: uint16(result),
FaceID: uint32(faceExtra.Qsid.Unwrap()),
ResultID: uint32(result),
isLargeFace: true,
}) // sticker 永远为单独消息
skipNext = true
Expand Down

0 comments on commit 8f4b374

Please sign in to comment.