Commit 73bd756c authored by Mrs4s's avatar Mrs4s

fix #341.

parent 9d58c56b
...@@ -151,6 +151,44 @@ func (bot *CQBot) SendGroupMessage(groupId int64, m *message.SendingMessage) int ...@@ -151,6 +151,44 @@ 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 {
ret, err := bot.Client.SendGroupRichMessage(groupId, 100497308, 1, 4, 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)
}
newElem = append(newElem, elem) newElem = append(newElem, elem)
} }
m.Elements = newElem m.Elements = newElem
......
...@@ -35,10 +35,30 @@ type GiftElement struct { ...@@ -35,10 +35,30 @@ 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
}
func (e *GiftElement) Type() message.ElementType { 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,
...@@ -429,8 +449,16 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message. ...@@ -429,8 +449,16 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
if d["content"] != "" { if d["content"] != "" {
content = d["content"] content = d["content"]
} }
json := fmt.Sprintf("{\"app\": \"com.tencent.structmsg\",\"desc\": \"音乐\",\"meta\": {\"music\": {\"desc\": \"%s\",\"jumpUrl\": \"%s\",\"musicUrl\": \"%s\",\"preview\": \"%s\",\"tag\": \"QQ音乐\",\"title\": \"%s\"}},\"prompt\": \"[分享]%s\",\"ver\": \"0.0.0.1\",\"view\": \"music\"}", content, jumpUrl, purl, preview, name, name) if purl == "" {
return message.NewLightApp(json), nil purl = "https://www.baidu.com" // fix vip song
}
return &QQMusicElement{MusicElement: MusicElement{
Title: name,
Summary: content,
Url: jumpUrl,
PictureUrl: preview,
MusicUrl: purl,
}}, nil
} }
if d["type"] == "163" { if d["type"] == "163" {
info, err := global.NeteaseMusicSongInfo(d["id"]) info, err := global.NeteaseMusicSongInfo(d["id"])
...@@ -448,8 +476,13 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message. ...@@ -448,8 +476,13 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
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
} }
json := fmt.Sprintf("{\"app\": \"com.tencent.structmsg\",\"desc\":\"音乐\",\"view\":\"music\",\"prompt\":\"[分享]%s\",\"ver\":\"0.0.0.1\",\"meta\":{ \"music\": { \"desc\": \"%s\", \"jumpUrl\": \"%s\", \"musicUrl\": \"%s\", \"preview\": \"%s\", \"tag\": \"网易云音乐\", \"title\":\"%s\"}}}", name, artistName, jumpUrl, musicUrl, picUrl, name) return &CloudMusicElement{MusicElement{
return message.NewLightApp(json), nil Title: name,
Summary: artistName,
Url: jumpUrl,
PictureUrl: picUrl,
MusicUrl: musicUrl,
}}, nil
} }
if d["type"] == "custom" { if d["type"] == "custom" {
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>`,
......
...@@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp ...@@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
go 1.14 go 1.14
require ( require (
github.com/Mrs4s/MiraiGo v0.0.0-20201008075030-5a7da6298521 github.com/Mrs4s/MiraiGo v0.0.0-20201008134448-b53aaceaa1b4
github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
github.com/gin-gonic/gin v1.6.3 github.com/gin-gonic/gin v1.6.3
github.com/go-playground/validator/v10 v10.4.0 // indirect github.com/go-playground/validator/v10 v10.4.0 // indirect
......
This diff is collapsed.
...@@ -130,33 +130,33 @@ func (s *webServer) Dologin() { ...@@ -130,33 +130,33 @@ func (s *webServer) Dologin() {
rsp, err = cli.SubmitCaptcha(strings.ReplaceAll(text, "\n", ""), rsp.CaptchaSign) rsp, err = cli.SubmitCaptcha(strings.ReplaceAll(text, "\n", ""), rsp.CaptchaSign)
global.DelFile("captcha.jpg") global.DelFile("captcha.jpg")
continue continue
case client.SNSNeededError: case client.SMSNeededError:
log.Warnf("账号已开启设备锁, 按下 Enter 向手机 %v 发送短信验证码.", rsp.SMSPhone) log.Warnf("账号已开启设备锁, 按下 Enter 向手机 %v 发送短信验证码.", rsp.SMSPhone)
_, _ = s.Console.ReadString('\n') _, _ = s.Console.ReadString('\n')
if !cli.RequestSNS() { if !cli.RequestSMS() {
log.Warnf("发送验证码失败,可能是请求过于频繁.") log.Warnf("发送验证码失败,可能是请求过于频繁.")
time.Sleep(time.Second * 5) time.Sleep(time.Second * 5)
os.Exit(0) os.Exit(0)
} }
log.Warn("请输入短信验证码: (Enter 提交)") log.Warn("请输入短信验证码: (Enter 提交)")
text, _ = s.Console.ReadString('\n') text, _ = s.Console.ReadString('\n')
rsp, err = cli.SubmitSNS(strings.ReplaceAll(strings.ReplaceAll(text, "\n", ""), "\r", "")) rsp, err = cli.SubmitSMS(strings.ReplaceAll(strings.ReplaceAll(text, "\n", ""), "\r", ""))
continue continue
case client.SNSOrVerifyNeededError: case client.SMSOrVerifyNeededError:
log.Warnf("账号已开启设备锁,请选择验证方式:") log.Warnf("账号已开启设备锁,请选择验证方式:")
log.Warnf("1. 向手机 %v 发送短信验证码", rsp.SMSPhone) log.Warnf("1. 向手机 %v 发送短信验证码", rsp.SMSPhone)
log.Warnf("2. 使用手机QQ扫码验证.") log.Warnf("2. 使用手机QQ扫码验证.")
log.Warn("请输入(1 - 2): ") log.Warn("请输入(1 - 2): ")
text, _ = s.Console.ReadString('\n') text, _ = s.Console.ReadString('\n')
if strings.Contains(text, "1") { if strings.Contains(text, "1") {
if !cli.RequestSNS() { if !cli.RequestSMS() {
log.Warnf("发送验证码失败,可能是请求过于频繁.") log.Warnf("发送验证码失败,可能是请求过于频繁.")
time.Sleep(time.Second * 5) time.Sleep(time.Second * 5)
os.Exit(0) os.Exit(0)
} }
log.Warn("请输入短信验证码: (Enter 提交)") log.Warn("请输入短信验证码: (Enter 提交)")
text, _ = s.Console.ReadString('\n') text, _ = s.Console.ReadString('\n')
rsp, err = cli.SubmitSNS(strings.ReplaceAll(strings.ReplaceAll(text, "\n", ""), "\r", "")) rsp, err = cli.SubmitSMS(strings.ReplaceAll(strings.ReplaceAll(text, "\n", ""), "\r", ""))
continue continue
} }
log.Warnf("请前往 -> %v <- 验证并重启Bot.", rsp.VerifyUrl) log.Warnf("请前往 -> %v <- 验证并重启Bot.", rsp.VerifyUrl)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment