diff --git a/.gitignore b/.gitignore index 48b8bf9..31e3ac6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ vendor/ +.idea diff --git a/coolq/cqcode.go b/coolq/cqcode.go index 4d01fd4..cce76d7 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -463,6 +463,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) } diff --git a/docs/cqhttp.md b/docs/cqhttp.md index 8cddcc7..a0f5c42 100644 --- a/docs/cqhttp.md +++ b/docs/cqhttp.md @@ -119,6 +119,51 @@ Type: `node` ] ```` +### xml支持 + +Type: `xml` + +范围: **发送** + +参数: + +| 参数名 | 类型 | 说明 | +| ------ | ------ | ------------------------------------------------------------ | +| data | string | xml内容,xml中的value部分,记得实体化处理| +| resid | int32 | 可以不填| + +示例: `[CQ:xml,data=xxxx]` + +####一些xml样例 +####ps:重要:xml中的value部分,记得html实体化处理后,再打加入到cq码中 +#### qq音乐 +```xml + +``` +#### 网易音乐 +```xml + +``` + +#### 卡片消息1 +```xml + + +生死8秒!女司机高速急刹,他一个操作救下一车性命 + + +``` + +#### 卡片消息2 +```xml + + + +test title + + + +``` ## API diff --git a/global/net.go b/global/net.go index 40aeab8..d3cf1a7 100644 --- a/global/net.go +++ b/global/net.go @@ -3,9 +3,11 @@ package global import ( "bytes" "compress/gzip" + "github.com/Mrs4s/MiraiGo/message" "github.com/tidwall/gjson" "io/ioutil" "net/http" + "strconv" "strings" ) @@ -41,3 +43,19 @@ func QQMusicSongInfo(id string) (gjson.Result, error) { } return gjson.ParseBytes(d).Get("songinfo.data"), nil } + +func NewXmlMsg(template string,ResId int64) *message.ServiceElement{ + var serviceid string + if ResId == 0{ + serviceid ="2" //默认值2 + }else{ + serviceid = strconv.FormatInt(ResId,10) + } + //println(serviceid) + return &message.ServiceElement{ + Id: int32(ResId), + Content: template, + ResId: serviceid, + SubType: "xml", + } +} diff --git a/server/http.go b/server/http.go index 168856b..ad864f5 100644 --- a/server/http.go +++ b/server/http.go @@ -400,6 +400,7 @@ func getParamOrDefault(c *gin.Context, k, def string) string { return def } + func getParam(c *gin.Context, k string) string { p, _ := getParamWithType(c, k) return p