83 lines
2.0 KiB
Go
83 lines
2.0 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
|
|
//"github.com/robfig/cron/v3"
|
|
"gopkg.in/robfig/cron.v3"
|
|
)
|
|
|
|
func startCron() *cron.Cron {
|
|
c := cron.New(cron.WithLocation(time.UTC))
|
|
c.AddFunc("15 7,15,23 * * *", cronSendWarReport)
|
|
c.AddFunc("58 6,14,22 * * *", cronSetDef)
|
|
c.AddFunc("02 1,3,5,9,11,13,17,19,21 * * *", cronGetHammerTime)
|
|
c.AddFunc("10 7,15,23 * * *", cronGetHammerTime)
|
|
c.AddFunc("13 3, 7, 11, 15, 19, 23 * * *", cronTribute)
|
|
c.Start()
|
|
return c
|
|
}
|
|
|
|
func stopCron(c *cron.Cron) {
|
|
c.Stop()
|
|
return
|
|
}
|
|
|
|
func cronSendWarReport() {
|
|
muxClients.RLock()
|
|
for _, c := range clients {
|
|
if c.Active {
|
|
p := JobPayloadMsgFwd{
|
|
ChatID64: cfg.Bot.Reportchat,
|
|
}
|
|
b, _ := json.Marshal(&p)
|
|
err := createJobCallback(cacheObjSubType[`job_msg_fwd`], c.TGUserID64, cacheObjSubType[`msg_report_ack`], b, 1*time.Minute)
|
|
logOnError(err, "cronSendWarReport : createJobCallback")
|
|
clientSendCWMsgDelay(c.TGUserID64, `/report`, 0)
|
|
}
|
|
}
|
|
muxClients.RUnlock()
|
|
return
|
|
}
|
|
|
|
func cronTribute() {
|
|
muxClients.RLock()
|
|
for _, c := range clients {
|
|
if c.Active && c.CWClass == `Knight` {
|
|
clientSendCWMsgDelay(c.TGUserID64, `/tributes`, 0)
|
|
}
|
|
}
|
|
muxClients.RUnlock()
|
|
return
|
|
}
|
|
|
|
func cronSetDef() {
|
|
muxClients.RLock()
|
|
for _, c := range clients {
|
|
if c.Active {
|
|
p := JobPayloadSetDef{}
|
|
b, _ := json.Marshal(&p)
|
|
err := createJobCallback(cacheObjSubType[`job_set_def`], c.TGUserID64, cacheObjSubType[`msg_me_ack`], b, 1*time.Minute)
|
|
logOnError(err, "cronSetDef : createJobCallback")
|
|
clientSendCWMsgDelay(c.TGUserID64, `🏅Me`, 0)
|
|
}
|
|
}
|
|
muxClients.RUnlock()
|
|
return
|
|
}
|
|
|
|
func cronGetHammerTime() {
|
|
clt, err := getLockedRandomClient()
|
|
logOnError(err, "cronGetHammerTime : getLockedRandomClient")
|
|
if err != nil {
|
|
return
|
|
}
|
|
clt.Mux.Unlock()
|
|
p := JobPayloadGetHammerTime{}
|
|
b, _ := json.Marshal(&p)
|
|
err = createJobCallback(cacheObjSubType[`job_get_hammer_time`], clt.TGUserID64, cacheObjSubType[`msg_time_ack`], b, 1*time.Minute)
|
|
logOnError(err, "cronGetHammerTime : createJobCallback")
|
|
clientSendCWMsgDelay(clt.TGUserID64, `/time`, 0)
|
|
}
|