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
8ae2c1c9
Commit
8ae2c1c9
authored
Aug 23, 2020
by
Mrs4s
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
music supported.
parent
8fa804a2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
1 deletion
+44
-1
coolq/cqcode.go
coolq/cqcode.go
+32
-0
global/net.go
global/net.go
+9
-0
go.mod
go.mod
+1
-1
go.sum
go.sum
+2
-0
No files found.
coolq/cqcode.go
View file @
8ae2c1c9
...
@@ -425,6 +425,38 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
...
@@ -425,6 +425,38 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
return
message
.
NewAt
(
t
),
nil
return
message
.
NewAt
(
t
),
nil
case
"share"
:
case
"share"
:
return
message
.
NewUrlShare
(
d
[
"url"
],
d
[
"title"
],
d
[
"content"
],
d
[
"image"
]),
nil
return
message
.
NewUrlShare
(
d
[
"url"
],
d
[
"title"
],
d
[
"content"
],
d
[
"image"
]),
nil
case
"music"
:
if
d
[
"type"
]
==
"qq"
{
info
,
err
:=
global
.
QQMusicSongInfo
(
d
[
"id"
])
if
err
!=
nil
{
return
nil
,
err
}
if
!
info
.
Get
(
"track_info"
)
.
Exists
()
{
return
nil
,
errors
.
New
(
"song not found"
)
}
aid
:=
strconv
.
FormatInt
(
info
.
Get
(
"track_info.album.id"
)
.
Int
(),
10
)
name
:=
info
.
Get
(
"track_info.name"
)
.
Str
if
len
(
aid
)
<
2
{
return
nil
,
errors
.
New
(
"song error"
)
}
xml
:=
fmt
.
Sprintf
(
`<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="2" templateID="1" action="web" brief="[分享] %s" sourceMsgId="0" url="https://i.y.qq.com/v8/playsong.html?_wv=1&songid=%s&souce=qqshare&source=qqshare&ADTAG=qqshare" flag="0" adverSign="0" multiMsgFlag="0"><item layout="2"><audio cover="http://imgcache.qq.com/music/photo/album_500/%s/500_albumpic_%s_0.jpg" src="%s" /><title>%s</title><summary>%s</summary></item><source name="QQ音乐" 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>`
,
name
,
d
[
"id"
],
aid
[
:
len
(
aid
)
-
2
],
aid
,
name
,
""
,
info
.
Get
(
"track_info.singer.name"
)
.
Str
)
return
&
message
.
ServiceElement
{
Id
:
60
,
Content
:
xml
,
SubType
:
"music"
,
},
nil
}
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>`
,
d
[
"title"
],
d
[
"url"
],
d
[
"image"
],
d
[
"audio"
],
d
[
"title"
],
d
[
"content"
])
return
&
message
.
ServiceElement
{
Id
:
60
,
Content
:
xml
,
SubType
:
"music"
,
},
nil
}
return
nil
,
errors
.
New
(
"unsupported music type: "
+
d
[
"type"
])
default
:
default
:
return
nil
,
errors
.
New
(
"unsupported cq code: "
+
t
)
return
nil
,
errors
.
New
(
"unsupported cq code: "
+
t
)
}
}
...
...
global/net.go
View file @
8ae2c1c9
...
@@ -3,6 +3,7 @@ package global
...
@@ -3,6 +3,7 @@ package global
import
(
import
(
"bytes"
"bytes"
"compress/gzip"
"compress/gzip"
"github.com/tidwall/gjson"
"io/ioutil"
"io/ioutil"
"net/http"
"net/http"
"strings"
"strings"
...
@@ -32,3 +33,11 @@ func GetBytes(url string) ([]byte, error) {
...
@@ -32,3 +33,11 @@ func GetBytes(url string) ([]byte, error) {
}
}
return
body
,
nil
return
body
,
nil
}
}
func
QQMusicSongInfo
(
id
string
)
(
gjson
.
Result
,
error
)
{
d
,
err
:=
GetBytes
(
`https://u.y.qq.com/cgi-bin/musicu.fcg?format=json&inCharset=utf8&outCharset=utf-8¬ice=0&platform=yqq.json&needNewCode=0&data={%22comm%22:{%22ct%22:24,%22cv%22:0},%22songinfo%22:{%22method%22:%22get_song_detail_yqq%22,%22param%22:{%22song_type%22:0,%22song_mid%22:%22%22,%22song_id%22:`
+
id
+
`},%22module%22:%22music.pf_song_detail_svr%22}}`
)
if
err
!=
nil
{
return
gjson
.
Result
{},
err
}
return
gjson
.
ParseBytes
(
d
)
.
Get
(
"songinfo.data"
),
nil
}
go.mod
View file @
8ae2c1c9
...
@@ -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-202008221
02558-4dc018de2be7
github.com/Mrs4s/MiraiGo v0.0.0-202008221
90748-ce670caee0a8
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/gorilla/websocket v1.4.2
github.com/gorilla/websocket v1.4.2
...
...
go.sum
View file @
8ae2c1c9
...
@@ -2,6 +2,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
...
@@ -2,6 +2,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Mrs4s/MiraiGo v0.0.0-20200822102558-4dc018de2be7 h1:X6ebQxHSXRXDa3ZkMSFYnUhEIKdn6iPUmcFf2pl46oA=
github.com/Mrs4s/MiraiGo v0.0.0-20200822102558-4dc018de2be7 h1:X6ebQxHSXRXDa3ZkMSFYnUhEIKdn6iPUmcFf2pl46oA=
github.com/Mrs4s/MiraiGo v0.0.0-20200822102558-4dc018de2be7/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM=
github.com/Mrs4s/MiraiGo v0.0.0-20200822102558-4dc018de2be7/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM=
github.com/Mrs4s/MiraiGo v0.0.0-20200822190748-ce670caee0a8 h1:29b2Y1TehWby+jEXC7kjOvXk/PxwZ1BeFAKwOzTaW7M=
github.com/Mrs4s/MiraiGo v0.0.0-20200822190748-ce670caee0a8/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM=
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE=
github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
...
...
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