diff --git a/coolq/bot.go b/coolq/bot.go index 162a893..81eee07 100644 --- a/coolq/bot.go +++ b/coolq/bot.go @@ -201,61 +201,8 @@ func (bot *CQBot) SendGroupMessage(groupId int64, m *message.SendingMessage) int bot.Client.SendGroupGift(uint64(groupId), uint64(i.Target), i.GiftId) return 0 } - if i, ok := elem.(*QQMusicElement); ok { - var msgStyle uint32 = 4 - if i.MusicUrl == "" { - msgStyle = 0 // fix vip song - } - ret, err := bot.Client.SendGroupRichMessage(groupId, 100497308, 1, msgStyle, client.RichClientInfo{ - Platform: 1, - SdkVersion: "0.0.0", - PackageName: "com.tencent.qqmusic", - Signature: "cbd27cd7c861227d013a25b2d10f0799", - }, &message.RichMessage{ - Title: i.Title, - Summary: i.Summary, - Url: i.Url, - PictureUrl: i.PictureUrl, - MusicUrl: i.MusicUrl, - }) - if err != nil { - log.Warnf("警告: 群 %v 富文本消息发送失败: %v", groupId, err) - return -1 - } - return bot.InsertGroupMessage(ret) - } - if i, ok := elem.(*CloudMusicElement); ok { - ret, err := bot.Client.SendGroupRichMessage(groupId, 100495085, 1, 4, client.RichClientInfo{ - Platform: 1, - SdkVersion: "0.0.0", - PackageName: "com.netease.cloudmusic", - Signature: "da6b069da1e2982db3e386233f68d76d", - }, &message.RichMessage{ - Title: i.Title, - Summary: i.Summary, - Url: i.Url, - PictureUrl: i.PictureUrl, - MusicUrl: i.MusicUrl, - }) - if err != nil { - log.Warnf("警告: 群 %v 富文本消息发送失败: %v", groupId, err) - return -1 - } - return bot.InsertGroupMessage(ret) - } - if i, ok := elem.(*MiguMusicElement); ok { - ret, err := bot.Client.SendGroupRichMessage(groupId, 1101053067, 1, 4, client.RichClientInfo{ - Platform: 1, - SdkVersion: "0.0.0", - PackageName: "cmccwm.mobilemusic", - Signature: "6cdc72a439cef99a3418d2a78aa28c73", - }, &message.RichMessage{ - Title: i.Title, - Summary: i.Summary, - Url: i.Url, - PictureUrl: i.PictureUrl, - MusicUrl: i.MusicUrl, - }) + if i, ok := elem.(*message.MusicShareElement); ok { + ret, err := bot.Client.SendGroupMusicShare(groupId, i) if err != nil { log.Warnf("警告: 群 %v 富文本消息发送失败: %v", groupId, err) return -1 @@ -312,53 +259,8 @@ func (bot *CQBot) SendPrivateMessage(target int64, m *message.SendingMessage) in newElem = append(newElem, gv) continue } - if i, ok := elem.(*QQMusicElement); ok { - var msgStyle uint32 = 4 - if i.MusicUrl == "" { - msgStyle = 0 // fix vip song - } - bot.Client.SendFriendRichMessage(target, 100497308, 1, msgStyle, client.RichClientInfo{ - Platform: 1, - SdkVersion: "0.0.0", - PackageName: "com.tencent.qqmusic", - Signature: "cbd27cd7c861227d013a25b2d10f0799", - }, &message.RichMessage{ - Title: i.Title, - Summary: i.Summary, - Url: i.Url, - PictureUrl: i.PictureUrl, - MusicUrl: i.MusicUrl, - }) - return 0 - } - if i, ok := elem.(*CloudMusicElement); ok { - bot.Client.SendFriendRichMessage(target, 100495085, 1, 4, client.RichClientInfo{ - Platform: 1, - SdkVersion: "0.0.0", - PackageName: "com.netease.cloudmusic", - Signature: "da6b069da1e2982db3e386233f68d76d", - }, &message.RichMessage{ - Title: i.Title, - Summary: i.Summary, - Url: i.Url, - PictureUrl: i.PictureUrl, - MusicUrl: i.MusicUrl, - }) - return 0 - } - if i, ok := elem.(*MiguMusicElement); ok { - bot.Client.SendFriendRichMessage(target, 1101053067, 1, 4, client.RichClientInfo{ - Platform: 1, - SdkVersion: "0.0.0", - PackageName: "cmccwm.mobilemusic", - Signature: "6cdc72a439cef99a3418d2a78aa28c73", - }, &message.RichMessage{ - Title: i.Title, - Summary: i.Summary, - Url: i.Url, - PictureUrl: i.PictureUrl, - MusicUrl: i.MusicUrl, - }) + if i, ok := elem.(*message.MusicShareElement); ok { + bot.Client.SendFriendMusicShare(target, i) return 0 } newElem = append(newElem, elem) diff --git a/coolq/cqcode.go b/coolq/cqcode.go index 4032e1a..cdfe09e 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -49,26 +49,6 @@ type GiftElement struct { GiftId message.GroupGift } -type MusicElement struct { - Title string - Summary string - Url string - PictureUrl string - MusicUrl string -} - -type QQMusicElement struct { - MusicElement -} - -type CloudMusicElement struct { - MusicElement -} - -type MiguMusicElement struct { - MusicElement -} - type LocalImageElement struct { message.ImageElement Stream io.ReadSeeker @@ -90,10 +70,6 @@ func (e *GiftElement) Type() message.ElementType { return message.At } -func (e *MusicElement) Type() message.ElementType { - return message.Service -} - var GiftId = [...]message.GroupGift{ message.SweetWink, message.HappyCola, @@ -699,7 +675,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interf 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 + " - " + info.Get("track_info.singer.0.name").Str + name := info.Get("track_info.name").Str mid := info.Get("track_info.mid").Str albumMid := info.Get("track_info.album.mid").Str pinfo, _ := global.GetBytes("http://u.y.qq.com/cgi-bin/musicu.fcg?g_tk=2034008533&uin=0&format=json&data={\"comm\":{\"ct\":23,\"cv\":0},\"url_mid\":{\"module\":\"vkey.GetVkeyServer\",\"method\":\"CgiGetVkey\",\"param\":{\"guid\":\"4311206557\",\"songmid\":[\"" + mid + "\"],\"songtype\":[0],\"uin\":\"0\",\"loginflag\":1,\"platform\":\"23\"}}}&_=1599039471576") @@ -709,17 +685,18 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interf if len(aid) < 2 { return nil, errors.New("song error") } - content := "来自go-cqhttp" + content := info.Get("track_info.singer.0.name").Str if d["content"] != "" { content = d["content"] } - return &QQMusicElement{MusicElement: MusicElement{ + return &message.MusicShareElement{ + MusicType: message.QQMusic, Title: name, Summary: content, Url: jumpUrl, PictureUrl: preview, MusicUrl: purl, - }}, nil + }, nil } if d["type"] == "163" { info, err := global.NeteaseMusicSongInfo(d["id"]) @@ -737,41 +714,36 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interf if info.Get("artists.0").Exists() { artistName = info.Get("artists.0.name").Str } - return &CloudMusicElement{MusicElement{ + return &message.MusicShareElement{ + MusicType: message.CloudMusic, Title: name, Summary: artistName, Url: jumpUrl, PictureUrl: picUrl, MusicUrl: musicUrl, - }}, nil + }, nil } if d["type"] == "custom" { - if d["subtype"] == "qq" { - return &QQMusicElement{MusicElement{ + if d["subtype"] != "" { + var subtype = map[string]int{ + "qq": message.QQMusic, + "163": message.CloudMusic, + "migu": message.MiguMusic, + "kugou": message.KugouMusic, + "kuwo": message.KuwoMusic, + } + var musicType = 0 + if tp, ok := subtype[d["subtype"]]; ok { + musicType = tp + } + return &message.MusicShareElement{ + MusicType: musicType, 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 - } - if d["subtype"] == "migu" { - return &MiguMusicElement{MusicElement{ - Title: d["title"], - Summary: d["content"], - Url: d["url"], - PictureUrl: d["image"], - MusicUrl: d["purl"], - }}, nil + }, nil } xml := fmt.Sprintf(``, XmlEscape(d["title"]), d["url"], d["image"], d["audio"], XmlEscape(d["title"]), XmlEscape(d["content"]))