mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-05 03:23:49 +08:00
reconnect supported.
This commit is contained in:
parent
82e2ea8466
commit
847711cd39
@ -6,14 +6,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type JsonConfig struct {
|
type JsonConfig struct {
|
||||||
Uin int64 `json:"uin"`
|
Uin int64 `json:"uin"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
EnableDB bool `json:"enable_db"`
|
EnableDB bool `json:"enable_db"`
|
||||||
AccessToken string `json:"access_token"`
|
AccessToken string `json:"access_token"`
|
||||||
//Reconnect bool `json:"reconnect"`
|
Reconnect bool `json:"reconnect"`
|
||||||
//ReconnectDelay int `json:"reconnect_delay"`
|
ReconnectDelay int `json:"reconnect_delay"`
|
||||||
HttpConfig *GoCQHttpConfig `json:"http_config"`
|
HttpConfig *GoCQHttpConfig `json:"http_config"`
|
||||||
WSConfig *GoCQWebsocketConfig `json:"ws_config"`
|
WSConfig *GoCQWebsocketConfig `json:"ws_config"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CQHttpApiConfig struct {
|
type CQHttpApiConfig struct {
|
||||||
|
21
main.go
21
main.go
@ -140,8 +140,27 @@ func main() {
|
|||||||
log.Info("资源初始化完成, 开始处理信息.")
|
log.Info("资源初始化完成, 开始处理信息.")
|
||||||
log.Info("アトリは、高性能ですから!")
|
log.Info("アトリは、高性能ですから!")
|
||||||
cli.OnDisconnected(func(bot *client.QQClient, e *client.ClientDisconnectedEvent) {
|
cli.OnDisconnected(func(bot *client.QQClient, e *client.ClientDisconnectedEvent) {
|
||||||
|
if conf.Reconnect {
|
||||||
|
log.Warnf("Bot已离线,将在 %v 秒后尝试重连.", conf.ReconnectDelay)
|
||||||
|
time.Sleep(time.Second * time.Duration(conf.ReconnectDelay))
|
||||||
|
rsp, err := cli.Login()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("重连失败: %v", err)
|
||||||
|
}
|
||||||
|
if !rsp.Success {
|
||||||
|
switch rsp.Error {
|
||||||
|
case client.NeedCaptcha:
|
||||||
|
log.Fatalf("重连失败: 需要验证码. (验证码处理正在开发中)")
|
||||||
|
case client.UnsafeDeviceError:
|
||||||
|
log.Fatalf("重连失败: 设备锁")
|
||||||
|
default:
|
||||||
|
log.Fatalf("重连失败: %v", rsp.ErrorMessage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
b.Release()
|
b.Release()
|
||||||
log.Fatalf("Bot已断线:", e.Message)
|
log.Fatalf("Bot已离线:%v", e.Message)
|
||||||
})
|
})
|
||||||
c := make(chan os.Signal, 1)
|
c := make(chan os.Signal, 1)
|
||||||
signal.Notify(c, os.Interrupt, os.Kill)
|
signal.Notify(c, os.Interrupt, os.Kill)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user