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.Start() return c } func stopCron(c *cron.Cron) { c.Stop() return } func cronSendWarReport() { muxClients.RLock() for _, c := range clients { if c.Active { p := JobPayloadFwdMsg{ ChatID64: cfg.Bot.Reportchat, } b, _ := json.Marshal(&p) err := createJobCallback(objSubTypeJobFwdMsg, c.TGUserID64, objSubTypeMessageReportAck, b, 1*time.Minute) logOnError(err, "cronSendWarReport : createJobCallback") clientSendCWMsgDelay(c.TGUserID64, `/report`, 0) } } muxClients.RUnlock() return } func cronSetDef() { muxClients.RLock() for _, c := range clients { if c.Active { p := JobPayloadSetDef{} b, _ := json.Marshal(&p) err := createJobCallback(objSubTypeJobSetDef, c.TGUserID64, objSubTypeMessageMeAck, b, 1*time.Minute) logOnError(err, "cronSetDef : createJobCallback") clientSendCWMsgDelay(c.TGUserID64, `🏅Me`, 0) } } muxClients.RUnlock() return }