添加Bot行为设置函数
This commit is contained in:
parent
5259114400
commit
5120404ba7
@ -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)
|
||||
|
||||
|
||||
|
||||
|
23
bot.go
23
bot.go
@ -74,12 +74,10 @@ 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] {
|
||||
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())
|
||||
|
Loading…
x
Reference in New Issue
Block a user