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
0894f2ac
Commit
0894f2ac
authored
Aug 27, 2020
by
Mrs4s
Committed by
GitHub
Aug 27, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #210 from qianjunakasumi/master
新增自定义心跳服务间隔时间及开关
parents
a9d08e5d
50191fce
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
22 deletions
+36
-22
coolq/bot.go
coolq/bot.go
+19
-12
docs/config.md
docs/config.md
+14
-10
global/config.go
global/config.go
+3
-0
No files found.
coolq/bot.go
View file @
0894f2ac
...
@@ -5,28 +5,30 @@ import (
...
@@ -5,28 +5,30 @@ import (
"encoding/gob"
"encoding/gob"
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"hash/crc32"
"path"
"sync"
"time"
"github.com/Mrs4s/MiraiGo/binary"
"github.com/Mrs4s/MiraiGo/binary"
"github.com/Mrs4s/MiraiGo/client"
"github.com/Mrs4s/MiraiGo/client"
"github.com/Mrs4s/MiraiGo/message"
"github.com/Mrs4s/MiraiGo/message"
"github.com/Mrs4s/go-cqhttp/global"
"github.com/Mrs4s/go-cqhttp/global"
log
"github.com/sirupsen/logrus"
log
"github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
"github.com/tidwall/gjson"
"github.com/xujiajun/nutsdb"
"github.com/xujiajun/nutsdb"
"hash/crc32"
"path"
"sync"
"time"
)
)
type
CQBot
struct
{
type
CQBot
struct
{
Client
*
client
.
QQClient
Client
*
client
.
QQClient
events
[]
func
(
MSG
)
events
[]
func
(
MSG
)
db
*
nutsdb
.
DB
db
*
nutsdb
.
DB
friendReqCache
sync
.
Map
friendReqCache
sync
.
Map
invitedReqCache
sync
.
Map
invitedReqCache
sync
.
Map
joinReqCache
sync
.
Map
joinReqCache
sync
.
Map
tempMsgCache
sync
.
Map
tempMsgCache
sync
.
Map
}
}
type
MSG
map
[
string
]
interface
{}
type
MSG
map
[
string
]
interface
{}
...
@@ -67,15 +69,20 @@ func NewQQBot(cli *client.QQClient, conf *global.JsonConfig) *CQBot {
...
@@ -67,15 +69,20 @@ func NewQQBot(cli *client.QQClient, conf *global.JsonConfig) *CQBot {
bot
.
Client
.
OnGroupInvited
(
bot
.
groupInvitedEvent
)
bot
.
Client
.
OnGroupInvited
(
bot
.
groupInvitedEvent
)
bot
.
Client
.
OnUserWantJoinGroup
(
bot
.
groupJoinReqEvent
)
bot
.
Client
.
OnUserWantJoinGroup
(
bot
.
groupJoinReqEvent
)
go
func
()
{
go
func
()
{
i
:=
conf
.
HeartbeatInterval
if
i
<
1
{
log
.
Warn
(
"警告: 心跳功能已关闭,若非预期,请检查配置文件。"
)
return
}
for
{
for
{
time
.
Sleep
(
time
.
Second
*
5
)
time
.
Sleep
(
time
.
Second
*
i
)
bot
.
dispatchEventMessage
(
MSG
{
bot
.
dispatchEventMessage
(
MSG
{
"time"
:
time
.
Now
()
.
Unix
(),
"time"
:
time
.
Now
()
.
Unix
(),
"self_id"
:
bot
.
Client
.
Uin
,
"self_id"
:
bot
.
Client
.
Uin
,
"post_type"
:
"meta_event"
,
"post_type"
:
"meta_event"
,
"meta_event_type"
:
"heartbeat"
,
"meta_event_type"
:
"heartbeat"
,
"status"
:
nil
,
"status"
:
nil
,
"interval"
:
5000
,
"interval"
:
1000
*
i
,
})
})
}
}
}()
}()
...
...
docs/config.md
View file @
0894f2ac
...
@@ -27,6 +27,7 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
...
@@ -27,6 +27,7 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
"post_message_format"
:
"string"
,
"post_message_format"
:
"string"
,
"ignore_invalid_cqcode"
:
false
,
"ignore_invalid_cqcode"
:
false
,
"force_fragmented"
:
true
,
"force_fragmented"
:
true
,
"heartbeat_interval"
:
5
,
"http_config"
:
{
"http_config"
:
{
"enabled"
:
true
,
"enabled"
:
true
,
"host"
:
"0.0.0.0"
,
"host"
:
"0.0.0.0"
,
...
@@ -55,17 +56,18 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
...
@@ -55,17 +56,18 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
| ------------------ | -------- | ------------------------------------------------------------------- |
| ------------------ | -------- | ------------------------------------------------------------------- |
| uin | int64 | 登录用QQ号 |
| uin | int64 | 登录用QQ号 |
| password | string | 登录用密码 |
| password | string | 登录用密码 |
| encrypt_password | bool | 是否对密码进行加密. |
| encrypt_password | bool | 是否对密码进行加密.
|
| password_encrypted | string | 加密后的密码(请勿修改) |
| password_encrypted | string | 加密后的密码(请勿修改) |
| enable_db | bool | 是否开启内置数据库, 关闭后将无法使用
**回复/撤回**
等上下文相关接口 |
| enable_db | bool | 是否开启内置数据库, 关闭后将无法使用
**回复/撤回**
等上下文相关接口
|
| access_token | string | 同CQHTTP的
`access_token`
用于身份验证 |
| access_token | string | 同CQHTTP的
`access_token`
用于身份验证
|
| relogin | bool | 是否自动重新登录 |
| relogin | bool | 是否自动重新登录
|
| relogin_delay | int | 重登录延时(秒) |
| relogin_delay | int | 重登录延时(秒)
|
| post_message_format | string | 上报信息类型 |
| post_message_format | string | 上报信息类型
|
| ignore_invalid_cqcode| bool | 是否忽略错误的CQ码 |
| ignore_invalid_cqcode| bool | 是否忽略错误的CQ码
|
| force_fragmented | bool | 是否强制分片发送群长消息 |
| force_fragmented | bool | 是否强制分片发送群长消息 |
| http_config | object | HTTP API配置 |
| heartbeat_interval | int64 | 心跳间隔时间,单位秒,若0则关闭心跳 |
| ws_config | object | Websocket API 配置 |
| http_config | object | HTTP API配置 |
| ws_config | object | Websocket API 配置 |
| ws_reverse_servers | object[] | 反向 Websocket API 配置 |
| ws_reverse_servers | object[] | 反向 Websocket API 配置 |
| log_level | string | 指定日志收集级别,将收集的日志单独存放到固定文件中,便于查看日志线索 当前支持 warn,error|
| log_level | string | 指定日志收集级别,将收集的日志单独存放到固定文件中,便于查看日志线索 当前支持 warn,error|
...
@@ -73,4 +75,6 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
...
@@ -73,4 +75,6 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
> 解密后密码将储存在内存中,用于自动重连等功能. 所以此加密并不能防止内存读取.
> 解密后密码将储存在内存中,用于自动重连等功能. 所以此加密并不能防止内存读取.
> 解密密钥在使用完成后并不会留存在内存中, 所以可用相对简单的字符串作为密钥
> 解密密钥在使用完成后并不会留存在内存中, 所以可用相对简单的字符串作为密钥
> 注2: 分片发送为原酷Q发送长消息的老方案, 发送速度更优/兼容性更好。关闭后将优先使用新方案, 能发送更长的消息, 但发送速度更慢,在部分老客户端将无法解析.
> 注2: 分片发送为原酷Q发送长消息的老方案, 发送速度更优/兼容性更好。关闭后将优先使用新方案, 能发送更长的消息, 但发送速度更慢,在部分老客户端将无法解析.
\ No newline at end of file
> 注3:关闭心跳服务可能引起断线,请谨慎关闭
\ No newline at end of file
global/config.go
View file @
0894f2ac
...
@@ -2,6 +2,8 @@ package global
...
@@ -2,6 +2,8 @@ package global
import
(
import
(
"encoding/json"
"encoding/json"
"time"
log
"github.com/sirupsen/logrus"
log
"github.com/sirupsen/logrus"
)
)
...
@@ -16,6 +18,7 @@ type JsonConfig struct {
...
@@ -16,6 +18,7 @@ type JsonConfig struct {
ReLoginDelay
int
`json:"relogin_delay"`
ReLoginDelay
int
`json:"relogin_delay"`
IgnoreInvalidCQCode
bool
`json:"ignore_invalid_cqcode"`
IgnoreInvalidCQCode
bool
`json:"ignore_invalid_cqcode"`
ForceFragmented
bool
`json:"force_fragmented"`
ForceFragmented
bool
`json:"force_fragmented"`
HeartbeatInterval
time
.
Duration
`json:"heartbeat_interval"`
HttpConfig
*
GoCQHttpConfig
`json:"http_config"`
HttpConfig
*
GoCQHttpConfig
`json:"http_config"`
WSConfig
*
GoCQWebsocketConfig
`json:"ws_config"`
WSConfig
*
GoCQWebsocketConfig
`json:"ws_config"`
ReverseServers
[]
*
GoCQReverseWebsocketConfig
`json:"ws_reverse_servers"`
ReverseServers
[]
*
GoCQReverseWebsocketConfig
`json:"ws_reverse_servers"`
...
...
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