11package bot
22
33import (
4- "html"
54 "strconv"
65 "strings"
76
@@ -45,6 +44,8 @@ func ProtoMsgToMiraiMsg(msgList []*onebot.Message, notConvertText bool) []messag
4544 messageChain = append (messageChain , ProtoShareToMiraiShare (protoMsg .Data ))
4645 case "light_app" :
4746 messageChain = append (messageChain , ProtoLightAppToMiraiLightApp (protoMsg .Data ))
47+ case "service" :
48+ messageChain = append (messageChain , ProtoServiceToMiraiService (protoMsg .Data ))
4849 default :
4950 log .Errorf ("不支持的消息类型 %+v" , protoMsg )
5051 }
@@ -73,7 +74,6 @@ func ProtoImageToMiraiImage(data map[string]string) message.IMessageElement {
7374 log .Warnf ("imageUrl不存在" )
7475 return EmptyText ()
7576 }
76- url = html .UnescapeString (url )
7777 log .Infof ("下载图片: %+v" , url )
7878 b , err := util .GetBytes (url )
7979 if err != nil {
@@ -92,7 +92,6 @@ func ProtoVoiceToMiraiVoice(data map[string]string) message.IMessageElement {
9292 log .Warnf ("recordUrl不存在" )
9393 return EmptyText ()
9494 }
95- url = html .UnescapeString (url )
9695 b , err := util .GetBytes (url )
9796 if err != nil {
9897 log .Errorf ("下载语音失败" )
@@ -163,3 +162,36 @@ func ProtoLightAppToMiraiLightApp(data map[string]string) message.IMessageElemen
163162 }
164163 return message .NewLightApp (content )
165164}
165+
166+ func ProtoServiceToMiraiService (data map [string ]string ) message.IMessageElement {
167+ subType , ok := data ["sub_type" ]
168+ if ! ok || subType == "" {
169+ log .Warnf ("service sub_type不存在" )
170+ return EmptyText ()
171+ }
172+
173+ content , ok := data ["content" ]
174+ if ! ok {
175+ log .Warnf ("service content不存在" )
176+ return EmptyText ()
177+ }
178+
179+ id , ok := data ["id" ]
180+ if ! ok {
181+ id = ""
182+ }
183+ resId , err := strconv .ParseInt (id , 10 , 64 )
184+ if err != nil || resId == 0 {
185+ if subType == "xml" {
186+ resId = 60 // xml默认60
187+ } else {
188+ resId = 1 // json默认1
189+ }
190+ }
191+
192+ return & message.ServiceElement {
193+ Id : int32 (resId ),
194+ Content : content ,
195+ SubType : subType ,
196+ }
197+ }
0 commit comments