92 lines
1.9 KiB
Go
92 lines
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/eatmoreapple/openwechat"
|
|
"go-bot/bot/controller"
|
|
"go-bot/bot/database"
|
|
"strings"
|
|
)
|
|
|
|
func main() {
|
|
|
|
// 创建bot 对象
|
|
bot := openwechat.DefaultBot(openwechat.Desktop)
|
|
// 创建热存储容器对象
|
|
reloadStorage := openwechat.NewJsonFileHotReloadStorage("storage.json")
|
|
//bot.HotLogin(reloadStorage)
|
|
// 执行热登录
|
|
err := bot.HotLogin(reloadStorage, true)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
|
|
// 注册登陆二维码回调
|
|
bot.UUIDCallback = openwechat.PrintlnQrcodeUrl
|
|
|
|
// 获取登陆的用户
|
|
self, err := bot.GetCurrentUser()
|
|
if err != nil {
|
|
fmt.Println(self, err)
|
|
return
|
|
}
|
|
|
|
// 获取所有的好友
|
|
//friends, err := self.Friends()
|
|
//fmt.Println(friends, err)
|
|
|
|
// 获取所有的群组
|
|
groups, err := self.Groups()
|
|
fmt.Println(groups, err)
|
|
|
|
//链接数据库
|
|
database.Database()
|
|
|
|
// 注册消息处理函数
|
|
bot.MessageHandler = func(msg *openwechat.Message) {
|
|
|
|
if msg.IsText() {
|
|
split := strings.Split(msg.Content, " ")
|
|
fmt.Printf("command: %s \n", split)
|
|
|
|
if split[0] == "英语" {
|
|
controller.SingleChoice(msg)
|
|
}
|
|
|
|
if split[0] == "打卡开启" {
|
|
controller.SignInBegin(msg, self)
|
|
}
|
|
if split[0] == "打卡关闭" {
|
|
controller.SignInEnd(msg, self, "叫啥好呢")
|
|
}
|
|
if split[0] == "今日打卡" {
|
|
controller.SignIn(msg, self)
|
|
}
|
|
|
|
if split[0] == "天气" {
|
|
controller.GetWeather(msg, self)
|
|
}
|
|
|
|
if split[0] == "school" && split[1] == "start" {
|
|
controller.SchoolSignInBegin(msg, self)
|
|
}
|
|
if split[0] == "school" && split[1] == "end" {
|
|
controller.SignInEnd(msg, self, "四大天王")
|
|
}
|
|
|
|
if split[0] == "我的信息" {
|
|
controller.GetUsers(msg, self)
|
|
}
|
|
|
|
if split[0] == "all start" {
|
|
controller.SignInBegin(msg, self)
|
|
controller.SchoolSignInBegin(msg, self)
|
|
}
|
|
}
|
|
}
|
|
|
|
// 阻塞主goroutine, 直到发生异常或者用户主动退出
|
|
bot.Block()
|
|
}
|