diff --git a/client/packets/pb/message/element.pb.go b/client/packets/pb/message/element.pb.go index eb51242..3564fd9 100644 --- a/client/packets/pb/message/element.pb.go +++ b/client/packets/pb/message/element.pb.go @@ -391,15 +391,16 @@ type MentionExtra struct { } type QFaceExtra struct { - Field1 proto.Option[string] `protobuf:"bytes,1,opt"` - Field2 proto.Option[string] `protobuf:"bytes,2,opt"` - FaceId proto.Option[int32] `protobuf:"varint,3,opt"` - Field4 proto.Option[int32] `protobuf:"varint,4,opt"` - Field5 proto.Option[int32] `protobuf:"varint,5,opt"` - Field6 proto.Option[string] `protobuf:"bytes,6,opt"` - Preview proto.Option[string] `protobuf:"bytes,7,opt"` - Field9 proto.Option[int32] `protobuf:"varint,9,opt"` - _ [0]func() + PackId proto.Option[string] `protobuf:"bytes,1,opt"` + StickerId proto.Option[string] `protobuf:"bytes,2,opt"` + Qsid proto.Option[int32] `protobuf:"varint,3,opt"` + SourceType proto.Option[int32] `protobuf:"varint,4,opt"` + StickerType proto.Option[int32] `protobuf:"varint,5,opt"` + ResultId proto.Option[string] `protobuf:"bytes,6,opt"` + Text proto.Option[string] `protobuf:"bytes,7,opt"` + // optional bytes surprise_id = 8; + RandomType proto.Option[int32] `protobuf:"varint,9,opt"` + _ [0]func() } type QSmallFaceExtra struct { diff --git a/client/packets/pb/message/element.proto b/client/packets/pb/message/element.proto index c7bce3f..5f04398 100644 --- a/client/packets/pb/message/element.proto +++ b/client/packets/pb/message/element.proto @@ -403,14 +403,15 @@ 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 { @@ -418,3 +419,4 @@ message QSmallFaceExtra { string Preview = 2; string Preview2 = 3; } + diff --git a/message/build.go b/message/build.go index 166712b..09ab286 100644 --- a/message/build.go +++ b/message/build.go @@ -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, @@ -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))}, }} } } diff --git a/message/elements.go b/message/elements.go index d0c490d..5486a1c 100644 --- a/message/elements.go +++ b/message/elements.go @@ -5,6 +5,7 @@ package message import ( "bytes" "encoding/base64" + "fmt" "io" "os" "path/filepath" @@ -35,6 +36,7 @@ type ( FaceElement struct { FaceID uint16 + ResultID uint16 // 猜拳和骰子的值 isLargeFace bool } @@ -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 } diff --git a/message/message.go b/message/message.go index 8602043..9540f98 100644 --- a/message/message.go +++ b/message/message.go @@ -6,6 +6,7 @@ import ( "encoding/xml" "fmt" "reflect" + "strconv" "strings" oidb2 "github.com/LagrangeDev/LagrangeGo/client/packets/pb/service/oidb" @@ -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 { @@ -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, + }) } }