feat: remove hot reload from bot (#537)

This commit is contained in:
多吃点苹果
2024-09-30 15:38:53 +08:00
committed by GitHub
parent f3ce16b011
commit 26b8262dad
2 changed files with 21 additions and 23 deletions
-22
View File
@@ -336,28 +336,6 @@ func (b *Bot) Context() context.Context {
return b.context
}
func (b *Bot) reload() error {
if b.hotReloadStorage == nil {
return errors.New("hotReloadStorage is nil")
}
var item HotReloadStorageItem
if err := b.Serializer.Decode(b.hotReloadStorage, &item); err != nil {
return err
}
b.Caller.Client.SetCookieJar(item.Jar)
b.Storage.LoginInfo = item.LoginInfo
b.Storage.Request = item.BaseRequest
b.Caller.Client.Domain = item.WechatDomain
b.uuid = item.UUID
if item.SyncKey != nil {
if b.Storage.Response == nil {
b.Storage.Response = &WebInitResponse{}
}
b.Storage.Response.SyncKey = item.SyncKey
}
return nil
}
// NewBot Bot的构造方法
// 接收外部的 context.Context,用于控制Bot的存活
func NewBot(c context.Context) *Bot {
+21 -1
View File
@@ -2,6 +2,8 @@ package openwechat
import (
"context"
"encoding/json"
"errors"
)
// LoginCode 定义登录状态码
@@ -186,8 +188,26 @@ func (s *ScanLogin) checkLogin(bot *Bot, uuid string) error {
}
func botReload(bot *Bot, storage HotReloadStorage) error {
if storage == nil {
return errors.New("storage is nil")
}
bot.hotReloadStorage = storage
return bot.reload()
var item HotReloadStorageItem
if err := json.NewDecoder(storage).Decode(&item); err != nil {
return err
}
bot.Caller.Client.SetCookieJar(item.Jar)
bot.Storage.LoginInfo = item.LoginInfo
bot.Storage.Request = item.BaseRequest
bot.Caller.Client.Domain = item.WechatDomain
bot.uuid = item.UUID
if item.SyncKey != nil {
if bot.Storage.Response == nil {
bot.Storage.Response = &WebInitResponse{}
}
bot.Storage.Response.SyncKey = item.SyncKey
}
return nil
}
// HotLogin 热登录模式