1
0
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:
wdvxdr 2021-01-25 15:06:30 +08:00
parent a2a0b4c86f
commit 817bb0e493
No known key found for this signature in database
GPG Key ID: 55FF1414A69CEBA6
2 changed files with 27 additions and 153 deletions

View File

@ -201,61 +201,8 @@ func (bot *CQBot) SendGroupMessage(groupId int64, m *message.SendingMessage) int
bot.Client.SendGroupGift(uint64(groupId), uint64(i.Target), i.GiftId) bot.Client.SendGroupGift(uint64(groupId), uint64(i.Target), i.GiftId)
return 0 return 0
} }
if i, ok := elem.(*QQMusicElement); ok { if i, ok := elem.(*message.MusicShareElement); ok {
var msgStyle uint32 = 4 ret, err := bot.Client.SendGroupMusicShare(groupId, i)
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 err != nil { if err != nil {
log.Warnf("警告: 群 %v 富文本消息发送失败: %v", groupId, err) log.Warnf("警告: 群 %v 富文本消息发送失败: %v", groupId, err)
return -1 return -1
@ -312,53 +259,8 @@ func (bot *CQBot) SendPrivateMessage(target int64, m *message.SendingMessage) in
newElem = append(newElem, gv) newElem = append(newElem, gv)
continue continue
} }
if i, ok := elem.(*QQMusicElement); ok { if i, ok := elem.(*message.MusicShareElement); ok {
var msgStyle uint32 = 4 bot.Client.SendFriendMusicShare(target, i)
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,
})
return 0 return 0
} }
newElem = append(newElem, elem) newElem = append(newElem, elem)

View File

@ -49,26 +49,6 @@ type GiftElement struct {
GiftId message.GroupGift 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 { type LocalImageElement struct {
message.ImageElement message.ImageElement
Stream io.ReadSeeker Stream io.ReadSeeker
@ -90,10 +70,6 @@ func (e *GiftElement) Type() message.ElementType {
return message.At return message.At
} }
func (e *MusicElement) Type() message.ElementType {
return message.Service
}
var GiftId = [...]message.GroupGift{ var GiftId = [...]message.GroupGift{
message.SweetWink, message.SweetWink,
message.HappyCola, 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") return nil, errors.New("song not found")
} }
aid := strconv.FormatInt(info.Get("track_info.album.id").Int(), 10) 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 mid := info.Get("track_info.mid").Str
albumMid := info.Get("track_info.album.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") 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 { if len(aid) < 2 {
return nil, errors.New("song error") return nil, errors.New("song error")
} }
content := "来自go-cqhttp" content := info.Get("track_info.singer.0.name").Str
if d["content"] != "" { if d["content"] != "" {
content = d["content"] content = d["content"]
} }
return &QQMusicElement{MusicElement: MusicElement{ return &message.MusicShareElement{
MusicType: message.QQMusic,
Title: name, Title: name,
Summary: content, Summary: content,
Url: jumpUrl, Url: jumpUrl,
PictureUrl: preview, PictureUrl: preview,
MusicUrl: purl, MusicUrl: purl,
}}, nil }, nil
} }
if d["type"] == "163" { if d["type"] == "163" {
info, err := global.NeteaseMusicSongInfo(d["id"]) 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() { if info.Get("artists.0").Exists() {
artistName = info.Get("artists.0.name").Str artistName = info.Get("artists.0.name").Str
} }
return &CloudMusicElement{MusicElement{ return &message.MusicShareElement{
MusicType: message.CloudMusic,
Title: name, Title: name,
Summary: artistName, Summary: artistName,
Url: jumpUrl, Url: jumpUrl,
PictureUrl: picUrl, PictureUrl: picUrl,
MusicUrl: musicUrl, MusicUrl: musicUrl,
}}, nil }, nil
} }
if d["type"] == "custom" { if d["type"] == "custom" {
if d["subtype"] == "qq" { if d["subtype"] != "" {
return &QQMusicElement{MusicElement{ var subtype = map[string]int{
Title: d["title"], "qq": message.QQMusic,
Summary: d["content"], "163": message.CloudMusic,
Url: d["url"], "migu": message.MiguMusic,
PictureUrl: d["image"], "kugou": message.KugouMusic,
MusicUrl: d["purl"], "kuwo": message.KuwoMusic,
}}, nil
} }
if d["subtype"] == "163" { var musicType = 0
return &CloudMusicElement{MusicElement{ if tp, ok := subtype[d["subtype"]]; ok {
Title: d["title"], musicType = tp
Summary: d["content"],
Url: d["url"],
PictureUrl: d["image"],
MusicUrl: d["purl"],
}}, nil
} }
if d["subtype"] == "migu" { return &message.MusicShareElement{
return &MiguMusicElement{MusicElement{ MusicType: musicType,
Title: d["title"], Title: d["title"],
Summary: d["content"], Summary: d["content"],
Url: d["url"], Url: d["url"],
PictureUrl: d["image"], PictureUrl: d["image"],
MusicUrl: d["purl"], 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>`, 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"])) XmlEscape(d["title"]), d["url"], d["image"], d["audio"], XmlEscape(d["title"]), XmlEscape(d["content"]))