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
73bd756c
Commit
73bd756c
authored
Oct 08, 2020
by
Mrs4s
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix #341.
parent
9d58c56b
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
84 additions
and
41 deletions
+84
-41
coolq/bot.go
coolq/bot.go
+38
-0
coolq/cqcode.go
coolq/cqcode.go
+37
-4
go.mod
go.mod
+1
-1
go.sum
go.sum
+2
-30
server/apiAdmin.go
server/apiAdmin.go
+6
-6
No files found.
coolq/bot.go
View file @
73bd756c
...
@@ -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
...
...
coolq/cqcode.go
View file @
73bd756c
...
@@ -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>`
,
...
...
go.mod
View file @
73bd756c
...
@@ -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-20201008
075030-5a7da6298521
github.com/Mrs4s/MiraiGo v0.0.0-20201008
134448-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
...
...
go.sum
View file @
73bd756c
This diff is collapsed.
Click to expand it.
server/apiAdmin.go
View file @
73bd756c
...
@@ -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
.
S
N
SNeededError
:
case
client
.
S
M
SNeededError
:
log
.
Warnf
(
"账号已开启设备锁, 按下 Enter 向手机 %v 发送短信验证码."
,
rsp
.
SMSPhone
)
log
.
Warnf
(
"账号已开启设备锁, 按下 Enter 向手机 %v 发送短信验证码."
,
rsp
.
SMSPhone
)
_
,
_
=
s
.
Console
.
ReadString
(
'\n'
)
_
,
_
=
s
.
Console
.
ReadString
(
'\n'
)
if
!
cli
.
RequestS
N
S
()
{
if
!
cli
.
RequestS
M
S
()
{
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
.
SubmitS
N
S
(
strings
.
ReplaceAll
(
strings
.
ReplaceAll
(
text
,
"
\n
"
,
""
),
"
\r
"
,
""
))
rsp
,
err
=
cli
.
SubmitS
M
S
(
strings
.
ReplaceAll
(
strings
.
ReplaceAll
(
text
,
"
\n
"
,
""
),
"
\r
"
,
""
))
continue
continue
case
client
.
S
N
SOrVerifyNeededError
:
case
client
.
S
M
SOrVerifyNeededError
:
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
.
RequestS
N
S
()
{
if
!
cli
.
RequestS
M
S
()
{
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
.
SubmitS
N
S
(
strings
.
ReplaceAll
(
strings
.
ReplaceAll
(
text
,
"
\n
"
,
""
),
"
\r
"
,
""
))
rsp
,
err
=
cli
.
SubmitS
M
S
(
strings
.
ReplaceAll
(
strings
.
ReplaceAll
(
text
,
"
\n
"
,
""
),
"
\r
"
,
""
))
continue
continue
}
}
log
.
Warnf
(
"请前往 -> %v <- 验证并重启Bot."
,
rsp
.
VerifyUrl
)
log
.
Warnf
(
"请前往 -> %v <- 验证并重启Bot."
,
rsp
.
VerifyUrl
)
...
...
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