From 95376a8a63b82a98a0ae78a6917a3eda140abc4f Mon Sep 17 00:00:00 2001 From: Mrs4s Date: Tue, 13 Oct 2020 20:56:50 +0800 Subject: [PATCH] feature: custom music type supported. --- coolq/cqcode.go | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/coolq/cqcode.go b/coolq/cqcode.go index 17ce84c..267df4e 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -367,8 +367,8 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m messag case "text": return message.NewText(d["text"]), nil case "image": - img,err := bot.makeImageElem(d, group) - if err != nil{ + img, err := bot.makeImageElem(d, group) + if err != nil { return nil, err } tp := d["type"] @@ -387,21 +387,21 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m messag } switch tp { case "flash": - if i, ok := img.(*message.GroupImageElement); ok{ - return &message.GroupFlashPicElement{GroupImageElement: *i},nil + if i, ok := img.(*message.GroupImageElement); ok { + return &message.GroupFlashPicElement{GroupImageElement: *i}, nil } - if i, ok := img.(*message.FriendImageElement); ok{ - return &message.FriendFlashPicElement{FriendImageElement: *i},nil + if i, ok := img.(*message.FriendImageElement); ok { + return &message.FriendFlashPicElement{FriendImageElement: *i}, nil } case "show": id, _ := strconv.ParseInt(d["id"], 10, 64) if id < 40000 || id >= 40006 { id = 40000 } - if i, ok := img.(*message.GroupImageElement); ok{ - return &message.GroupShowPicElement{GroupImageElement: *i,EffectId: int32(id)},nil + if i, ok := img.(*message.GroupImageElement); ok { + return &message.GroupShowPicElement{GroupImageElement: *i, EffectId: int32(id)}, nil } - return img,nil // 私聊还没做 + return img, nil // 私聊还没做 } case "poke": @@ -425,7 +425,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m messag return nil, errors.New("private voice unsupported now") } defer func() { - if r := recover();r != nil { + if r := recover(); r != nil { m = nil err = errors.New("tts 转换失败") } @@ -524,6 +524,24 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m messag }}, nil } if d["type"] == "custom" { + if d["subtype"] == "qq" { + return &QQMusicElement{MusicElement{ + Title: d["title"], + Summary: d["content"], + Url: d["url"], + PictureUrl: d["image"], + MusicUrl: d["purl"], + }}, nil + } + if d["subtype"] == "163" { + return &CloudMusicElement{MusicElement{ + Title: d["title"], + Summary: d["content"], + Url: d["url"], + PictureUrl: d["image"], + MusicUrl: d["purl"], + }}, nil + } xml := fmt.Sprintf(``, d["title"], d["url"], d["image"], d["audio"], d["title"], d["content"]) return &message.ServiceElement{