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
11592c44
Commit
11592c44
authored
Aug 27, 2020
by
QianjuNakasumi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增自定义心跳服务间隔时间及开关
parent
a9d08e5d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
13 deletions
+28
-13
coolq/bot.go
coolq/bot.go
+20
-12
docs/config.md
docs/config.md
+5
-1
global/config.go
global/config.go
+3
-0
No files found.
coolq/bot.go
View file @
11592c44
...
@@ -5,28 +5,31 @@ import (
...
@@ -5,28 +5,31 @@ 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
heartbeatInterval
uint16
invitedReqCache
sync
.
Map
friendReqCache
sync
.
Map
joinReqCache
sync
.
Map
invitedReqCache
sync
.
Map
tempMsgCache
sync
.
Map
joinReqCache
sync
.
Map
tempMsgCache
sync
.
Map
}
}
type
MSG
map
[
string
]
interface
{}
type
MSG
map
[
string
]
interface
{}
...
@@ -67,15 +70,20 @@ func NewQQBot(cli *client.QQClient, conf *global.JsonConfig) *CQBot {
...
@@ -67,15 +70,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 @
11592c44
...
@@ -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"
,
...
@@ -64,6 +65,7 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
...
@@ -64,6 +65,7 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
| post_message_format | string | 上报信息类型 |
| post_message_format | string | 上报信息类型 |
| ignore_invalid_cqcode| bool | 是否忽略错误的CQ码 |
| ignore_invalid_cqcode| bool | 是否忽略错误的CQ码 |
| force_fragmented | bool | 是否强制分片发送群长消息 |
| force_fragmented | bool | 是否强制分片发送群长消息 |
| heartbeat_interval | int64 | 心跳间隔时间,单位秒,若0则关闭心跳
| http_config | object | HTTP API配置 |
| http_config | object | HTTP API配置 |
| ws_config | object | Websocket API 配置 |
| ws_config | object | Websocket API 配置 |
| ws_reverse_servers | object[] | 反向 Websocket API 配置 |
| ws_reverse_servers | object[] | 反向 Websocket API 配置 |
...
@@ -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 @
11592c44
...
@@ -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