From 2b00b49755532b657ba2d90e0d1a6bbe0ffeb026 Mon Sep 17 00:00:00 2001 From: wdvxdr Date: Sat, 5 Sep 2020 17:47:30 +0800 Subject: [PATCH 1/2] fix: fit onebot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 适配onebot标准 --- docs/cqhttp.md | 2 +- server/http.go | 2 +- server/websocket.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/cqhttp.md b/docs/cqhttp.md index f491cb5..bdbedef 100644 --- a/docs/cqhttp.md +++ b/docs/cqhttp.md @@ -209,7 +209,7 @@ json中的字符串需要进行转义: | 字段 | 类型 | 说明 | | -------- | ------ | ---- | | group_id | int64 | 群号 | -| name | string | 新名 | +| group_name | string | 新名 | ### 获取图片信息 diff --git a/server/http.go b/server/http.go index 168856b..1bbac8c 100644 --- a/server/http.go +++ b/server/http.go @@ -347,7 +347,7 @@ func (s *httpServer) SetWholeBan(c *gin.Context) { func (s *httpServer) SetGroupName(c *gin.Context) { gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64) - c.JSON(200, s.bot.CQSetGroupName(gid, getParam(c, "name"))) + c.JSON(200, s.bot.CQSetGroupName(gid, getParam(c, "group_name"))) } func (s *httpServer) SetGroupLeave(c *gin.Context) { diff --git a/server/websocket.go b/server/websocket.go index 9c6c9c8..a1f241d 100644 --- a/server/websocket.go +++ b/server/websocket.go @@ -477,7 +477,7 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{ }()) }, "set_group_name": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG { - return bot.CQSetGroupName(p.Get("group_id").Int(), p.Get("name").Str) + return bot.CQSetGroupName(p.Get("group_id").Int(), p.Get("group_name").Str) }, "set_group_leave": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG { return bot.CQSetGroupLeave(p.Get("group_id").Int()) From d79cb0b536a2dd8b2f03109ce76d92bab766a05f Mon Sep 17 00:00:00 2001 From: wdvxdr Date: Sat, 5 Sep 2020 18:49:32 +0800 Subject: [PATCH 2/2] feature: send netease with json --- coolq/cqcode.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/coolq/cqcode.go b/coolq/cqcode.go index 0b86843..d6e04a6 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -493,17 +493,15 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message. return nil, errors.New("song not found") } name := info.Get("name").Str + jumpUrl := "https://y.music.163.com/m/song/" + d["id"] + musicUrl := "http://music.163.com/song/media/outer/url?id=" + d["id"] + picUrl := info.Get("album.picUrl").Str artistName := "" if info.Get("artists.0").Exists() { artistName = info.Get("artists.0.name").Str } - xml := fmt.Sprintf(``, - name, d["id"], info.Get("album.picUrl").Str, d["id"], name, artistName) - return &message.ServiceElement{ - Id: 60, - Content: xml, - SubType: "music", - }, nil + json := fmt.Sprintf("{\"app\": \"com.tencent.structmsg\",\"desc\":\"音乐\",\"view\":\"music\",\"prompt\":\"[分享]%s\",\"ver\":\"0.0.0.1\",\"meta\":{ \"music\": { \"desc\": \"%s\", \"jumpUrl\": \"%s\", \"musicUrl\": \"%s\", \"preview\": \"%s\", \"tag\": \"网易云音乐\", \"title\":\"%s\"}}}", name,artistName, jumpUrl, musicUrl, picUrl, name) + return message.NewLightApp(json), nil } if d["type"] == "custom" { xml := fmt.Sprintf(``,