移出 isHot 属性

This commit is contained in:
eatmoreapple 2022-11-14 10:55:57 +08:00
parent 1649ee68b8
commit 80efb966db

14
bot.go
View File

@ -19,7 +19,6 @@ type Bot struct {
SyncCheckCallback func(resp SyncCheckResponse) // 心跳回调 SyncCheckCallback func(resp SyncCheckResponse) // 心跳回调
MessageHandler MessageHandler // 获取消息成功的handle MessageHandler MessageHandler // 获取消息成功的handle
MessageErrorHandler func(err error) bool // 获取消息发生错误的handle, 返回true则尝试继续监听 MessageErrorHandler func(err error) bool // 获取消息发生错误的handle, 返回true则尝试继续监听
isHot bool // 是否为热登录模式
once sync.Once once sync.Once
err error err error
context context.Context context context.Context
@ -27,7 +26,7 @@ type Bot struct {
Caller *Caller Caller *Caller
self *Self self *Self
Storage *Storage Storage *Storage
HotReloadStorage HotReloadStorage hotReloadStorage HotReloadStorage
uuid string uuid string
deviceId string // 设备Id deviceId string // 设备Id
} }
@ -74,8 +73,7 @@ func (b *Bot) GetCurrentUser() (*Self, error) {
// err := bot.HotLogin(Storage, true) // err := bot.HotLogin(Storage, true)
// fmt.Println(err) // fmt.Println(err)
func (b *Bot) HotLogin(storage HotReloadStorage, retry ...bool) error { func (b *Bot) HotLogin(storage HotReloadStorage, retry ...bool) error {
b.isHot = true b.hotReloadStorage = storage
b.HotReloadStorage = storage
var err error var err error
@ -200,7 +198,7 @@ func (b *Bot) HandleLogin(data []byte) error {
b.Storage.Request = request b.Storage.Request = request
// 如果是热登陆,则将当前的重要信息写入hotReloadStorage // 如果是热登陆,则将当前的重要信息写入hotReloadStorage
if b.isHot { if b.hotReloadStorage != nil {
if err = b.DumpHotReloadStorage(); err != nil { if err = b.DumpHotReloadStorage(); err != nil {
return err return err
} }
@ -349,7 +347,7 @@ func (b *Bot) MessageOnError(h func(err error) bool) {
// DumpHotReloadStorage 写入HotReloadStorage // DumpHotReloadStorage 写入HotReloadStorage
func (b *Bot) DumpHotReloadStorage() error { func (b *Bot) DumpHotReloadStorage() error {
if b.HotReloadStorage == nil { if b.hotReloadStorage == nil {
return errors.New("HotReloadStorage can not be nil") return errors.New("HotReloadStorage can not be nil")
} }
cookies := b.Caller.Client.GetCookieMap() cookies := b.Caller.Client.GetCookieMap()
@ -361,7 +359,7 @@ func (b *Bot) DumpHotReloadStorage() error {
UUID: b.uuid, UUID: b.uuid,
} }
return json.NewEncoder(b.HotReloadStorage).Encode(item) return json.NewEncoder(b.hotReloadStorage).Encode(item)
} }
// OnLogin is a setter for LoginCallBack // OnLogin is a setter for LoginCallBack
@ -452,7 +450,7 @@ func open(url string) error {
// IsHot returns true if is hot login otherwise false // IsHot returns true if is hot login otherwise false
func (b *Bot) IsHot() bool { func (b *Bot) IsHot() bool {
return b.isHot return b.hotReloadStorage != nil
} }
// UUID returns current uuid of bot // UUID returns current uuid of bot