From b99986d1127dfa77fd8fc795b7ef838ea1c8f460 Mon Sep 17 00:00:00 2001 From: wdvxdr Date: Sat, 17 Oct 2020 19:46:24 +0800 Subject: [PATCH 1/2] feature: support custom migu misic --- coolq/bot.go | 34 ++++++++++++++++++++++++++++++++++ coolq/cqcode.go | 14 ++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/coolq/bot.go b/coolq/bot.go index 04bd0b5..0483d57 100644 --- a/coolq/bot.go +++ b/coolq/bot.go @@ -190,6 +190,25 @@ func (bot *CQBot) SendGroupMessage(groupId int64, m *message.SendingMessage) int } 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 { + log.Warnf("警告: 群 %v 富文本消息发送失败: %v", groupId, err) + return -1 + } + return bot.InsertGroupMessage(ret) + } newElem = append(newElem, elem) } m.Elements = newElem @@ -256,6 +275,21 @@ func (bot *CQBot) SendPrivateMessage(target int64, m *message.SendingMessage) in }) 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 + } newElem = append(newElem, elem) } m.Elements = newElem diff --git a/coolq/cqcode.go b/coolq/cqcode.go index e35a6fc..1e4f1d3 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -51,6 +51,10 @@ type CloudMusicElement struct { MusicElement } +type MiguMusicElement struct { + MusicElement +} + func (e *GiftElement) Type() message.ElementType { return message.At } @@ -372,6 +376,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m messag return nil, err } tp := d["type"] + fmt.Println(tp) if tp != "show" && tp != "flash" { return img, nil } @@ -536,6 +541,15 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m messag 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 + } xml := fmt.Sprintf(``, d["title"], d["url"], d["image"], d["audio"], d["title"], d["content"]) return &message.ServiceElement{ From 98b9be575e6ffee3702ed0a61d3684d2a7f1d1aa Mon Sep 17 00:00:00 2001 From: wdvxdr Date: Sat, 17 Oct 2020 19:50:14 +0800 Subject: [PATCH 2/2] fix typo --- coolq/cqcode.go | 1 - 1 file changed, 1 deletion(-) diff --git a/coolq/cqcode.go b/coolq/cqcode.go index 1e4f1d3..95363cf 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -376,7 +376,6 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m messag return nil, err } tp := d["type"] - fmt.Println(tp) if tp != "show" && tp != "flash" { return img, nil }