77 "github.com/Mrs4s/MiraiGo/message"
88 "github.com/ProtobufBot/Go-Mirai-Client/pkg/util"
99 "github.com/ProtobufBot/Go-Mirai-Client/proto_gen/onebot"
10+ "github.com/ProtobufBot/Go-Mirai-Client/service/cache"
1011 log "github.com/sirupsen/logrus"
1112)
1213
@@ -16,6 +17,7 @@ func EmptyText() *message.TextElement {
1617
1718// 消息列表,不自动把code变成msg
1819func ProtoMsgToMiraiMsg (msgList []* onebot.Message , notConvertText bool ) []message.IMessageElement {
20+ containReply := false // 每条消息只能包含一个reply
1921 messageChain := make ([]message.IMessageElement , 0 )
2022 for _ , protoMsg := range msgList {
2123 switch protoMsg .Type {
@@ -46,6 +48,11 @@ func ProtoMsgToMiraiMsg(msgList []*onebot.Message, notConvertText bool) []messag
4648 messageChain = append (messageChain , ProtoLightAppToMiraiLightApp (protoMsg .Data ))
4749 case "service" :
4850 messageChain = append (messageChain , ProtoServiceToMiraiService (protoMsg .Data ))
51+ case "reply" :
52+ if replyElement := ProtoReplyToMiraiReply (protoMsg .Data ); replyElement != nil && ! containReply {
53+ containReply = true
54+ messageChain = append ([]message.IMessageElement {replyElement }, messageChain ... )
55+ }
4956 default :
5057 log .Errorf ("不支持的消息类型 %+v" , protoMsg )
5158 }
@@ -195,3 +202,40 @@ func ProtoServiceToMiraiService(data map[string]string) message.IMessageElement
195202 SubType : subType ,
196203 }
197204}
205+
206+ func ProtoReplyToMiraiReply (data map [string ]string ) * message.ReplyElement {
207+ messageIdStr , ok := data ["message_id" ]
208+ if ! ok {
209+ return nil
210+ }
211+ messageIdInt , err := strconv .Atoi (messageIdStr )
212+ if err != nil {
213+ return nil
214+ }
215+ messageId := int32 (messageIdInt )
216+ eventInterface , ok := cache .GroupMessageLru .Get (messageId )
217+ if ok {
218+ groupMessage , ok := eventInterface .(* message.GroupMessage )
219+ if ok {
220+ return & message.ReplyElement {
221+ ReplySeq : groupMessage .Id ,
222+ Sender : groupMessage .Sender .Uin ,
223+ Time : groupMessage .Time ,
224+ Elements : groupMessage .Elements ,
225+ }
226+ }
227+ }
228+ eventInterface , ok = cache .PrivateMessageLru .Get (messageId )
229+ if ok {
230+ privateMessage , ok := eventInterface .(* message.PrivateMessage )
231+ if ok {
232+ return & message.ReplyElement {
233+ ReplySeq : privateMessage .Id ,
234+ Sender : privateMessage .Sender .Uin ,
235+ Time : privateMessage .Time ,
236+ Elements : privateMessage .Elements ,
237+ }
238+ }
239+ }
240+ return nil
241+ }
0 commit comments