71 lines
1.3 KiB
Go
71 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/eatmoreapple/openwechat"
|
|
"go-bot/bot/controller"
|
|
"go-bot/bot/tool"
|
|
)
|
|
|
|
func main() {
|
|
|
|
// 创建bot 对象
|
|
bot := openwechat.DefaultBot(openwechat.Desktop)
|
|
// 创建热存储容器对象
|
|
reloadStorage := openwechat.NewJsonFileHotReloadStorage("storage.json")
|
|
|
|
// 注册消息处理函数
|
|
bot.MessageHandler = func(msg *openwechat.Message) {
|
|
|
|
if msg.IsText() && msg.Content == "英语" {
|
|
controller.SingleChoice(msg)
|
|
}
|
|
|
|
if msg.IsText() && msg.Content == "打卡开启" {
|
|
controller.SignInBegin(msg)
|
|
}
|
|
|
|
if msg.IsText() && msg.Content == "打卡关闭" {
|
|
controller.SignInEnd(msg)
|
|
}
|
|
|
|
}
|
|
|
|
// 注册登陆二维码回调
|
|
bot.UUIDCallback = openwechat.PrintlnQrcodeUrl
|
|
|
|
// 登陆
|
|
//if err := bot.Login(); err != nil {
|
|
// fmt.Println(err)
|
|
// return
|
|
//}
|
|
|
|
// 执行热登录
|
|
err := bot.HotLogin(reloadStorage)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
// 获取登陆的用户
|
|
self, err := bot.GetCurrentUser()
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
tool.SetCurrentUser(*self)
|
|
return
|
|
}
|
|
|
|
// 获取所有的好友
|
|
friends, err := self.Friends()
|
|
fmt.Println(friends, err)
|
|
|
|
// 获取所有的群组
|
|
groups, err := self.Groups()
|
|
fmt.Println(groups, err)
|
|
|
|
// 阻塞主goroutine, 直到发生异常或者用户主动退出
|
|
err = bot.Block()
|
|
if err != nil {
|
|
return
|
|
}
|
|
}
|