设置默认5分钟同步一次热存储数据 (#192)

This commit is contained in:
多吃点苹果 2023-01-10 19:28:14 +08:00 committed by GitHub
parent fb20b70ebf
commit 71fe8b87ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

5
bot.go
View File

@ -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 {

View File

@ -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 免扫码登录模式