From 173f3b6369a81b09023e84b6ea9080061b2a06aa Mon Sep 17 00:00:00 2001
From: lz1998 <875543533@qq.com>
Date: Sat, 18 Dec 2021 18:42:20 +0800
Subject: [PATCH] finger guessing
---
go.mod | 2 +-
go.sum | 4 ++--
pkg/bot/mirai2proto.go | 12 ++++++++++++
pkg/bot/mirai2raw.go | 2 ++
pkg/bot/proto2mirai.go | 14 ++++++++++++++
pkg/bot/raw2mirai.go | 2 ++
6 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/go.mod b/go.mod
index d6f08b3..c87c0be 100644
--- a/go.mod
+++ b/go.mod
@@ -3,7 +3,7 @@ module github.com/ProtobufBot/Go-Mirai-Client
go 1.17
require (
- github.com/Mrs4s/MiraiGo v0.0.0-20211218073652-950567e4b77a
+ github.com/Mrs4s/MiraiGo v0.0.0-20211218093950-72ffc08b72ac
github.com/fanliao/go-promise v0.0.0-20141029170127-1890db352a72
github.com/gin-gonic/gin v1.7.2
github.com/go-playground/validator/v10 v10.8.0 // indirect
diff --git a/go.sum b/go.sum
index ca8b1d3..9ecbace 100644
--- a/go.sum
+++ b/go.sum
@@ -1,5 +1,5 @@
-github.com/Mrs4s/MiraiGo v0.0.0-20211218073652-950567e4b77a h1:luE4izN3BxycpMafSBY0HQHw66isocQCpIWyEBehb14=
-github.com/Mrs4s/MiraiGo v0.0.0-20211218073652-950567e4b77a/go.mod h1:HI05ardsa5HE1Z2xTw69dytmaqqRWv4ajD5Jpnycqqw=
+github.com/Mrs4s/MiraiGo v0.0.0-20211218093950-72ffc08b72ac h1:YYOJTY+L8ttv9CFUkcmZ+3V7n8rdRGrelfSZWdL+7VA=
+github.com/Mrs4s/MiraiGo v0.0.0-20211218093950-72ffc08b72ac/go.mod h1:HI05ardsa5HE1Z2xTw69dytmaqqRWv4ajD5Jpnycqqw=
github.com/RomiChan/protobuf v0.0.0-20211204042931-ff4f35848737 h1:p4o7/eSoP39jwnGZz08N1IpH/mNzg9SdCn7kPM9A9BE=
github.com/RomiChan/protobuf v0.0.0-20211204042931-ff4f35848737/go.mod h1:CKKOWC7mBxd36zxsCB1V8DTrwlTNRQvkSVbYqyUiGEE=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
diff --git a/pkg/bot/mirai2proto.go b/pkg/bot/mirai2proto.go
index f8d2b9c..013baaa 100644
--- a/pkg/bot/mirai2proto.go
+++ b/pkg/bot/mirai2proto.go
@@ -20,6 +20,8 @@ func MiraiMsgToProtoMsg(cli *client.QQClient, messageChain []message.IMessageEle
msgList = append(msgList, MiraiAtToProtoAt(elem))
case *message.DiceElement:
msgList = append(msgList, MiraiDiceToProtoDice(elem))
+ case *message.FingerGuessingElement:
+ msgList = append(msgList, MiraiFingerGuessingToProtoFingerGuessing(elem))
case *message.FriendImageElement:
msgList = append(msgList, MiraiFriendImageToProtoImage(elem))
case *message.GroupImageElement:
@@ -119,6 +121,16 @@ func MiraiDiceToProtoDice(elem *message.DiceElement) *onebot.Message {
}
}
+func MiraiFingerGuessingToProtoFingerGuessing(elem *message.FingerGuessingElement) *onebot.Message {
+ return &onebot.Message{
+ Type: "finger_guessing",
+ Data: map[string]string{
+ "value": strconv.FormatInt(int64(elem.Value), 10),
+ "name": elem.Name,
+ },
+ }
+}
+
func MiraiFaceToProtoFace(elem *message.FaceElement) *onebot.Message {
return &onebot.Message{
Type: "face",
diff --git a/pkg/bot/mirai2raw.go b/pkg/bot/mirai2raw.go
index 7de5693..aaa3802 100644
--- a/pkg/bot/mirai2raw.go
+++ b/pkg/bot/mirai2raw.go
@@ -20,6 +20,8 @@ func MiraiMsgToRawMsg(cli *client.QQClient, messageChain []message.IMessageEleme
result += fmt.Sprintf(``, elem.Target)
case *message.DiceElement:
result += fmt.Sprintf(``, elem.Value)
+ case *message.FingerGuessingElement:
+ result += fmt.Sprintf(``, elem.Value, elem.Name)
case *message.FriendImageElement:
result += fmt.Sprintf(``, html.EscapeString(elem.ImageId), html.EscapeString(elem.Url))
case *message.GroupImageElement:
diff --git a/pkg/bot/proto2mirai.go b/pkg/bot/proto2mirai.go
index c9e127d..78430b7 100644
--- a/pkg/bot/proto2mirai.go
+++ b/pkg/bot/proto2mirai.go
@@ -45,6 +45,8 @@ func ProtoMsgToMiraiMsg(cli *client.QQClient, msgList []*onebot.Message, notConv
messageChain = append(messageChain, ProtoAtToMiraiAt(protoMsg.Data))
case "dice":
messageChain = append(messageChain, ProtoDiceToMiraiDice(protoMsg.Data))
+ case "finger_guessing":
+ messageChain = append(messageChain, ProtoFingerGuessingToMiraiFingerGuessing(protoMsg.Data))
case "poke":
messageChain = append(messageChain, ProtoPokeToMiraiPoke(protoMsg.Data))
case "image":
@@ -181,6 +183,18 @@ func ProtoDiceToMiraiDice(data map[string]string) message.IMessageElement {
return message.NewDice(value)
}
+func ProtoFingerGuessingToMiraiFingerGuessing(data map[string]string) message.IMessageElement {
+ value := int32(rand.Intn(2))
+ valueStr, ok := data["value"]
+ if ok {
+ v, err := strconv.ParseInt(valueStr, 10, 64)
+ if err == nil && v >= 0 && v <= 2 {
+ value = int32(v)
+ }
+ }
+ return message.NewFingerGuessing(value)
+}
+
func ProtoPokeToMiraiPoke(data map[string]string) message.IMessageElement {
qq, ok := data["qq"]
if !ok {
diff --git a/pkg/bot/raw2mirai.go b/pkg/bot/raw2mirai.go
index ba06b39..b98443a 100644
--- a/pkg/bot/raw2mirai.go
+++ b/pkg/bot/raw2mirai.go
@@ -49,6 +49,8 @@ func RawMsgToMiraiMsg(cli *client.QQClient, str string) []message.IMessageElemen
elemList = append(elemList, ProtoAtToMiraiAt(attrMap))
case "dice":
elemList = append(elemList, ProtoDiceToMiraiDice(attrMap))
+ case "finger_guessing":
+ elemList = append(elemList, ProtoFingerGuessingToMiraiFingerGuessing(attrMap))
case "poke":
elemList = append(elemList, ProtoPokeToMiraiPoke(attrMap))
case "img":