mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-05 03:23:49 +08:00
添加 [CQ:json,data={json代码}]的支持
This commit is contained in:
parent
e319f2645e
commit
fc18b84d4b
@ -470,6 +470,9 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
|
|||||||
i, _ := strconv.ParseInt(resId, 10, 64)
|
i, _ := strconv.ParseInt(resId, 10, 64)
|
||||||
msg := global.NewXmlMsg(template, i)
|
msg := global.NewXmlMsg(template, i)
|
||||||
return msg, nil
|
return msg, nil
|
||||||
|
case "json":
|
||||||
|
msg := global.NewJsonMsg(d["data"])
|
||||||
|
return msg, nil
|
||||||
default:
|
default:
|
||||||
return nil, errors.New("unsupported cq code: " + t)
|
return nil, errors.New("unsupported cq code: " + t)
|
||||||
}
|
}
|
||||||
|
@ -135,8 +135,11 @@ Type: `xml`
|
|||||||
示例: `[CQ:xml,data=xxxx]`
|
示例: `[CQ:xml,data=xxxx]`
|
||||||
|
|
||||||
####一些xml样例
|
####一些xml样例
|
||||||
|
|
||||||
####ps:重要:xml中的value部分,记得html实体化处理后,再打加入到cq码中
|
####ps:重要:xml中的value部分,记得html实体化处理后,再打加入到cq码中
|
||||||
|
|
||||||
#### qq音乐
|
#### qq音乐
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="2" templateID="1" action="web" brief="[分享] 十年" sourceMsgId="0" url="https://i.y.qq.com/v8/playsong.html?_wv=1&songid=4830342&souce=qqshare&source=qqshare&ADTAG=qqshare" flag="0" adverSign="0" multiMsgFlag="0" ><item layout="2"><audio cover="http://imgcache.qq.com/music/photo/album_500/26/500_albumpic_89526_0.jpg" src="http://ws.stream.qqmusic.qq.com/C400003mAan70zUy5O.m4a?guid=1535153710&vkey=D5315B8C0603653592AD4879A8A3742177F59D582A7A86546E24DD7F282C3ACF81526C76E293E57EA1E42CF19881C561275D919233333ADE&uin=&fromtag=3" /><title>十年</title><summary>陈奕迅</summary></item><source name="QQ音乐" icon="https://i.gtimg.cn/open/app_icon/01/07/98/56/1101079856_100_m.png" url="http://web.p.qq.com/qqmpmobile/aio/app.html?id=1101079856" action="app" a_actionData="com.tencent.qqmusic" i_actionData="tencent1101079856://" appid="1101079856" /></msg>
|
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="2" templateID="1" action="web" brief="[分享] 十年" sourceMsgId="0" url="https://i.y.qq.com/v8/playsong.html?_wv=1&songid=4830342&souce=qqshare&source=qqshare&ADTAG=qqshare" flag="0" adverSign="0" multiMsgFlag="0" ><item layout="2"><audio cover="http://imgcache.qq.com/music/photo/album_500/26/500_albumpic_89526_0.jpg" src="http://ws.stream.qqmusic.qq.com/C400003mAan70zUy5O.m4a?guid=1535153710&vkey=D5315B8C0603653592AD4879A8A3742177F59D582A7A86546E24DD7F282C3ACF81526C76E293E57EA1E42CF19881C561275D919233333ADE&uin=&fromtag=3" /><title>十年</title><summary>陈奕迅</summary></item><source name="QQ音乐" icon="https://i.gtimg.cn/open/app_icon/01/07/98/56/1101079856_100_m.png" url="http://web.p.qq.com/qqmpmobile/aio/app.html?id=1101079856" action="app" a_actionData="com.tencent.qqmusic" i_actionData="tencent1101079856://" appid="1101079856" /></msg>
|
||||||
```
|
```
|
||||||
@ -165,6 +168,9 @@ Type: `xml`
|
|||||||
</msg>
|
</msg>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
###json消息支持
|
||||||
|
|
||||||
|
json中的","逗号,需要转义成`,`,否则无法正确得到解析
|
||||||
|
|
||||||
## API
|
## API
|
||||||
|
|
||||||
|
@ -59,3 +59,12 @@ func NewXmlMsg(template string,ResId int64) *message.ServiceElement{
|
|||||||
SubType: "xml",
|
SubType: "xml",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewJsonMsg(template string) *message.ServiceElement{
|
||||||
|
return &message.ServiceElement{
|
||||||
|
Id: 1,
|
||||||
|
Content: template,
|
||||||
|
ResId: "1",
|
||||||
|
SubType: "json",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user