diff --git a/cron.go b/cron.go new file mode 100644 index 0000000..a633506 --- /dev/null +++ b/cron.go @@ -0,0 +1,29 @@ +package main + +import ( + "github.com/robfig/cron/v3" + //"gopkg.in/robfig/cron.v3" +) + +func startCron() *Cron { + c := cron.New(cron.WithLocation(time.UTC)) + c.AddFunc("@every 1m", cronSendReport) + c.Start() + return +} + +func stopCron(c *Cron) { + c.Stop() + return +} + +func cronSendReport() { + muxClients.RLock() + for id, c := range clients { + if c.Active { + clientSendCWMsg(c.TGUserID64, `/report`) + } + } + muxClients.RUnlock() + return +} diff --git a/main.go b/main.go index e7cfac2..5878fbe 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "sync" "time" + "github.com/robfig/cron/v3" "gopkg.in/gcfg.v1" _ "github.com/go-sql-driver/mysql" @@ -50,6 +51,8 @@ var ( db *sql.DB b *tb.Bot + c *cron.Cron + cfg Config RndSrc *rand.Rand @@ -154,6 +157,8 @@ func main() { } b.Send(&u, "Bot restarted") + c = startCron() + MQCWMsgQueue = make(chan ChatWarsMessage, MQCWMsgQueueSize) SQLMsgIdentifyQueue = make(chan int64, SQLMsgIdentifyQueueSize) TGCmdQueue = make(chan TGCommand, TGCmdQueueSize)