chirpnest/cron.go

38 lines
728 B
Go
Raw Normal View History

2019-12-12 10:42:05 +01:00
package main
import (
2019-12-12 10:45:27 +01:00
"time"
2019-12-12 10:44:18 +01:00
//"github.com/robfig/cron/v3"
"gopkg.in/robfig/cron.v3"
2019-12-12 10:42:05 +01:00
)
2019-12-12 10:45:27 +01:00
func startCron() *cron.Cron {
2019-12-12 10:42:05 +01:00
c := cron.New(cron.WithLocation(time.UTC))
2019-12-12 11:24:12 +01:00
c.AddFunc("15 0,8,16 * * *", cronSendWarReport)
2019-12-12 10:42:05 +01:00
c.Start()
2019-12-12 10:49:18 +01:00
return c
2019-12-12 10:42:05 +01:00
}
2019-12-12 10:45:27 +01:00
func stopCron(c *cron.Cron) {
2019-12-12 10:42:05 +01:00
c.Stop()
return
}
2019-12-12 11:24:12 +01:00
func cronSendWarReport() {
2019-12-12 10:42:05 +01:00
muxClients.RLock()
2019-12-12 10:51:01 +01:00
for _, c := range clients {
2019-12-12 10:42:05 +01:00
if c.Active {
2019-12-12 11:24:12 +01:00
p := JobPayloadFwdMsg{
ChatID64: cfg.Bot.Reportchat,
}
2019-12-12 11:25:06 +01:00
b, _ := json.Marshal(&p)
2019-12-12 11:24:12 +01:00
err := createJobCallback(objSubTypeJobFwdMsg, c.TGUserID64, objSubTypeMessageReportAck, b, 1*time.Minute)
logOnError(err, "cronSendWarReport : createJobCallback")
2019-12-12 10:42:05 +01:00
clientSendCWMsg(c.TGUserID64, `/report`)
}
}
muxClients.RUnlock()
return
}