Skip to content

Commit 17e2d0e

Browse files
committed
service msg
1 parent 957916d commit 17e2d0e

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

service/bot/mirai2raw.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func MiraiMsgToRawMsg(messageChain []message.IMessageElement) string {
2222
case *message.VoiceElement:
2323
result += fmt.Sprintf(`<voice url="%s"/>`, html.EscapeString(elem.Url))
2424
case *message.ServiceElement:
25-
result += fmt.Sprintf(`<service id="%d" content="%s" res_id="%d" sub_type="%s"/>`, elem.Id, html.EscapeString(elem.Content), elem.ResId, elem.SubType)
25+
result += fmt.Sprintf(`<service id="%d" content="%s" res_id="%s" sub_type="%s"/>`, elem.Id, html.EscapeString(elem.Content), elem.ResId, elem.SubType)
2626
case *message.LightAppElement:
2727
result += fmt.Sprintf(`<light_app content="%s"/>`, html.EscapeString(elem.Content))
2828
case *message.ShortVideoElement:

service/bot/proto2mirai.go

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package bot
22

33
import (
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+
}

service/bot/raw2mirai.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ func RawMsgToMiraiMsg(str string) []message.IMessageElement {
6161
elemList = append(elemList, ProtoTextToMiraiText(attrMap))
6262
case "light_app":
6363
elemList = append(elemList, ProtoLightAppToMiraiLightApp(attrMap))
64+
case "service":
65+
elemList = append(elemList, ProtoServiceToMiraiService(attrMap))
6466
default:
6567
log.Warnf("不支持的类型 %s", code)
6668
elemList = append(elemList, message.NewText(code))

0 commit comments

Comments
 (0)