From 03cc0dba9509d3dc044c2ec70c4cdbe4028d83f8 Mon Sep 17 00:00:00 2001 From: scjtqs Date: Mon, 24 Aug 2020 16:01:21 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E5=8A=A8xml=E5=A4=84=E7=90=86?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- coolq/cqcode.go | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/coolq/cqcode.go b/coolq/cqcode.go index f7c6294..d59b097 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -196,22 +196,6 @@ func (bot *CQBot) ConvertStringMessage(m string, group bool) (r []message.IMessa } } } - if(t == "xml"){ - //xml需要实体化,发送的时候不能转回去 - x := make(map[string]string) - //循环遍历Map - for _, p := range ps { - x[p[1]] = p[2] - } - resId := x["resid"] - template := x["data"] - println(template) - i, _ := strconv.ParseInt(resId, 10, 64) - msg :=global.NewXmlMsg(template,i) - r=append(r,msg) - continue - } - elem, err := bot.ToElement(t, d, group) if err != nil { log.Warnf("转换CQ码到MiraiGo Element时出现错误: %v 将原样发送.", err) @@ -252,16 +236,6 @@ func (bot *CQBot) ConvertObjectMessage(m gjson.Result, group bool) (r []message. } } } - if t =="xml"{ - //xml需要实体化,发送的时候不能转回去 - resId := e.Get("data").Get("resid").Str - template := e.Get("data").Get("data").Str - println(template) - i, _ := strconv.ParseInt(resId, 10, 64) - msg :=global.NewXmlMsg(template,i) - r=append(r,msg) - return - } d := make(map[string]string) e.Get("data").ForEach(func(key, value gjson.Result) bool { d[key.Str] = value.Str @@ -483,6 +457,13 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message. }, nil } return nil, errors.New("unsupported music type: " + d["type"]) + case "xml": + resId := d["resid"] + template := CQCodeEscapeValue(d["data"]) + println(template) + i, _ := strconv.ParseInt(resId, 10, 64) + msg :=global.NewXmlMsg(template,i) + return msg,nil default: return nil, errors.New("unsupported cq code: " + t) }