Skip to content

Commit 0b3fa5f

Browse files
committed
feat: remove hot reload from bot
1 parent f3ce16b commit 0b3fa5f

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

bot.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -336,28 +336,6 @@ func (b *Bot) Context() context.Context {
336336
return b.context
337337
}
338338

339-
func (b *Bot) reload() error {
340-
if b.hotReloadStorage == nil {
341-
return errors.New("hotReloadStorage is nil")
342-
}
343-
var item HotReloadStorageItem
344-
if err := b.Serializer.Decode(b.hotReloadStorage, &item); err != nil {
345-
return err
346-
}
347-
b.Caller.Client.SetCookieJar(item.Jar)
348-
b.Storage.LoginInfo = item.LoginInfo
349-
b.Storage.Request = item.BaseRequest
350-
b.Caller.Client.Domain = item.WechatDomain
351-
b.uuid = item.UUID
352-
if item.SyncKey != nil {
353-
if b.Storage.Response == nil {
354-
b.Storage.Response = &WebInitResponse{}
355-
}
356-
b.Storage.Response.SyncKey = item.SyncKey
357-
}
358-
return nil
359-
}
360-
361339
// NewBot Bot的构造方法
362340
// 接收外部的 context.Context,用于控制Bot的存活
363341
func NewBot(c context.Context) *Bot {

bot_login.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package openwechat
22

33
import (
44
"context"
5+
"encoding/json"
6+
"errors"
57
)
68

79
// LoginCode 定义登录状态码
@@ -186,8 +188,26 @@ func (s *ScanLogin) checkLogin(bot *Bot, uuid string) error {
186188
}
187189

188190
func botReload(bot *Bot, storage HotReloadStorage) error {
191+
if storage == nil {
192+
return errors.New("storage is nil")
193+
}
189194
bot.hotReloadStorage = storage
190-
return bot.reload()
195+
var item HotReloadStorageItem
196+
if err := json.NewDecoder(storage).Decode(&item); err != nil {
197+
return err
198+
}
199+
bot.Caller.Client.SetCookieJar(item.Jar)
200+
bot.Storage.LoginInfo = item.LoginInfo
201+
bot.Storage.Request = item.BaseRequest
202+
bot.Caller.Client.Domain = item.WechatDomain
203+
bot.uuid = item.UUID
204+
if item.SyncKey != nil {
205+
if bot.Storage.Response == nil {
206+
bot.Storage.Response = &WebInitResponse{}
207+
}
208+
bot.Storage.Response.SyncKey = item.SyncKey
209+
}
210+
return nil
191211
}
192212

193213
// HotLogin 热登录模式

0 commit comments

Comments
 (0)