diff --git a/coolq/cqcode.go b/coolq/cqcode.go
index 4c5e8b4..f3a6fe6 100644
--- a/coolq/cqcode.go
+++ b/coolq/cqcode.go
@@ -6,11 +6,6 @@ import (
"encoding/hex"
"errors"
"fmt"
- "github.com/Mrs4s/MiraiGo/binary"
- "github.com/Mrs4s/MiraiGo/message"
- "github.com/Mrs4s/go-cqhttp/global"
- log "github.com/sirupsen/logrus"
- "github.com/tidwall/gjson"
"io/ioutil"
"net/url"
"path"
@@ -18,6 +13,12 @@ import (
"runtime"
"strconv"
"strings"
+
+ "github.com/Mrs4s/MiraiGo/binary"
+ "github.com/Mrs4s/MiraiGo/message"
+ "github.com/Mrs4s/go-cqhttp/global"
+ log "github.com/sirupsen/logrus"
+ "github.com/tidwall/gjson"
)
var matchReg = regexp.MustCompile(`\[CQ:\w+?.*?]`)
@@ -453,6 +454,27 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
SubType: "music",
}, nil
}
+ if d["type"] == "163" {
+ info, err := global.NeteaseMusicSongInfo(d["id"])
+ if err != nil {
+ return nil, err
+ }
+ if !info.Exists() {
+ return nil, errors.New("song not found")
+ }
+ name := info.Get("name").Str
+ artistName := ""
+ if info.Get("artists.0").Exists() {
+ artistName = info.Get("artists.0.name").Str
+ }
+ xml := fmt.Sprintf(`- %s%s
`,
+ name, d["id"], info.Get("album.picUrl").Str, d["id"], name, artistName)
+ return &message.ServiceElement{
+ Id: 60,
+ Content: xml,
+ SubType: "music",
+ }, nil
+ }
if d["type"] == "custom" {
xml := fmt.Sprintf(`- %s%s
`,
d["title"], d["url"], d["image"], d["audio"], d["title"], d["content"])
diff --git a/global/net.go b/global/net.go
index d3cf1a7..e394efd 100644
--- a/global/net.go
+++ b/global/net.go
@@ -3,12 +3,14 @@ package global
import (
"bytes"
"compress/gzip"
- "github.com/Mrs4s/MiraiGo/message"
- "github.com/tidwall/gjson"
+ "fmt"
"io/ioutil"
"net/http"
"strconv"
"strings"
+
+ "github.com/Mrs4s/MiraiGo/message"
+ "github.com/tidwall/gjson"
)
func GetBytes(url string) ([]byte, error) {
@@ -44,12 +46,20 @@ func QQMusicSongInfo(id string) (gjson.Result, error) {
return gjson.ParseBytes(d).Get("songinfo.data"), nil
}
-func NewXmlMsg(template string,ResId int64) *message.ServiceElement{
+func NeteaseMusicSongInfo(id string) (gjson.Result, error) {
+ d, err := GetBytes(fmt.Sprintf("http://music.163.com/api/song/detail/?id=%s&ids=%%5B%s%%5D", id, id))
+ if err != nil {
+ return gjson.Result{}, err
+ }
+ return gjson.ParseBytes(d).Get("songs.0"), nil
+}
+
+func NewXmlMsg(template string, ResId int64) *message.ServiceElement {
var serviceid string
- if ResId == 0{
- serviceid ="2" //默认值2
- }else{
- serviceid = strconv.FormatInt(ResId,10)
+ if ResId == 0 {
+ serviceid = "2" //默认值2
+ } else {
+ serviceid = strconv.FormatInt(ResId, 10)
}
//println(serviceid)
return &message.ServiceElement{