Skip to content

Commit

Permalink
添加在非热登录模式下主动导出热登录数据接口
Browse files Browse the repository at this point in the history
  • Loading branch information
eatmoreapple committed Dec 9, 2022
1 parent c223141 commit 8ba4460
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
"io"
"log"
"net/url"
"os/exec"
Expand Down Expand Up @@ -352,6 +353,12 @@ func (b *Bot) DumpHotReloadStorage() error {
if b.hotReloadStorage == nil {
return errors.New("HotReloadStorage can not be nil")
}
return b.DumpTo(b.hotReloadStorage)
}

// DumpTo 将热登录需要的数据写入到指定的 io.Writer 中
// 注: 写之前最好先清空之前的数据
func (b *Bot) DumpTo(writer io.Writer) error {
cookies := b.Caller.Client.GetCookieMap()
item := HotReloadStorageItem{
BaseRequest: b.Storage.Request,
Expand All @@ -360,8 +367,7 @@ func (b *Bot) DumpHotReloadStorage() error {
WechatDomain: b.Caller.Client.Domain,
UUID: b.uuid,
}

return json.NewEncoder(b.hotReloadStorage).Encode(item)
return json.NewEncoder(writer).Encode(item)
}

// OnLogin is a setter for LoginCallBack
Expand Down

0 comments on commit 8ba4460

Please sign in to comment.