55 "strings"
66 "time"
77
8+ "github.com/Mrs4s/MiraiGo/client"
89 "github.com/Mrs4s/MiraiGo/message"
910 "github.com/ProtobufBot/Go-Mirai-Client/pkg/util"
1011 "github.com/ProtobufBot/Go-Mirai-Client/proto_gen/onebot"
@@ -17,7 +18,7 @@ func EmptyText() *message.TextElement {
1718}
1819
1920// 消息列表,不自动把code变成msg
20- func ProtoMsgToMiraiMsg (msgList []* onebot.Message , notConvertText bool ) []message.IMessageElement {
21+ func ProtoMsgToMiraiMsg (cli * client. QQClient , msgList []* onebot.Message , notConvertText bool ) []message.IMessageElement {
2122 containReply := false // 每条消息只能包含一个reply
2223 messageChain := make ([]message.IMessageElement , 0 )
2324 for _ , protoMsg := range msgList {
@@ -31,7 +32,7 @@ func ProtoMsgToMiraiMsg(msgList []*onebot.Message, notConvertText bool) []messag
3132 log .Warnf ("text不存在" )
3233 continue
3334 }
34- messageChain = append (messageChain , RawMsgToMiraiMsg (text )... ) // 转换xml码
35+ messageChain = append (messageChain , RawMsgToMiraiMsg (cli , text )... ) // 转换xml码
3536 }
3637 case "at" :
3738 messageChain = append (messageChain , ProtoAtToMiraiAt (protoMsg .Data ))
@@ -56,6 +57,8 @@ func ProtoMsgToMiraiMsg(msgList []*onebot.Message, notConvertText bool) []messag
5657 }
5758 case "sleep" :
5859 ProtoSleep (protoMsg .Data )
60+ case "tts" :
61+ messageChain = append (messageChain , ProtoTtsToMiraiTts (cli , protoMsg .Data ))
5962 default :
6063 log .Errorf ("不支持的消息类型 %+v" , protoMsg )
6164 }
@@ -274,3 +277,23 @@ func ProtoSleep(data map[string]string) {
274277 }
275278 time .Sleep (time .Duration (ms ) * time .Millisecond )
276279}
280+
281+ func ProtoTtsToMiraiTts (cli * client.QQClient , data map [string ]string ) (m message.IMessageElement ) {
282+ defer func () {
283+ if r := recover (); r != nil {
284+ log .Warnf ("tts 转换失败" )
285+ m = EmptyText ()
286+ }
287+ }()
288+ text , ok := data ["text" ]
289+ if ! ok {
290+ log .Warnf ("text不存在" )
291+ return EmptyText ()
292+ }
293+ b , err := cli .GetTts (text )
294+ if err != nil {
295+ log .Warnf ("failed to get tts" )
296+ return EmptyText ()
297+ }
298+ return & message.VoiceElement {Data : b }
299+ }
0 commit comments