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
2302cf62
Commit
2302cf62
authored
Oct 17, 2020
by
wdvxdr
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'upstream/dev' into dev
parents
e719c867
9b36645b
Changes
13
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
245 additions
and
157 deletions
+245
-157
.github/workflows/ci.yml
.github/workflows/ci.yml
+4
-2
.github/workflows/release.yml
.github/workflows/release.yml
+3
-0
README.md
README.md
+4
-0
coolq/api.go
coolq/api.go
+15
-5
coolq/bot.go
coolq/bot.go
+92
-31
coolq/cqcode.go
coolq/cqcode.go
+49
-37
coolq/event.go
coolq/event.go
+28
-4
docs/QA.md
docs/QA.md
+0
-8
go.mod
go.mod
+2
-15
go.sum
go.sum
+26
-39
server/apiAdmin.go
server/apiAdmin.go
+16
-10
server/http.go
server/http.go
+4
-4
server/websocket.go
server/websocket.go
+2
-2
No files found.
.github/workflows/ci.yml
View file @
2302cf62
...
@@ -14,12 +14,14 @@ jobs:
...
@@ -14,12 +14,14 @@ jobs:
runs-on
:
ubuntu-latest
runs-on
:
ubuntu-latest
strategy
:
strategy
:
matrix
:
matrix
:
# build and publish in parallel: linux/386, linux/amd64, windows/386, windows/amd64, darwin/
386, darwin/amd64
# build and publish in parallel: linux/386, linux/amd64, windows/386, windows/amd64, darwin/
amd64
goos
:
[
linux
,
windows
,
darwin
]
goos
:
[
linux
,
windows
,
darwin
]
goarch
:
[
"
386"
,
amd64
,
arm
]
goarch
:
[
"
386"
,
amd64
,
arm
]
exclude
:
exclude
:
-
goos
:
darwin
-
goos
:
darwin
goarch
:
arm
goarch
:
arm
-
goos
:
darwin
goarch
:
"
386"
fail-fast
:
true
fail-fast
:
true
steps
:
steps
:
...
@@ -28,7 +30,7 @@ jobs:
...
@@ -28,7 +30,7 @@ jobs:
-
name
:
Setup Go environment
-
name
:
Setup Go environment
uses
:
actions/setup-go@v2.1.1
uses
:
actions/setup-go@v2.1.1
with
:
with
:
go-version
:
1.1
4
go-version
:
1.1
5
-
name
:
Build binary file
-
name
:
Build binary file
env
:
env
:
...
...
.github/workflows/release.yml
View file @
2302cf62
...
@@ -14,6 +14,8 @@ jobs:
...
@@ -14,6 +14,8 @@ jobs:
exclude
:
exclude
:
-
goos
:
darwin
-
goos
:
darwin
goarch
:
arm
goarch
:
arm
-
goos
:
darwin
goarch
:
"
386"
steps
:
steps
:
-
uses
:
actions/checkout@v2
-
uses
:
actions/checkout@v2
...
@@ -26,5 +28,6 @@ jobs:
...
@@ -26,5 +28,6 @@ jobs:
github_token
:
${{ secrets.GITHUB_TOKEN }}
github_token
:
${{ secrets.GITHUB_TOKEN }}
goos
:
${{ matrix.goos }}
goos
:
${{ matrix.goos }}
goarch
:
${{ matrix.goarch }}
goarch
:
${{ matrix.goarch }}
goversion
:
"
https://golang.org/dl/go1.15.3.linux-amd64.tar.gz"
ldflags
:
-w -s -X "github.com/Mrs4s/go-cqhttp/coolq.Version=${{ env.RELEASE_VERSION }}"
ldflags
:
-w -s -X "github.com/Mrs4s/go-cqhttp/coolq.Version=${{ env.RELEASE_VERSION }}"
\ No newline at end of file
README.md
View file @
2302cf62
...
@@ -35,6 +35,10 @@
...
@@ -35,6 +35,10 @@
-
[CQ:reply]
-
[CQ:reply]
-
[CQ:forward]
-
[CQ:forward]
-
[CQ:node]
-
[CQ:node]
-
[CQ:gift]
-
[CQ:redbag]
-
[CQ:tts]
-
[CQ:music]
</details>
</details>
...
...
coolq/api.go
View file @
2302cf62
...
@@ -189,7 +189,7 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupId int64, m gjson.Result) MSG {
...
@@ -189,7 +189,7 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupId int64, m gjson.Result) MSG {
ts
.
Add
(
time
.
Second
)
ts
.
Add
(
time
.
Second
)
if
e
.
Get
(
"data.id"
)
.
Exists
()
{
if
e
.
Get
(
"data.id"
)
.
Exists
()
{
i
,
_
:=
strconv
.
Atoi
(
e
.
Get
(
"data.id"
)
.
Str
)
i
,
_
:=
strconv
.
Atoi
(
e
.
Get
(
"data.id"
)
.
Str
)
m
:=
bot
.
Get
Group
Message
(
int32
(
i
))
m
:=
bot
.
GetMessage
(
int32
(
i
))
if
m
!=
nil
{
if
m
!=
nil
{
sender
:=
m
[
"sender"
]
.
(
message
.
Sender
)
sender
:=
m
[
"sender"
]
.
(
message
.
Sender
)
nodes
=
append
(
nodes
,
&
message
.
ForwardNode
{
nodes
=
append
(
nodes
,
&
message
.
ForwardNode
{
...
@@ -412,11 +412,19 @@ func (bot *CQBot) CQProcessGroupRequest(flag, subType, reason string, approve bo
...
@@ -412,11 +412,19 @@ func (bot *CQBot) CQProcessGroupRequest(flag, subType, reason string, approve bo
// https://cqhttp.cc/docs/4.15/#/API?id=delete_msg-%E6%92%A4%E5%9B%9E%E6%B6%88%E6%81%AF
// https://cqhttp.cc/docs/4.15/#/API?id=delete_msg-%E6%92%A4%E5%9B%9E%E6%B6%88%E6%81%AF
func
(
bot
*
CQBot
)
CQDeleteMessage
(
messageId
int32
)
MSG
{
func
(
bot
*
CQBot
)
CQDeleteMessage
(
messageId
int32
)
MSG
{
msg
:=
bot
.
Get
Group
Message
(
messageId
)
msg
:=
bot
.
GetMessage
(
messageId
)
if
msg
==
nil
{
if
msg
==
nil
{
return
Failed
(
100
)
return
Failed
(
100
)
}
}
bot
.
Client
.
RecallGroupMessage
(
msg
[
"group"
]
.
(
int64
),
msg
[
"message-id"
]
.
(
int32
),
msg
[
"internal-id"
]
.
(
int32
))
if
_
,
ok
:=
msg
[
"group"
];
ok
{
bot
.
Client
.
RecallGroupMessage
(
msg
[
"group"
]
.
(
int64
),
msg
[
"message-id"
]
.
(
int32
),
msg
[
"internal-id"
]
.
(
int32
))
}
else
{
if
msg
[
"sender"
]
.
(
message
.
Sender
)
.
Uin
!=
bot
.
Client
.
Uin
{
log
.
Warnf
(
"撤回 %v 失败: 好友会话无法撤回对方消息."
)
return
Failed
(
100
)
}
bot
.
Client
.
RecallPrivateMessage
(
msg
[
"target"
]
.
(
int64
),
int64
(
msg
[
"time"
]
.
(
int32
)),
msg
[
"message-id"
]
.
(
int32
),
msg
[
"internal-id"
]
.
(
int32
))
}
return
OK
(
nil
)
return
OK
(
nil
)
}
}
...
@@ -638,15 +646,17 @@ func (bot *CQBot) CQGetForwardMessage(resId string) MSG {
...
@@ -638,15 +646,17 @@ func (bot *CQBot) CQGetForwardMessage(resId string) MSG {
})
})
}
}
func
(
bot
*
CQBot
)
CQGet
Group
Message
(
messageId
int32
)
MSG
{
func
(
bot
*
CQBot
)
CQGetMessage
(
messageId
int32
)
MSG
{
msg
:=
bot
.
Get
Group
Message
(
messageId
)
msg
:=
bot
.
GetMessage
(
messageId
)
if
msg
==
nil
{
if
msg
==
nil
{
return
Failed
(
100
)
return
Failed
(
100
)
}
}
sender
:=
msg
[
"sender"
]
.
(
message
.
Sender
)
sender
:=
msg
[
"sender"
]
.
(
message
.
Sender
)
_
,
group
:=
msg
[
"group"
]
return
OK
(
MSG
{
return
OK
(
MSG
{
"message_id"
:
messageId
,
"message_id"
:
messageId
,
"real_id"
:
msg
[
"message-id"
],
"real_id"
:
msg
[
"message-id"
],
"group"
:
group
,
"sender"
:
MSG
{
"sender"
:
MSG
{
"user_id"
:
sender
.
Uin
,
"user_id"
:
sender
.
Uin
,
"nickname"
:
sender
.
Nickname
,
"nickname"
:
sender
.
Nickname
,
...
...
coolq/bot.go
View file @
2302cf62
...
@@ -5,6 +5,7 @@ import (
...
@@ -5,6 +5,7 @@ import (
"encoding/gob"
"encoding/gob"
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"github.com/syndtr/goleveldb/leveldb"
"hash/crc32"
"hash/crc32"
"path"
"path"
"sync"
"sync"
...
@@ -17,14 +18,13 @@ import (
...
@@ -17,14 +18,13 @@ import (
log
"github.com/sirupsen/logrus"
log
"github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
"github.com/tidwall/gjson"
"github.com/xujiajun/nutsdb"
)
)
type
CQBot
struct
{
type
CQBot
struct
{
Client
*
client
.
QQClient
Client
*
client
.
QQClient
events
[]
func
(
MSG
)
events
[]
func
(
MSG
)
db
*
nuts
db
.
DB
db
*
level
db
.
DB
friendReqCache
sync
.
Map
friendReqCache
sync
.
Map
invitedReqCache
sync
.
Map
invitedReqCache
sync
.
Map
joinReqCache
sync
.
Map
joinReqCache
sync
.
Map
...
@@ -41,10 +41,8 @@ func NewQQBot(cli *client.QQClient, conf *global.JsonConfig) *CQBot {
...
@@ -41,10 +41,8 @@ func NewQQBot(cli *client.QQClient, conf *global.JsonConfig) *CQBot {
Client
:
cli
,
Client
:
cli
,
}
}
if
conf
.
EnableDB
{
if
conf
.
EnableDB
{
opt
:=
nutsdb
.
DefaultOptions
p
:=
path
.
Join
(
"data"
,
"leveldb"
)
opt
.
Dir
=
path
.
Join
(
"data"
,
"db"
)
db
,
err
:=
leveldb
.
OpenFile
(
p
,
nil
)
opt
.
EntryIdxMode
=
nutsdb
.
HintBPTSparseIdxMode
db
,
err
:=
nutsdb
.
Open
(
opt
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatalf
(
"打开数据库失败, 如果频繁遇到此问题请清理 data/db 文件夹或关闭数据库功能。"
)
log
.
Fatalf
(
"打开数据库失败, 如果频繁遇到此问题请清理 data/db 文件夹或关闭数据库功能。"
)
}
}
...
@@ -61,6 +59,7 @@ func NewQQBot(cli *client.QQClient, conf *global.JsonConfig) *CQBot {
...
@@ -61,6 +59,7 @@ func NewQQBot(cli *client.QQClient, conf *global.JsonConfig) *CQBot {
bot
.
Client
.
OnGroupMessageRecalled
(
bot
.
groupRecallEvent
)
bot
.
Client
.
OnGroupMessageRecalled
(
bot
.
groupRecallEvent
)
bot
.
Client
.
OnGroupNotify
(
bot
.
groupNotifyEvent
)
bot
.
Client
.
OnGroupNotify
(
bot
.
groupNotifyEvent
)
bot
.
Client
.
OnFriendMessageRecalled
(
bot
.
friendRecallEvent
)
bot
.
Client
.
OnFriendMessageRecalled
(
bot
.
friendRecallEvent
)
bot
.
Client
.
OnReceivedOfflineFile
(
bot
.
offlineFileEvent
)
bot
.
Client
.
OnJoinGroup
(
bot
.
joinGroupEvent
)
bot
.
Client
.
OnJoinGroup
(
bot
.
joinGroupEvent
)
bot
.
Client
.
OnLeaveGroup
(
bot
.
leaveGroupEvent
)
bot
.
Client
.
OnLeaveGroup
(
bot
.
leaveGroupEvent
)
bot
.
Client
.
OnGroupMemberJoined
(
bot
.
memberJoinEvent
)
bot
.
Client
.
OnGroupMemberJoined
(
bot
.
memberJoinEvent
)
...
@@ -99,20 +98,17 @@ func (bot *CQBot) OnEventPush(f func(m MSG)) {
...
@@ -99,20 +98,17 @@ func (bot *CQBot) OnEventPush(f func(m MSG)) {
bot
.
events
=
append
(
bot
.
events
,
f
)
bot
.
events
=
append
(
bot
.
events
,
f
)
}
}
func
(
bot
*
CQBot
)
Get
Group
Message
(
mid
int32
)
MSG
{
func
(
bot
*
CQBot
)
GetMessage
(
mid
int32
)
MSG
{
if
bot
.
db
!=
nil
{
if
bot
.
db
!=
nil
{
m
:=
MSG
{}
m
:=
MSG
{}
err
:=
bot
.
db
.
View
(
func
(
tx
*
nutsdb
.
Tx
)
error
{
data
,
err
:=
bot
.
db
.
Get
(
binary
.
ToBytes
(
mid
),
nil
)
e
,
err
:=
tx
.
Get
(
"group-messages"
,
binary
.
ToBytes
(
mid
))
if
err
!=
nil
{
return
err
}
buff
:=
new
(
bytes
.
Buffer
)
buff
.
Write
(
binary
.
GZipUncompress
(
e
.
Value
))
return
gob
.
NewDecoder
(
buff
)
.
Decode
(
&
m
)
})
if
err
==
nil
{
if
err
==
nil
{
return
m
buff
:=
new
(
bytes
.
Buffer
)
buff
.
Write
(
binary
.
GZipUncompress
(
data
))
err
=
gob
.
NewDecoder
(
buff
)
.
Decode
(
&
m
)
if
err
==
nil
{
return
m
}
}
}
log
.
Warnf
(
"获取信息时出现错误: %v id: %v"
,
err
,
mid
)
log
.
Warnf
(
"获取信息时出现错误: %v id: %v"
,
err
,
mid
)
}
}
...
@@ -217,30 +213,73 @@ func (bot *CQBot) SendPrivateMessage(target int64, m *message.SendingMessage) in
...
@@ -217,30 +213,73 @@ func (bot *CQBot) SendPrivateMessage(target int64, m *message.SendingMessage) in
newElem
=
append
(
newElem
,
fm
)
newElem
=
append
(
newElem
,
fm
)
continue
continue
}
}
if
i
,
ok
:=
elem
.
(
*
message
.
VoiceElement
);
ok
{
fv
,
err
:=
bot
.
Client
.
UploadPrivatePtt
(
target
,
i
.
Data
)
if
err
!=
nil
{
log
.
Warnf
(
"警告: 好友 %v 消息语音上传失败: %v"
,
target
,
err
)
continue
}
newElem
=
append
(
newElem
,
fv
)
continue
}
if
i
,
ok
:=
elem
.
(
*
QQMusicElement
);
ok
{
var
msgStyle
uint32
=
4
if
i
.
MusicUrl
==
""
{
msgStyle
=
0
// fix vip song
}
bot
.
Client
.
SendFriendRichMessage
(
target
,
100497308
,
1
,
msgStyle
,
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
,
})
return
0
}
if
i
,
ok
:=
elem
.
(
*
CloudMusicElement
);
ok
{
bot
.
Client
.
SendFriendRichMessage
(
target
,
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
,
})
return
0
}
newElem
=
append
(
newElem
,
elem
)
newElem
=
append
(
newElem
,
elem
)
}
}
m
.
Elements
=
newElem
m
.
Elements
=
newElem
var
id
int32
=
-
1
var
id
int32
=
-
1
if
bot
.
Client
.
FindFriend
(
target
)
!=
nil
{
if
bot
.
Client
.
FindFriend
(
target
)
!=
nil
{
// 双向好友
msg
:=
bot
.
Client
.
SendPrivateMessage
(
target
,
m
)
msg
:=
bot
.
Client
.
SendPrivateMessage
(
target
,
m
)
if
msg
!=
nil
{
if
msg
!=
nil
{
id
=
msg
.
Id
id
=
bot
.
InsertPrivateMessage
(
msg
)
}
}
}
else
if
code
,
ok
:=
bot
.
tempMsgCache
.
Load
(
target
);
ok
{
}
else
if
code
,
ok
:=
bot
.
tempMsgCache
.
Load
(
target
);
ok
{
// 临时会话
msg
:=
bot
.
Client
.
SendTempMessage
(
code
.
(
int64
),
target
,
m
)
msg
:=
bot
.
Client
.
SendTempMessage
(
code
.
(
int64
),
target
,
m
)
if
msg
!=
nil
{
if
msg
!=
nil
{
id
=
msg
.
Id
id
=
msg
.
Id
}
}
}
else
if
_
,
ok
:=
bot
.
oneWayMsgCache
.
Load
(
target
);
ok
{
}
else
if
_
,
ok
:=
bot
.
oneWayMsgCache
.
Load
(
target
);
ok
{
// 单向好友
msg
:=
bot
.
Client
.
SendPrivateMessage
(
target
,
m
)
msg
:=
bot
.
Client
.
SendPrivateMessage
(
target
,
m
)
if
msg
!=
nil
{
if
msg
!=
nil
{
id
=
msg
.
Id
id
=
bot
.
InsertPrivateMessage
(
msg
)
}
}
}
}
if
id
==
-
1
{
if
id
==
-
1
{
return
-
1
return
-
1
}
}
return
ToGlobalId
(
target
,
id
)
return
id
}
}
func
(
bot
*
CQBot
)
InsertGroupMessage
(
m
*
message
.
GroupMessage
)
int32
{
func
(
bot
*
CQBot
)
InsertGroupMessage
(
m
*
message
.
GroupMessage
)
int32
{
...
@@ -255,14 +294,36 @@ func (bot *CQBot) InsertGroupMessage(m *message.GroupMessage) int32 {
...
@@ -255,14 +294,36 @@ func (bot *CQBot) InsertGroupMessage(m *message.GroupMessage) int32 {
}
}
id
:=
ToGlobalId
(
m
.
GroupCode
,
m
.
Id
)
id
:=
ToGlobalId
(
m
.
GroupCode
,
m
.
Id
)
if
bot
.
db
!=
nil
{
if
bot
.
db
!=
nil
{
err
:=
bot
.
db
.
Update
(
func
(
tx
*
nutsdb
.
Tx
)
error
{
buf
:=
new
(
bytes
.
Buffer
)
buf
:=
new
(
bytes
.
Buffer
)
if
err
:=
gob
.
NewEncoder
(
buf
)
.
Encode
(
val
);
err
!=
nil
{
if
err
:=
gob
.
NewEncoder
(
buf
)
.
Encode
(
val
);
err
!=
nil
{
log
.
Warnf
(
"记录聊天数据时出现错误: %v"
,
err
)
return
err
return
-
1
}
}
return
tx
.
Put
(
"group-messages"
,
binary
.
ToBytes
(
id
),
binary
.
GZipCompress
(
buf
.
Bytes
()),
0
)
if
err
:=
bot
.
db
.
Put
(
binary
.
ToBytes
(
id
),
binary
.
GZipCompress
(
buf
.
Bytes
()),
nil
);
err
!=
nil
{
})
log
.
Warnf
(
"记录聊天数据时出现错误: %v"
,
err
)
if
err
!=
nil
{
return
-
1
}
}
return
id
}
func
(
bot
*
CQBot
)
InsertPrivateMessage
(
m
*
message
.
PrivateMessage
)
int32
{
val
:=
MSG
{
"message-id"
:
m
.
Id
,
"internal-id"
:
m
.
InternalId
,
"target"
:
m
.
Target
,
"sender"
:
m
.
Sender
,
"time"
:
m
.
Time
,
"message"
:
ToStringMessage
(
m
.
Elements
,
m
.
Sender
.
Uin
,
true
),
}
id
:=
ToGlobalId
(
m
.
Sender
.
Uin
,
m
.
Id
)
if
bot
.
db
!=
nil
{
buf
:=
new
(
bytes
.
Buffer
)
if
err
:=
gob
.
NewEncoder
(
buf
)
.
Encode
(
val
);
err
!=
nil
{
log
.
Warnf
(
"记录聊天数据时出现错误: %v"
,
err
)
return
-
1
}
if
err
:=
bot
.
db
.
Put
(
binary
.
ToBytes
(
id
),
binary
.
GZipCompress
(
buf
.
Bytes
()),
nil
);
err
!=
nil
{
log
.
Warnf
(
"记录聊天数据时出现错误: %v"
,
err
)
log
.
Warnf
(
"记录聊天数据时出现错误: %v"
,
err
)
return
-
1
return
-
1
}
}
...
...
coolq/cqcode.go
View file @
2302cf62
This diff is collapsed.
Click to expand it.
coolq/event.go
View file @
2302cf62
...
@@ -31,18 +31,22 @@ func ToFormattedMessage(e []message.IMessageElement, code int64, raw ...bool) (r
...
@@ -31,18 +31,22 @@ func ToFormattedMessage(e []message.IMessageElement, code int64, raw ...bool) (r
func
(
bot
*
CQBot
)
privateMessageEvent
(
c
*
client
.
QQClient
,
m
*
message
.
PrivateMessage
)
{
func
(
bot
*
CQBot
)
privateMessageEvent
(
c
*
client
.
QQClient
,
m
*
message
.
PrivateMessage
)
{
bot
.
checkMedia
(
m
.
Elements
)
bot
.
checkMedia
(
m
.
Elements
)
cqm
:=
ToStringMessage
(
m
.
Elements
,
0
,
true
)
cqm
:=
ToStringMessage
(
m
.
Elements
,
m
.
Sender
.
Uin
,
true
)
if
!
m
.
Sender
.
IsFriend
{
if
!
m
.
Sender
.
IsFriend
{
bot
.
oneWayMsgCache
.
Store
(
m
.
Sender
.
Uin
,
""
)
bot
.
oneWayMsgCache
.
Store
(
m
.
Sender
.
Uin
,
""
)
}
}
log
.
Infof
(
"收到好友 %v(%v) 的消息: %v"
,
m
.
Sender
.
DisplayName
(),
m
.
Sender
.
Uin
,
cqm
)
id
:=
m
.
Id
if
bot
.
db
!=
nil
{
id
=
bot
.
InsertPrivateMessage
(
m
)
}
log
.
Infof
(
"收到好友 %v(%v) 的消息: %v (%v)"
,
m
.
Sender
.
DisplayName
(),
m
.
Sender
.
Uin
,
cqm
,
id
)
fm
:=
MSG
{
fm
:=
MSG
{
"post_type"
:
"message"
,
"post_type"
:
"message"
,
"message_type"
:
"private"
,
"message_type"
:
"private"
,
"sub_type"
:
"friend"
,
"sub_type"
:
"friend"
,
"message_id"
:
ToGlobalId
(
m
.
Sender
.
Uin
,
m
.
Id
)
,
"message_id"
:
id
,
"user_id"
:
m
.
Sender
.
Uin
,
"user_id"
:
m
.
Sender
.
Uin
,
"message"
:
ToFormattedMessage
(
m
.
Elements
,
0
,
false
),
"message"
:
ToFormattedMessage
(
m
.
Elements
,
m
.
Sender
.
Uin
,
false
),
"raw_message"
:
cqm
,
"raw_message"
:
cqm
,
"font"
:
0
,
"font"
:
0
,
"self_id"
:
c
.
Uin
,
"self_id"
:
c
.
Uin
,
...
@@ -278,6 +282,26 @@ func (bot *CQBot) friendRecallEvent(c *client.QQClient, e *client.FriendMessageR
...
@@ -278,6 +282,26 @@ func (bot *CQBot) friendRecallEvent(c *client.QQClient, e *client.FriendMessageR
})
})
}
}
func
(
bot
*
CQBot
)
offlineFileEvent
(
c
*
client
.
QQClient
,
e
*
client
.
OfflineFileEvent
)
{
f
:=
c
.
FindFriend
(
e
.
Sender
)
if
f
==
nil
{
return
}
log
.
Infof
(
"好友 %v(%v) 发送了离线文件 %v"
,
f
.
Nickname
,
f
.
Uin
,
e
.
FileName
)
bot
.
dispatchEventMessage
(
MSG
{
"post_type"
:
"notice"
,
"notice_type"
:
"offline_file"
,
"user_id"
:
e
.
Sender
,
"file"
:
MSG
{
"name"
:
e
.
FileName
,
"size"
:
e
.
FileSize
,
"url"
:
e
.
DownloadUrl
,
},
"self_id"
:
c
.
Uin
,
"time"
:
time
.
Now
()
.
Unix
(),
})
}
func
(
bot
*
CQBot
)
joinGroupEvent
(
c
*
client
.
QQClient
,
group
*
client
.
GroupInfo
)
{
func
(
bot
*
CQBot
)
joinGroupEvent
(
c
*
client
.
QQClient
,
group
*
client
.
GroupInfo
)
{
log
.
Infof
(
"Bot进入了群 %v."
,
formatGroupName
(
group
))
log
.
Infof
(
"Bot进入了群 %v."
,
formatGroupName
(
group
))
bot
.
dispatchEventMessage
(
bot
.
groupIncrease
(
group
.
Code
,
0
,
c
.
Uin
))
bot
.
dispatchEventMessage
(
bot
.
groupIncrease
(
group
.
Code
,
0
,
c
.
Uin
))
...
...
docs/QA.md
View file @
2302cf62
# 常见问题
# 常见问题
### Q: 为什么登录的时候出现 `客户端版本过低 请升级客户端`?
### A: 此问题是因为密码输入错误导致的, 信息为服务器返回, 很可能是TX相关的错误, 请检查密码
### Q: 为什么登录的时候出现 `为了您的帐号安全,请使用QQ一键登录`?
### A: 因为目前手机协议不支持图片验证码,切换成平板协议登录成功后,再切换回手机协议即可
### Q: 为什么挂一段时间后就会出现 `消息发送失败,账号可能被风控`?
### Q: 为什么挂一段时间后就会出现 `消息发送失败,账号可能被风控`?
### A: 如果你刚开始使用 go-cqhttp 建议挂机3-7天,即可解除风控
### A: 如果你刚开始使用 go-cqhttp 建议挂机3-7天,即可解除风控
go.mod
View file @
2302cf62
...
@@ -3,32 +3,19 @@ module github.com/Mrs4s/go-cqhttp
...
@@ -3,32 +3,19 @@ module github.com/Mrs4s/go-cqhttp
go 1.14
go 1.14
require (
require (
github.com/Mrs4s/MiraiGo v0.0.0-20201011070235-2fa335fd8b68
github.com/Mrs4s/MiraiGo v0.0.0-20201017083749-517ddcd50b8d
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/gorilla/websocket v1.4.2
github.com/gorilla/websocket v1.4.2
github.com/guonaihong/gout v0.1.2
github.com/guonaihong/gout v0.1.2
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 // indirect
github.com/jonboulle/clockwork v0.2.0 // indirect
github.com/json-iterator/go v1.1.10 // indirect
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
github.com/lestrrat-go/strftime v1.0.3 // indirect
github.com/lestrrat-go/strftime v1.0.3 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
github.com/sirupsen/logrus v1.7.0
github.com/sirupsen/logrus v1.7.0
github.com/syndtr/goleveldb v1.0.0
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816
github.com/tebeka/strftime v0.1.5 // indirect
github.com/tidwall/gjson v1.6.1
github.com/tidwall/gjson v1.6.1
github.com/ugorji/go v1.1.10 // indirect
github.com/wdvxdr1123/go-silk v0.0.0-20201007123416-b982fd3d91d6
github.com/wdvxdr1123/go-silk v0.0.0-20201007123416-b982fd3d91d6
github.com/xujiajun/nutsdb v0.5.0
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0 // indirect
golang.org/x/net v0.0.0-20201010224723-4f7140c49acb // indirect
golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634 // indirect
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
gopkg.in/yaml.v2 v2.3.0 // indirect
)
)
go.sum
View file @
2302cf62
This diff is collapsed.
Click to expand it.
server/apiAdmin.go
View file @
2302cf62
...
@@ -77,7 +77,9 @@ func (s *webServer) Run(addr string, cli *client.QQClient) *coolq.CQBot {
...
@@ -77,7 +77,9 @@ func (s *webServer) Run(addr string, cli *client.QQClient) *coolq.CQBot {
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Error
(
err
)
log
.
Error
(
err
)
log
.
Infof
(
"请检查端口是否被占用."
)
log
.
Infof
(
"请检查端口是否被占用."
)
time
.
Sleep
(
time
.
Second
*
5
)
c
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
c
,
os
.
Interrupt
,
os
.
Kill
)
<-
c
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
}
else
{
}
else
{
...
@@ -96,6 +98,10 @@ func (s *webServer) Run(addr string, cli *client.QQClient) *coolq.CQBot {
...
@@ -96,6 +98,10 @@ func (s *webServer) Run(addr string, cli *client.QQClient) *coolq.CQBot {
func
(
s
*
webServer
)
Dologin
()
{
func
(
s
*
webServer
)
Dologin
()
{
s
.
Console
=
bufio
.
NewReader
(
os
.
Stdin
)
s
.
Console
=
bufio
.
NewReader
(
os
.
Stdin
)
readLine
:=
func
()
(
str
string
)
{
str
,
_
=
s
.
Console
.
ReadString
(
'\n'
)
return
}
conf
:=
GetConf
()
conf
:=
GetConf
()
cli
:=
s
.
Cli
cli
:=
s
.
Cli
cli
.
AllowSlider
=
true
cli
.
AllowSlider
=
true
...
@@ -109,7 +115,7 @@ func (s *webServer) Dologin() {
...
@@ -109,7 +115,7 @@ func (s *webServer) Dologin() {
if
client
.
SystemDeviceInfo
.
Protocol
==
client
.
AndroidPhone
{
if
client
.
SystemDeviceInfo
.
Protocol
==
client
.
AndroidPhone
{
log
.
Warnf
(
"警告: Android Phone 强制要求暂不支持的滑条验证码, 请开启设备锁或切换到Watch协议验证通过后再使用."
)
log
.
Warnf
(
"警告: Android Phone 强制要求暂不支持的滑条验证码, 请开启设备锁或切换到Watch协议验证通过后再使用."
)
log
.
Infof
(
"按 Enter 继续...."
)
log
.
Infof
(
"按 Enter 继续...."
)
_
,
_
=
s
.
Console
.
ReadString
(
'\n'
)
readLine
(
)
os
.
Exit
(
0
)
os
.
Exit
(
0
)
}
}
cli
.
AllowSlider
=
false
cli
.
AllowSlider
=
false
...
@@ -125,21 +131,21 @@ func (s *webServer) Dologin() {
...
@@ -125,21 +131,21 @@ func (s *webServer) Dologin() {
text
=
<-
WebInput
text
=
<-
WebInput
}
else
{
}
else
{
log
.
Warn
(
"请输入验证码 (captcha.jpg): (Enter 提交)"
)
log
.
Warn
(
"请输入验证码 (captcha.jpg): (Enter 提交)"
)
text
,
_
=
s
.
Console
.
ReadString
(
'\n'
)
text
=
readLine
(
)
}
}
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
.
SMSNeededError
:
case
client
.
SMSNeededError
:
log
.
Warnf
(
"账号已开启设备锁, 按下 Enter 向手机 %v 发送短信验证码."
,
rsp
.
SMSPhone
)
log
.
Warnf
(
"账号已开启设备锁, 按下 Enter 向手机 %v 发送短信验证码."
,
rsp
.
SMSPhone
)
_
,
_
=
s
.
Console
.
ReadString
(
'\n'
)
readLine
(
)
if
!
cli
.
RequestSMS
()
{
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
=
readLine
(
)
rsp
,
err
=
cli
.
SubmitSMS
(
strings
.
ReplaceAll
(
strings
.
ReplaceAll
(
text
,
"
\n
"
,
""
),
"
\r
"
,
""
))
rsp
,
err
=
cli
.
SubmitSMS
(
strings
.
ReplaceAll
(
strings
.
ReplaceAll
(
text
,
"
\n
"
,
""
),
"
\r
"
,
""
))
continue
continue
case
client
.
SMSOrVerifyNeededError
:
case
client
.
SMSOrVerifyNeededError
:
...
@@ -147,7 +153,7 @@ func (s *webServer) Dologin() {
...
@@ -147,7 +153,7 @@ func (s *webServer) Dologin() {
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
=
readLine
(
)
if
strings
.
Contains
(
text
,
"1"
)
{
if
strings
.
Contains
(
text
,
"1"
)
{
if
!
cli
.
RequestSMS
()
{
if
!
cli
.
RequestSMS
()
{
log
.
Warnf
(
"发送验证码失败,可能是请求过于频繁."
)
log
.
Warnf
(
"发送验证码失败,可能是请求过于频繁."
)
...
@@ -155,13 +161,13 @@ func (s *webServer) Dologin() {
...
@@ -155,13 +161,13 @@ func (s *webServer) Dologin() {
os
.
Exit
(
0
)
os
.
Exit
(
0
)
}
}
log
.
Warn
(
"请输入短信验证码: (Enter 提交)"
)
log
.
Warn
(
"请输入短信验证码: (Enter 提交)"
)
text
,
_
=
s
.
Console
.
ReadString
(
'\n'
)
text
=
readLine
(
)
rsp
,
err
=
cli
.
SubmitSMS
(
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
)
log
.
Infof
(
"按 Enter 继续...."
)
log
.
Infof
(
"按 Enter 继续...."
)
_
,
_
=
s
.
Console
.
ReadString
(
'\n'
)
readLine
(
)
os
.
Exit
(
0
)
os
.
Exit
(
0
)
return
return
case
client
.
UnsafeDeviceError
:
case
client
.
UnsafeDeviceError
:
...
@@ -171,7 +177,7 @@ func (s *webServer) Dologin() {
...
@@ -171,7 +177,7 @@ func (s *webServer) Dologin() {
text
=
<-
WebInput
text
=
<-
WebInput
}
else
{
}
else
{
log
.
Infof
(
"按 Enter 继续...."
)
log
.
Infof
(
"按 Enter 继续...."
)
_
,
_
=
s
.
Console
.
ReadString
(
'\n'
)
readLine
(
)
}
}
log
.
Info
(
text
)
log
.
Info
(
text
)
os
.
Exit
(
0
)
os
.
Exit
(
0
)
...
@@ -179,7 +185,7 @@ func (s *webServer) Dologin() {
...
@@ -179,7 +185,7 @@ func (s *webServer) Dologin() {
case
client
.
OtherLoginError
,
client
.
UnknownLoginError
:
case
client
.
OtherLoginError
,
client
.
UnknownLoginError
:
log
.
Warnf
(
"登录失败: %v"
,
rsp
.
ErrorMessage
)
log
.
Warnf
(
"登录失败: %v"
,
rsp
.
ErrorMessage
)
log
.
Infof
(
"按 Enter 继续...."
)
log
.
Infof
(
"按 Enter 继续...."
)
_
,
_
=
s
.
Console
.
ReadString
(
'\n'
)
readLine
(
)
os
.
Exit
(
0
)
os
.
Exit
(
0
)
return
return
}
}
...
...
server/http.go
View file @
2302cf62
...
@@ -234,9 +234,9 @@ func (s *httpServer) GetImage(c *gin.Context) {
...
@@ -234,9 +234,9 @@ func (s *httpServer) GetImage(c *gin.Context) {
c
.
JSON
(
200
,
s
.
bot
.
CQGetImage
(
file
))
c
.
JSON
(
200
,
s
.
bot
.
CQGetImage
(
file
))
}
}
func
(
s
*
httpServer
)
Get
Group
Message
(
c
*
gin
.
Context
)
{
func
(
s
*
httpServer
)
GetMessage
(
c
*
gin
.
Context
)
{
mid
,
_
:=
strconv
.
ParseInt
(
getParam
(
c
,
"message_id"
),
10
,
32
)
mid
,
_
:=
strconv
.
ParseInt
(
getParam
(
c
,
"message_id"
),
10
,
32
)
c
.
JSON
(
200
,
s
.
bot
.
CQGet
Group
Message
(
int32
(
mid
)))
c
.
JSON
(
200
,
s
.
bot
.
CQGetMessage
(
int32
(
mid
)))
}
}
func
(
s
*
httpServer
)
GetGroupHonorInfo
(
c
*
gin
.
Context
)
{
func
(
s
*
httpServer
)
GetGroupHonorInfo
(
c
*
gin
.
Context
)
{
...
@@ -501,8 +501,8 @@ var httpApi = map[string]func(s *httpServer, c *gin.Context){
...
@@ -501,8 +501,8 @@ var httpApi = map[string]func(s *httpServer, c *gin.Context){
"get_forward_msg"
:
func
(
s
*
httpServer
,
c
*
gin
.
Context
)
{
"get_forward_msg"
:
func
(
s
*
httpServer
,
c
*
gin
.
Context
)
{
s
.
GetForwardMessage
(
c
)
s
.
GetForwardMessage
(
c
)
},
},
"get_
group_
msg"
:
func
(
s
*
httpServer
,
c
*
gin
.
Context
)
{
"get_msg"
:
func
(
s
*
httpServer
,
c
*
gin
.
Context
)
{
s
.
Get
Group
Message
(
c
)
s
.
GetMessage
(
c
)
},
},
"get_group_honor_info"
:
func
(
s
*
httpServer
,
c
*
gin
.
Context
)
{
"get_group_honor_info"
:
func
(
s
*
httpServer
,
c
*
gin
.
Context
)
{
s
.
GetGroupHonorInfo
(
c
)
s
.
GetGroupHonorInfo
(
c
)
...
...
server/websocket.go
View file @
2302cf62
...
@@ -474,8 +474,8 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
...
@@ -474,8 +474,8 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
"get_forward_msg"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
"get_forward_msg"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQGetForwardMessage
(
p
.
Get
(
"message_id"
)
.
Str
)
return
bot
.
CQGetForwardMessage
(
p
.
Get
(
"message_id"
)
.
Str
)
},
},
"get_
group_
msg"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
"get_msg"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQGet
Group
Message
(
int32
(
p
.
Get
(
"message_id"
)
.
Int
()))
return
bot
.
CQGetMessage
(
int32
(
p
.
Get
(
"message_id"
)
.
Int
()))
},
},
"get_group_honor_info"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
"get_group_honor_info"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQGetGroupHonorInfo
(
p
.
Get
(
"group_id"
)
.
Int
(),
p
.
Get
(
"type"
)
.
Str
)
return
bot
.
CQGetGroupHonorInfo
(
p
.
Get
(
"group_id"
)
.
Int
(),
p
.
Get
(
"type"
)
.
Str
)
...
...
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