From 11592c44831df0e1932e0bef189127292ca314fc Mon Sep 17 00:00:00 2001 From: QianjuNakasumi Date: Thu, 27 Aug 2020 23:15:37 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E5=BF=83=E8=B7=B3=E6=9C=8D=E5=8A=A1=E9=97=B4=E9=9A=94?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E5=8F=8A=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- coolq/bot.go | 38 +++++++++++++++++++++++--------------- docs/config.md | 6 +++++- global/config.go | 3 +++ 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/coolq/bot.go b/coolq/bot.go index 6f36aa2..1aca793 100644 --- a/coolq/bot.go +++ b/coolq/bot.go @@ -5,28 +5,31 @@ import ( "encoding/gob" "encoding/json" "fmt" - "github.com/Mrs4s/MiraiGo/binary" - "github.com/Mrs4s/MiraiGo/client" - "github.com/Mrs4s/MiraiGo/message" - "github.com/Mrs4s/go-cqhttp/global" - log "github.com/sirupsen/logrus" - "github.com/tidwall/gjson" - "github.com/xujiajun/nutsdb" "hash/crc32" "path" "sync" "time" + + "github.com/Mrs4s/MiraiGo/binary" + "github.com/Mrs4s/MiraiGo/client" + "github.com/Mrs4s/MiraiGo/message" + "github.com/Mrs4s/go-cqhttp/global" + + log "github.com/sirupsen/logrus" + "github.com/tidwall/gjson" + "github.com/xujiajun/nutsdb" ) type CQBot struct { Client *client.QQClient - events []func(MSG) - db *nutsdb.DB - friendReqCache sync.Map - invitedReqCache sync.Map - joinReqCache sync.Map - tempMsgCache sync.Map + events []func(MSG) + db *nutsdb.DB + heartbeatInterval uint16 + friendReqCache sync.Map + invitedReqCache sync.Map + joinReqCache sync.Map + tempMsgCache sync.Map } type MSG map[string]interface{} @@ -67,15 +70,20 @@ func NewQQBot(cli *client.QQClient, conf *global.JsonConfig) *CQBot { bot.Client.OnGroupInvited(bot.groupInvitedEvent) bot.Client.OnUserWantJoinGroup(bot.groupJoinReqEvent) go func() { + i := conf.HeartbeatInterval + if i < 1 { + log.Warn("警告: 心跳功能已关闭,若非预期,请检查配置文件。") + return + } for { - time.Sleep(time.Second * 5) + time.Sleep(time.Second * i) bot.dispatchEventMessage(MSG{ "time": time.Now().Unix(), "self_id": bot.Client.Uin, "post_type": "meta_event", "meta_event_type": "heartbeat", "status": nil, - "interval": 5000, + "interval": 1000 * i, }) } }() diff --git a/docs/config.md b/docs/config.md index d3f0373..eb27e6d 100644 --- a/docs/config.md +++ b/docs/config.md @@ -27,6 +27,7 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为: "post_message_format": "string", "ignore_invalid_cqcode": false, "force_fragmented": true, + "heartbeat_interval": 5, "http_config": { "enabled": true, "host": "0.0.0.0", @@ -64,6 +65,7 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为: | post_message_format | string | 上报信息类型 | | ignore_invalid_cqcode| bool | 是否忽略错误的CQ码 | | force_fragmented | bool | 是否强制分片发送群长消息 | +| heartbeat_interval | int64 | 心跳间隔时间,单位秒,若0则关闭心跳 | http_config | object | HTTP API配置 | | ws_config | object | Websocket API 配置 | | ws_reverse_servers | object[] | 反向 Websocket API 配置 | @@ -73,4 +75,6 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为: > 解密后密码将储存在内存中,用于自动重连等功能. 所以此加密并不能防止内存读取. > 解密密钥在使用完成后并不会留存在内存中, 所以可用相对简单的字符串作为密钥 -> 注2: 分片发送为原酷Q发送长消息的老方案, 发送速度更优/兼容性更好。关闭后将优先使用新方案, 能发送更长的消息, 但发送速度更慢,在部分老客户端将无法解析. \ No newline at end of file +> 注2: 分片发送为原酷Q发送长消息的老方案, 发送速度更优/兼容性更好。关闭后将优先使用新方案, 能发送更长的消息, 但发送速度更慢,在部分老客户端将无法解析. + +> 注3:关闭心跳服务可能引起断线,请谨慎关闭 \ No newline at end of file diff --git a/global/config.go b/global/config.go index e384137..bd57850 100644 --- a/global/config.go +++ b/global/config.go @@ -2,6 +2,8 @@ package global import ( "encoding/json" + "time" + log "github.com/sirupsen/logrus" ) @@ -16,6 +18,7 @@ type JsonConfig struct { ReLoginDelay int `json:"relogin_delay"` IgnoreInvalidCQCode bool `json:"ignore_invalid_cqcode"` ForceFragmented bool `json:"force_fragmented"` + HeartbeatInterval time.Duration `json:"heartbeat_interval"` HttpConfig *GoCQHttpConfig `json:"http_config"` WSConfig *GoCQWebsocketConfig `json:"ws_config"` ReverseServers []*GoCQReverseWebsocketConfig `json:"ws_reverse_servers"` From 41614b9d1617c2a6e64830d19fc9cb53aeda4c3d Mon Sep 17 00:00:00 2001 From: QianjuNakasumi Date: Thu, 27 Aug 2020 23:20:45 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=BF=83=E8=B7=B3?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E9=97=B4=E9=9A=94=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/config.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/config.md b/docs/config.md index eb27e6d..7ee7c56 100644 --- a/docs/config.md +++ b/docs/config.md @@ -56,18 +56,18 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为: | ------------------ | -------- | ------------------------------------------------------------------- | | uin | int64 | 登录用QQ号 | | password | string | 登录用密码 | -| encrypt_password | bool | 是否对密码进行加密. | +| encrypt_password | bool | 是否对密码进行加密. | | password_encrypted | string | 加密后的密码(请勿修改) | -| enable_db | bool | 是否开启内置数据库, 关闭后将无法使用 **回复/撤回** 等上下文相关接口 | -| access_token | string | 同CQHTTP的 `access_token` 用于身份验证 | -| relogin | bool | 是否自动重新登录 | -| relogin_delay | int | 重登录延时(秒) | -| post_message_format | string | 上报信息类型 | -| ignore_invalid_cqcode| bool | 是否忽略错误的CQ码 | +| enable_db | bool | 是否开启内置数据库, 关闭后将无法使用 **回复/撤回** 等上下文相关接口 | +| access_token | string | 同CQHTTP的 `access_token` 用于身份验证 | +| relogin | bool | 是否自动重新登录 | +| relogin_delay | int | 重登录延时(秒) | +| post_message_format | string | 上报信息类型 | +| ignore_invalid_cqcode| bool | 是否忽略错误的CQ码 | | force_fragmented | bool | 是否强制分片发送群长消息 | -| heartbeat_interval | int64 | 心跳间隔时间,单位秒,若0则关闭心跳 -| http_config | object | HTTP API配置 | -| ws_config | object | Websocket API 配置 | +| heartbeat_interval | int64 | 心跳间隔时间,单位秒,若0则关闭心跳 | +| http_config | object | HTTP API配置 | +| ws_config | object | Websocket API 配置 | | ws_reverse_servers | object[] | 反向 Websocket API 配置 | | log_level | string | 指定日志收集级别,将收集的日志单独存放到固定文件中,便于查看日志线索 当前支持 warn,error| From 50191fcedf4c9cf5b5ff801ca6b923ebb75407a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=83=E6=A9=98=E9=9B=AB=E9=9C=9E?= <53565118+qianjunakasumi@users.noreply.github.com> Date: Thu, 27 Aug 2020 23:29:10 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=88=A0=E9=99=A4=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=8A=A0=E5=85=A5=E7=9A=84=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- coolq/bot.go | 1 - 1 file changed, 1 deletion(-) diff --git a/coolq/bot.go b/coolq/bot.go index 1aca793..d27ff7b 100644 --- a/coolq/bot.go +++ b/coolq/bot.go @@ -25,7 +25,6 @@ type CQBot struct { events []func(MSG) db *nutsdb.DB - heartbeatInterval uint16 friendReqCache sync.Map invitedReqCache sync.Map joinReqCache sync.Map