学校打卡任务 微信提醒 小功能。
This commit is contained in:
@@ -44,7 +44,7 @@ func SignInBegin(msg *openwechat.Message, self *openwechat.Self) {
|
|||||||
// 启动定时器
|
// 启动定时器
|
||||||
crontab.Start()
|
crontab.Start()
|
||||||
|
|
||||||
self.SendTextToGroup(name, "打卡程序启动成功!")
|
self.SendTextToGroup(name, "sign start is success!")
|
||||||
// 定时任务是另起协程执行的,这里使用 select 简答阻塞.实际开发中需要
|
// 定时任务是另起协程执行的,这里使用 select 简答阻塞.实际开发中需要
|
||||||
// 根据实际情况进行控制
|
// 根据实际情况进行控制
|
||||||
//阻塞主线程停止
|
//阻塞主线程停止
|
||||||
@@ -53,14 +53,54 @@ func SignInBegin(msg *openwechat.Message, self *openwechat.Self) {
|
|||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
func SignInEnd(msg *openwechat.Message, self *openwechat.Self) {
|
func SchoolSignInBegin(msg *openwechat.Message, self *openwechat.Self) {
|
||||||
|
groups, err := self.Groups()
|
||||||
|
name := groups.GetByNickName("四大天王")
|
||||||
|
fmt.Printf(name.NickName, err)
|
||||||
|
|
||||||
|
//定义定时器调用的任务函数
|
||||||
|
task := func() {
|
||||||
|
self.SendTextToGroup(name, "智慧东方打卡!")
|
||||||
|
}
|
||||||
|
|
||||||
|
//定义定时器调用的任务函数
|
||||||
|
task1 := func() {
|
||||||
|
self.SendTextToGroup(name, "还不打? 是想对狒狒呲牙麻?")
|
||||||
|
}
|
||||||
|
|
||||||
|
//定义定时器调用的任务函数
|
||||||
|
task2 := func() {
|
||||||
|
self.SendTextToGroup(name, "拍照打卡!")
|
||||||
|
}
|
||||||
|
|
||||||
|
//定时任务
|
||||||
|
spec := "0 0 9 * * ?" //cron表达式,每天9点
|
||||||
|
spec1 := "0 10 9 * * ?" //cron表达式,每天9点
|
||||||
|
spec2 := "0 11 22 * * ?" //cron表达式,每天9点
|
||||||
|
// 添加定时任务,
|
||||||
|
crontab.AddFunc(spec, task)
|
||||||
|
crontab.AddFunc(spec1, task1)
|
||||||
|
crontab.AddFunc(spec2, task2)
|
||||||
|
// 启动定时器
|
||||||
|
crontab.Start()
|
||||||
|
|
||||||
|
self.SendTextToGroup(name, "sign start is success!")
|
||||||
|
// 定时任务是另起协程执行的,这里使用 select 简答阻塞.实际开发中需要
|
||||||
|
// 根据实际情况进行控制
|
||||||
|
//阻塞主线程停止
|
||||||
|
//select {
|
||||||
|
//查询语句,保持程序运行,在这里等同于for{}
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
func SignInEnd(msg *openwechat.Message, self *openwechat.Self, string2 string) {
|
||||||
|
|
||||||
groups, err := self.Groups()
|
groups, err := self.Groups()
|
||||||
name := groups.GetByNickName("叫啥好呢")
|
name := groups.GetByNickName(string2)
|
||||||
fmt.Printf(name.NickName, err)
|
fmt.Printf(name.NickName, err)
|
||||||
crontab.Stop()
|
crontab.Stop()
|
||||||
// 发送到微信
|
// 发送到微信
|
||||||
self.SendTextToGroup(name, "打卡程序结束运行成功!")
|
self.SendTextToGroup(name, "sign end is success!")
|
||||||
}
|
}
|
||||||
|
|
||||||
func SignIn(msg *openwechat.Message, self *openwechat.Self) {
|
func SignIn(msg *openwechat.Message, self *openwechat.Self) {
|
||||||
|
|||||||
9
main.go
9
main.go
@@ -58,12 +58,19 @@ func main() {
|
|||||||
controller.SignInBegin(msg, self)
|
controller.SignInBegin(msg, self)
|
||||||
}
|
}
|
||||||
if split[0] == "打卡关闭" {
|
if split[0] == "打卡关闭" {
|
||||||
controller.SignInEnd(msg, self)
|
controller.SignInEnd(msg, self, "叫啥好呢")
|
||||||
}
|
}
|
||||||
if split[0] == "今日打卡" {
|
if split[0] == "今日打卡" {
|
||||||
controller.SignIn(msg, self)
|
controller.SignIn(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] == "我的信息" {
|
if split[0] == "我的信息" {
|
||||||
controller.GetUsers(msg, self)
|
controller.GetUsers(msg, self)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user