Skip to content

Commit

Permalink
add 发送猜拳和骰子消息,解析animatedStickerMsg (#107)
Browse files Browse the repository at this point in the history
* add 发送猜拳和骰子

* code type

* fix: ci, no value of type uint16 is less than 0
  • Loading branch information
icarus-ai authored Oct 20, 2024
1 parent 971534c commit 3de1816
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 34 deletions.
19 changes: 10 additions & 9 deletions client/packets/pb/message/element.pb.go

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

18 changes: 10 additions & 8 deletions client/packets/pb/message/element.proto
Original file line number Diff line number Diff line change
Expand Up @@ -403,18 +403,20 @@ message MentionExtra {
}

message QFaceExtra {
optional string Field1 = 1;
optional string Field2 = 2;
optional int32 FaceId = 3;
optional int32 Field4 = 4;
optional int32 Field5 = 5;
optional string Field6 = 6;
optional string Preview = 7;
optional int32 Field9 = 9;
optional string PackId = 1;
optional string StickerId = 2;
optional int32 Qsid = 3;
optional int32 SourceType = 4;
optional int32 StickerType = 5;
optional string ResultId = 6;
optional string Text = 7;
//optional bytes SurpriseId = 8;
optional int32 RandomType = 9;
}

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

30 changes: 18 additions & 12 deletions message/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,25 @@ 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)),
name, business, resultid := "", int32(1), ""
if e.FaceID == 358 {
name, business = "/骰子", 2
resultid = fmt.Sprint(e.ResultID)
} else if e.FaceID == 359 {
name, business = "/包剪锤", 2
resultid = fmt.Sprint(e.ResultID)
}
qFaceData, _ := proto.Marshal(&qFace)
qFaceData, _ := proto.Marshal(&message.QFaceExtra{
PackId: proto.Some("1"),
StickerId: proto.Some("8"),
Qsid: proto.Some(int32(e.FaceID)),
SourceType: proto.Some(int32(1)),
StickerType: proto.Some(business),
ResultId: proto.Some(resultid),
Text: proto.Some(name),
RandomType: proto.Some(int32(1)),
})
return []*message.Elem{{
CommonElem: &message.CommonElem{
ServiceType: 37,
Expand All @@ -60,7 +66,7 @@ func (e *FaceElement) BuildElement() []*message.Elem {
}}
} else {
return []*message.Elem{{
Face: &message.Face{Index: proto.Some(faceId)},
Face: &message.Face{Index: proto.Some(int32(e.FaceID))},
}}
}
}
Expand Down
45 changes: 45 additions & 0 deletions message/elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package message
import (
"bytes"
"encoding/base64"
"fmt"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -35,6 +36,7 @@ type (

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

Expand Down Expand Up @@ -351,6 +353,49 @@ func NewForwardWithNodes(nodes []*ForwardNode) *ForwardMessage {
}
}

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

func NewDice(value uint16) *FaceElement {
if value > 6 {
value = uint16(crypto.RandU32()%3) + 1
}
return &FaceElement{
FaceID: 358,
ResultID: value,
isLargeFace: true,
}
}

type FingerGuessingType uint16

const (
FingerGuessingRock FingerGuessingType = 3 // 石头
FingerGuessingScissors FingerGuessingType = 2 // 剪刀
FingerGuessingPaper FingerGuessingType = 1 // 布
)

func (m FingerGuessingType) String() string {
switch m {
case FingerGuessingRock:
return "石头"
case FingerGuessingScissors:
return "剪刀"
case FingerGuessingPaper:
return "布"
}
return fmt.Sprint(int(m))
}

func NewFingerGuessing(value FingerGuessingType) *FaceElement {
return &FaceElement{
FaceID: 359,
ResultID: uint16(value),
isLargeFace: true,
}
}

func (e *TextElement) Type() ElementType {
return Text
}
Expand Down
18 changes: 13 additions & 5 deletions message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/xml"
"fmt"
"reflect"
"strconv"
"strings"

oidb2 "github.com/LagrangeDev/LagrangeGo/client/packets/pb/service/oidb"
Expand Down Expand Up @@ -196,11 +197,9 @@ func ParseMessageElements(msg []*message.Elem) []IMessageElement {
}
} else if elem.CommonElem != nil && 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})
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})
}
}
} else if elem.CommonElem != nil && elem.CommonElem.ServiceType == 33 && elem.CommonElem.PbElem != nil {
Expand Down Expand Up @@ -334,6 +333,15 @@ func ParseMessageElements(msg []*message.Elem) []IMessageElement {
Url: fmt.Sprintf("http://gchat.qpic.cn/gchatpic_new/0/0-0-%X/0", img.PicMd5),
})
skipNext = true
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),
isLargeFace: true,
})
}
}

Expand Down

0 comments on commit 3de1816

Please sign in to comment.