diff --git a/README.md b/README.md index 4c49270..264738f 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ `go get` ```shell -go get github.com/eatMoreApple/openwechat +go get github.com/eatmoreapple/openwechat ``` @@ -36,7 +36,7 @@ package main import ( "fmt" - "github.com/eatMoreApple/openwechat" + "github.com/eatmoreapple/openwechat" ) func main() { @@ -95,7 +95,7 @@ func main() { ### 项目主页 -[https://github.com/eatMoreApple/openwechat](https://github.com/eatMoreApple/openwechat) +[https://github.com/eatmoreapple/openwechat](https://github.com/eatmoreapple/openwechat) diff --git a/bot.go b/bot.go index 0ca0255..ec3f0c2 100644 --- a/bot.go +++ b/bot.go @@ -74,10 +74,8 @@ func (b *Bot) HotLogin(storage HotReloadStorage, retry ...bool) error { // 如果webInit出错,则说明可能身份信息已经失效 // 如果retry为True的话,则进行正常登陆 if err = b.webInit(); err != nil { - if len(retry) > 0 { - if retry[0] { - return b.Login() - } + if len(retry) > 0 && retry[0] { + return b.Login() } } return err @@ -176,7 +174,7 @@ func (b *Bot) handleLogin(data []byte) error { // 如果是热登陆,则将当前的重要信息写入hotReloadStorage if b.isHot { - if err := b.DumpHotReloadStorage(); err != nil { + if err = b.DumpHotReloadStorage(); err != nil { return err } } @@ -207,7 +205,7 @@ func (b *Bot) webInit() error { if b.GetMessageErrorHandler == nil { b.GetMessageErrorHandler = b.stopAsyncCALL } - if err := b.asyncCall(); err != nil { + if err = b.asyncCall(); err != nil { b.GetMessageErrorHandler(err) } }() @@ -308,6 +306,21 @@ func (b *Bot) DumpHotReloadStorage() error { return b.hotReloadStorage.Dump(item) } +// OnLogin is a setter for LoginCallBack +func (b *Bot) OnLogin(f func(body []byte)) { + b.LoginCallBack = f +} + +// OnScanned is a setter for ScanCallBack +func (b *Bot) OnScanned(f func(body []byte)) { + b.ScanCallBack = f +} + +// OnLogout is a setter for LogoutCallBack +func (b *Bot) OnLogout(f func(bot *Bot)) { + b.LogoutCallBack = f +} + // Bot的构造方法,需要自己传入Caller func NewBot(caller *Caller) *Bot { ctx, cancel := context.WithCancel(context.Background()) diff --git a/go.mod b/go.mod index 1b56828..6031327 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/eatMoreApple/openwechat +module github.com/eatmoreapple/openwechat go 1.15