mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-06 12:03:50 +08:00
simplify music share
support Kugou,Kuwo custom
This commit is contained in:
parent
a2a0b4c86f
commit
817bb0e493
106
coolq/bot.go
106
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)
|
||||
|
@ -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(`<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="2" templateID="1" action="web" brief="[分享] %s" sourceMsgId="0" url="%s" flag="0" adverSign="0" multiMsgFlag="0"><item layout="2"><audio cover="%s" src="%s"/><title>%s</title><summary>%s</summary></item><source name="音乐" 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>`,
|
||||
XmlEscape(d["title"]), d["url"], d["image"], d["audio"], XmlEscape(d["title"]), XmlEscape(d["content"]))
|
||||
|
Loading…
x
Reference in New Issue
Block a user