Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
G
go-cqhttp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
go-cqhttp
Commits
174bb0bb
Commit
174bb0bb
authored
Aug 25, 2020
by
F0ur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(music): add netease(163) music for [CQ:music]
parent
e319f264
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
12 deletions
+44
-12
coolq/cqcode.go
coolq/cqcode.go
+27
-5
global/net.go
global/net.go
+17
-7
No files found.
coolq/cqcode.go
View file @
174bb0bb
...
@@ -6,11 +6,6 @@ import (
...
@@ -6,11 +6,6 @@ import (
"encoding/hex"
"encoding/hex"
"errors"
"errors"
"fmt"
"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"
"io/ioutil"
"net/url"
"net/url"
"path"
"path"
...
@@ -18,6 +13,12 @@ import (
...
@@ -18,6 +13,12 @@ import (
"runtime"
"runtime"
"strconv"
"strconv"
"strings"
"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+?.*?]`
)
var
matchReg
=
regexp
.
MustCompile
(
`\[CQ:\w+?.*?]`
)
...
@@ -453,6 +454,27 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
...
@@ -453,6 +454,27 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
SubType
:
"music"
,
SubType
:
"music"
,
},
nil
},
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
(
`<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="2" templateID="1" action="web" brief="[分享] %s" sourceMsgId="0" url="http://music.163.com/m/song/%s" flag="0" adverSign="0" multiMsgFlag="0"><item layout="2"><audio cover="%s?param=90y90" src="https://music.163.com/song/media/outer/url?id=%s.mp3" /><title>%s</title><summary>%s</summary></item><source name="网易云音乐" icon="https://pic.rmb.bdstatic.com/911423bee2bef937975b29b265d737b3.png" url="http://web.p.qq.com/qqmpmobile/aio/app.html?id=1101079856" action="app" a_actionData="com.netease.cloudmusic" i_actionData="tencent100495085://" appid="100495085" /></msg>`
,
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"
{
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>`
,
d
[
"title"
],
d
[
"url"
],
d
[
"image"
],
d
[
"audio"
],
d
[
"title"
],
d
[
"content"
])
d
[
"title"
],
d
[
"url"
],
d
[
"image"
],
d
[
"audio"
],
d
[
"title"
],
d
[
"content"
])
...
...
global/net.go
View file @
174bb0bb
...
@@ -3,12 +3,14 @@ package global
...
@@ -3,12 +3,14 @@ package global
import
(
import
(
"bytes"
"bytes"
"compress/gzip"
"compress/gzip"
"github.com/Mrs4s/MiraiGo/message"
"fmt"
"github.com/tidwall/gjson"
"io/ioutil"
"io/ioutil"
"net/http"
"net/http"
"strconv"
"strconv"
"strings"
"strings"
"github.com/Mrs4s/MiraiGo/message"
"github.com/tidwall/gjson"
)
)
func
GetBytes
(
url
string
)
([]
byte
,
error
)
{
func
GetBytes
(
url
string
)
([]
byte
,
error
)
{
...
@@ -44,12 +46,20 @@ func QQMusicSongInfo(id string) (gjson.Result, error) {
...
@@ -44,12 +46,20 @@ func QQMusicSongInfo(id string) (gjson.Result, error) {
return
gjson
.
ParseBytes
(
d
)
.
Get
(
"songinfo.data"
),
nil
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
var
serviceid
string
if
ResId
==
0
{
if
ResId
==
0
{
serviceid
=
"2"
//默认值2
serviceid
=
"2"
//默认值2
}
else
{
}
else
{
serviceid
=
strconv
.
FormatInt
(
ResId
,
10
)
serviceid
=
strconv
.
FormatInt
(
ResId
,
10
)
}
}
//println(serviceid)
//println(serviceid)
return
&
message
.
ServiceElement
{
return
&
message
.
ServiceElement
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment