Skip to content

Commit 6cd4fcc

Browse files
author
eatmoreapple
committed
设置bot的默认行为
1 parent e7f21d7 commit 6cd4fcc

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

bot.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ import (
1010
)
1111

1212
type Bot struct {
13-
ScanCallBack func(body []byte) // 扫码回调,可获取扫码用户的头像
14-
LoginCallBack func(body []byte) // 登陆回调
15-
LogoutCallBack func(bot *Bot) // 退出回调
16-
UUIDCallback func(uuid string) // 获取UUID的回调函数
17-
MessageHandler MessageHandler // 获取消息成功的handle
18-
GetMessageErrorHandler func(err error) // 获取消息发生错误的handle
19-
IsHot bool // 是否为热登录模式
13+
ScanCallBack func(body []byte) // 扫码回调,可获取扫码用户的头像
14+
LoginCallBack func(body []byte) // 登陆回调
15+
LogoutCallBack func(bot *Bot) // 退出回调
16+
UUIDCallback func(uuid string) // 获取UUID的回调函数
17+
SyncCheckCallback func(resp SyncCheckResponse) // 心跳回调
18+
MessageHandler MessageHandler // 获取消息成功的handle
19+
GetMessageErrorHandler func(err error) // 获取消息发生错误的handle
20+
IsHot bool // 是否为热登录模式
2021
once sync.Once
2122
err error
2223
context context.Context
@@ -234,6 +235,10 @@ func (b *Bot) asyncCall() error {
234235
if err != nil {
235236
return err
236237
}
238+
// 执行心跳回调
239+
if b.SyncCheckCallback != nil {
240+
b.SyncCheckCallback(*resp)
241+
}
237242
// 如果不是正常的状态码返回,发生了错误,直接退出
238243
if !resp.Success() {
239244
return resp
@@ -357,6 +362,15 @@ func DefaultBot(modes ...mode) *Bot {
357362
caller.Client.mode = m
358363
bot := NewBot(caller)
359364
bot.UUIDCallback = PrintlnQrcodeUrl
365+
bot.ScanCallBack = func(body []byte) {
366+
log.Println("扫码成功,请在手机上确认登录")
367+
}
368+
bot.LoginCallBack = func(body []byte) {
369+
log.Println("登录成功")
370+
}
371+
bot.SyncCheckCallback = func(resp SyncCheckResponse) {
372+
log.Printf("RetCode:%s Selector:%s", resp.RetCode, resp.Selector)
373+
}
360374
return bot
361375
}
362376

0 commit comments

Comments
 (0)