add public method DumpHotReloadStorage

This commit is contained in:
eatMoreApple 2021-05-14 23:33:54 +08:00
parent f1327345ed
commit 6a9d276ea4

24
bot.go
View File

@ -176,14 +176,7 @@ func (b *Bot) handleLogin(data []byte) error {
// 如果是热登陆,则将当前的重要信息写入hotReloadStorage // 如果是热登陆,则将当前的重要信息写入hotReloadStorage
if b.isHot { if b.isHot {
cookies := b.Caller.Client.GetCookieMap() if err := b.DumpHotReloadStorage(); err != nil {
item := HotReloadStorageItem{
BaseRequest: request,
Cookies: cookies,
LoginInfo: info,
WechatDomain: b.Caller.Client.domain,
}
if err := b.hotReloadStorage.Dump(item); err != nil {
return err return err
} }
} }
@ -300,6 +293,21 @@ func (b *Bot) MessageOnError(h func(err error)) {
b.GetMessageErrorHandler = h b.GetMessageErrorHandler = h
} }
// 写入HotReloadStorage
func (b *Bot) DumpHotReloadStorage() error {
if b.hotReloadStorage == nil {
return errors.New("hotReloadStorage can be nil")
}
cookies := b.Caller.Client.GetCookieMap()
item := HotReloadStorageItem{
BaseRequest: b.storage.Request,
Cookies: cookies,
LoginInfo: b.storage.LoginInfo,
WechatDomain: b.Caller.Client.domain,
}
return b.hotReloadStorage.Dump(item)
}
// Bot的构造方法需要自己传入Caller // Bot的构造方法需要自己传入Caller
func NewBot(caller *Caller) *Bot { func NewBot(caller *Caller) *Bot {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())