File tree Expand file tree Collapse file tree 2 files changed +21
-23
lines changed Expand file tree Collapse file tree 2 files changed +21
-23
lines changed Original file line number Diff line number Diff line change @@ -336,28 +336,6 @@ func (b *Bot) Context() context.Context {
336
336
return b .context
337
337
}
338
338
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
-
361
339
// NewBot Bot的构造方法
362
340
// 接收外部的 context.Context,用于控制Bot的存活
363
341
func NewBot (c context.Context ) * Bot {
Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ package openwechat
2
2
3
3
import (
4
4
"context"
5
+ "encoding/json"
6
+ "errors"
5
7
)
6
8
7
9
// LoginCode 定义登录状态码
@@ -186,8 +188,26 @@ func (s *ScanLogin) checkLogin(bot *Bot, uuid string) error {
186
188
}
187
189
188
190
func botReload (bot * Bot , storage HotReloadStorage ) error {
191
+ if storage == nil {
192
+ return errors .New ("storage is nil" )
193
+ }
189
194
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
191
211
}
192
212
193
213
// HotLogin 热登录模式
You can’t perform that action at this time.
0 commit comments