From 80efb966db66d0c8c51986292698758475e8c1e2 Mon Sep 17 00:00:00 2001 From: eatmoreapple Date: Mon, 14 Nov 2022 10:55:57 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E5=87=BA=20isHot=20=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/bot.go b/bot.go index b4ff2e4..6d9f2ec 100644 --- a/bot.go +++ b/bot.go @@ -19,7 +19,6 @@ type Bot struct { SyncCheckCallback func(resp SyncCheckResponse) // 心跳回调 MessageHandler MessageHandler // 获取消息成功的handle MessageErrorHandler func(err error) bool // 获取消息发生错误的handle, 返回true则尝试继续监听 - isHot bool // 是否为热登录模式 once sync.Once err error context context.Context @@ -27,7 +26,7 @@ type Bot struct { Caller *Caller self *Self Storage *Storage - HotReloadStorage HotReloadStorage + hotReloadStorage HotReloadStorage uuid string deviceId string // 设备Id } @@ -74,8 +73,7 @@ func (b *Bot) GetCurrentUser() (*Self, error) { // err := bot.HotLogin(Storage, true) // fmt.Println(err) func (b *Bot) HotLogin(storage HotReloadStorage, retry ...bool) error { - b.isHot = true - b.HotReloadStorage = storage + b.hotReloadStorage = storage var err error @@ -200,7 +198,7 @@ func (b *Bot) HandleLogin(data []byte) error { b.Storage.Request = request // 如果是热登陆,则将当前的重要信息写入hotReloadStorage - if b.isHot { + if b.hotReloadStorage != nil { if err = b.DumpHotReloadStorage(); err != nil { return err } @@ -349,7 +347,7 @@ func (b *Bot) MessageOnError(h func(err error) bool) { // DumpHotReloadStorage 写入HotReloadStorage func (b *Bot) DumpHotReloadStorage() error { - if b.HotReloadStorage == nil { + if b.hotReloadStorage == nil { return errors.New("HotReloadStorage can not be nil") } cookies := b.Caller.Client.GetCookieMap() @@ -361,7 +359,7 @@ func (b *Bot) DumpHotReloadStorage() error { UUID: b.uuid, } - return json.NewEncoder(b.HotReloadStorage).Encode(item) + return json.NewEncoder(b.hotReloadStorage).Encode(item) } // OnLogin is a setter for LoginCallBack @@ -452,7 +450,7 @@ func open(url string) error { // IsHot returns true if is hot login otherwise false func (b *Bot) IsHot() bool { - return b.isHot + return b.hotReloadStorage != nil } // UUID returns current uuid of bot