1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-05 03:23:49 +08:00

style: simply parse subtype in custom music share

This commit is contained in:
wdvxdr 2021-05-02 13:06:29 +08:00
parent 9534fc42fc
commit 111ac7f865
No known key found for this signature in database
GPG Key ID: 55FF1414A69CEBA6

View File

@ -827,7 +827,6 @@ func (bot *CQBot) ToElement(t string, d map[string]string, isGroup bool) (m inte
if !info.Get("track_info").Exists() { if !info.Get("track_info").Exists() {
return nil, errors.New("song not found") return nil, errors.New("song not found")
} }
aid := strconv.FormatInt(info.Get("track_info.album.id").Int(), 10)
name := info.Get("track_info.name").Str name := info.Get("track_info.name").Str
mid := info.Get("track_info.mid").Str mid := info.Get("track_info.mid").Str
albumMid := info.Get("track_info.album.mid").Str albumMid := info.Get("track_info.album.mid").Str
@ -835,9 +834,6 @@ func (bot *CQBot) ToElement(t string, d map[string]string, isGroup bool) (m inte
jumpURL := "https://i.y.qq.com/v8/playsong.html?platform=11&appshare=android_qq&appversion=10030010&hosteuin=oKnlNenz7i-s7c**&songmid=" + mid + "&type=0&appsongtype=1&_wv=1&source=qq&ADTAG=qfshare" jumpURL := "https://i.y.qq.com/v8/playsong.html?platform=11&appshare=android_qq&appversion=10030010&hosteuin=oKnlNenz7i-s7c**&songmid=" + mid + "&type=0&appsongtype=1&_wv=1&source=qq&ADTAG=qfshare"
purl := gjson.ParseBytes(pinfo).Get("url_mid.data.midurlinfo.0.purl").Str purl := gjson.ParseBytes(pinfo).Get("url_mid.data.midurlinfo.0.purl").Str
preview := "http://y.gtimg.cn/music/photo_new/T002R180x180M000" + albumMid + ".jpg" preview := "http://y.gtimg.cn/music/photo_new/T002R180x180M000" + albumMid + ".jpg"
if len(aid) < 2 {
return nil, errors.New("song error")
}
content := info.Get("track_info.singer.0.name").Str content := info.Get("track_info.singer.0.name").Str
if d["content"] != "" { if d["content"] != "" {
content = d["content"] content = d["content"]
@ -878,19 +874,21 @@ func (bot *CQBot) ToElement(t string, d map[string]string, isGroup bool) (m inte
} }
if d["type"] == "custom" { if d["type"] == "custom" {
if d["subtype"] != "" { if d["subtype"] != "" {
subtype := map[string]int{ var subType int
"qq": message.QQMusic, switch d["subtype"] {
"163": message.CloudMusic, default:
"migu": message.MiguMusic, subType = message.QQMusic
"kugou": message.KugouMusic, case "163":
"kuwo": message.KuwoMusic, subType = message.CloudMusic
} case "migu":
musicType := 0 subType = message.MiguMusic
if tp, ok := subtype[d["subtype"]]; ok { case "kugou":
musicType = tp subType = message.KugouMusic
case "kuwo":
subType = message.KuwoMusic
} }
return &message.MusicShareElement{ return &message.MusicShareElement{
MusicType: musicType, MusicType: subType,
Title: d["title"], Title: d["title"],
Summary: d["content"], Summary: d["content"],
Url: d["url"], Url: d["url"],