From 71fe8b87ec712aedf9ce46ca25e6b9bf523c1660 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E5=90=83=E7=82=B9=E8=8B=B9=E6=9E=9C?= <73388495+eatmoreapple@users.noreply.github.com> Date: Tue, 10 Jan 2023 19:28:14 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E9=BB=98=E8=AE=A45=E5=88=86?= =?UTF-8?q?=E9=92=9F=E5=90=8C=E6=AD=A5=E4=B8=80=E6=AC=A1=E7=83=AD=E5=AD=98?= =?UTF-8?q?=E5=82=A8=E6=95=B0=E6=8D=AE=20(#192)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.go | 5 ++++- bot_login.go | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/bot.go b/bot.go index 0940540..ad6d3cd 100644 --- a/bot.go +++ b/bot.go @@ -79,6 +79,9 @@ func (b *Bot) Login() error { // HotLogin 热登录,可实现在单位时间内免重复扫码登录 func (b *Bot) HotLogin(storage HotReloadStorage, opts ...HotLoginOptionFunc) error { hotLogin := &HotLogin{storage: storage} + // 进行相关设置。 + // 如果相对默认的行为进行修改,在opts里面进行追加即可。 + opts = append(defaultHotLoginOpts[:], opts...) for _, opt := range opts { opt(&hotLogin.opt) } @@ -331,7 +334,7 @@ func NewBot(c context.Context) *Bot { } // DefaultBot 默认的Bot的构造方法, -// mode不传入默认为 openwechat.Desktop,详情见mode +// mode不传入默认为 openwechat.Normal,详情见mode // // bot := openwechat.DefaultBot(openwechat.Desktop) func DefaultBot(opts ...BotOptionFunc) *Bot { diff --git a/bot_login.go b/bot_login.go index a691e3e..32a9431 100644 --- a/bot_login.go +++ b/bot_login.go @@ -4,6 +4,10 @@ import ( "time" ) +const ( + defaultHotStorageSyncDuration = time.Minute * 5 +) + // BotLogin 定义了一个Login的接口 type BotLogin interface { Login(bot *Bot) error @@ -52,6 +56,10 @@ func HotLoginWithSyncReloadData(duration time.Duration) HotLoginOptionFunc { } } +var defaultHotLoginOpts = [...]HotLoginOptionFunc{ + HotLoginWithSyncReloadData(defaultHotStorageSyncDuration), +} + // HotLogin 热登录模式 type HotLogin struct { storage HotReloadStorage @@ -138,6 +146,7 @@ func PushLoginWithSyncReloadData(duration time.Duration) PushLoginOptionFunc { var defaultPushLoginOpts = [...]PushLoginOptionFunc{ PushLoginWithoutUUIDCallback(true), PushLoginWithoutScanCallback(true), + PushLoginWithSyncReloadData(defaultHotStorageSyncDuration), } // PushLogin 免扫码登录模式