设置默认5分钟同步一次热存储数据 (#192)
This commit is contained in:
parent
fb20b70ebf
commit
71fe8b87ec
5
bot.go
5
bot.go
@ -79,6 +79,9 @@ func (b *Bot) Login() error {
|
|||||||
// HotLogin 热登录,可实现在单位时间内免重复扫码登录
|
// HotLogin 热登录,可实现在单位时间内免重复扫码登录
|
||||||
func (b *Bot) HotLogin(storage HotReloadStorage, opts ...HotLoginOptionFunc) error {
|
func (b *Bot) HotLogin(storage HotReloadStorage, opts ...HotLoginOptionFunc) error {
|
||||||
hotLogin := &HotLogin{storage: storage}
|
hotLogin := &HotLogin{storage: storage}
|
||||||
|
// 进行相关设置。
|
||||||
|
// 如果相对默认的行为进行修改,在opts里面进行追加即可。
|
||||||
|
opts = append(defaultHotLoginOpts[:], opts...)
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
opt(&hotLogin.opt)
|
opt(&hotLogin.opt)
|
||||||
}
|
}
|
||||||
@ -331,7 +334,7 @@ func NewBot(c context.Context) *Bot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DefaultBot 默认的Bot的构造方法,
|
// DefaultBot 默认的Bot的构造方法,
|
||||||
// mode不传入默认为 openwechat.Desktop,详情见mode
|
// mode不传入默认为 openwechat.Normal,详情见mode
|
||||||
//
|
//
|
||||||
// bot := openwechat.DefaultBot(openwechat.Desktop)
|
// bot := openwechat.DefaultBot(openwechat.Desktop)
|
||||||
func DefaultBot(opts ...BotOptionFunc) *Bot {
|
func DefaultBot(opts ...BotOptionFunc) *Bot {
|
||||||
|
@ -4,6 +4,10 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
defaultHotStorageSyncDuration = time.Minute * 5
|
||||||
|
)
|
||||||
|
|
||||||
// BotLogin 定义了一个Login的接口
|
// BotLogin 定义了一个Login的接口
|
||||||
type BotLogin interface {
|
type BotLogin interface {
|
||||||
Login(bot *Bot) error
|
Login(bot *Bot) error
|
||||||
@ -52,6 +56,10 @@ func HotLoginWithSyncReloadData(duration time.Duration) HotLoginOptionFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var defaultHotLoginOpts = [...]HotLoginOptionFunc{
|
||||||
|
HotLoginWithSyncReloadData(defaultHotStorageSyncDuration),
|
||||||
|
}
|
||||||
|
|
||||||
// HotLogin 热登录模式
|
// HotLogin 热登录模式
|
||||||
type HotLogin struct {
|
type HotLogin struct {
|
||||||
storage HotReloadStorage
|
storage HotReloadStorage
|
||||||
@ -138,6 +146,7 @@ func PushLoginWithSyncReloadData(duration time.Duration) PushLoginOptionFunc {
|
|||||||
var defaultPushLoginOpts = [...]PushLoginOptionFunc{
|
var defaultPushLoginOpts = [...]PushLoginOptionFunc{
|
||||||
PushLoginWithoutUUIDCallback(true),
|
PushLoginWithoutUUIDCallback(true),
|
||||||
PushLoginWithoutScanCallback(true),
|
PushLoginWithoutScanCallback(true),
|
||||||
|
PushLoginWithSyncReloadData(defaultHotStorageSyncDuration),
|
||||||
}
|
}
|
||||||
|
|
||||||
// PushLogin 免扫码登录模式
|
// PushLogin 免扫码登录模式
|
||||||
|
Loading…
x
Reference in New Issue
Block a user