2020-05-30 10:43:11 +00:00
|
|
|
package cron
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
2020-06-02 07:00:40 +00:00
|
|
|
|
2020-06-05 12:36:29 +00:00
|
|
|
"github.com/tribalwarshelp/golang-sdk/sdk"
|
2020-08-08 12:02:32 +00:00
|
|
|
"github.com/tribalwarshelp/shared/mode"
|
2020-06-05 12:36:29 +00:00
|
|
|
|
2020-06-02 07:00:40 +00:00
|
|
|
"github.com/tribalwarshelp/dcbot/discord"
|
2020-06-26 18:30:25 +00:00
|
|
|
"github.com/tribalwarshelp/dcbot/group"
|
2020-06-18 12:51:31 +00:00
|
|
|
"github.com/tribalwarshelp/dcbot/observation"
|
2020-06-02 07:00:40 +00:00
|
|
|
"github.com/tribalwarshelp/dcbot/server"
|
2020-05-30 10:43:11 +00:00
|
|
|
|
|
|
|
"github.com/robfig/cron/v3"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2020-06-18 12:51:31 +00:00
|
|
|
ServerRepo server.Repository
|
|
|
|
ObservationRepo observation.Repository
|
|
|
|
Discord *discord.Session
|
2020-06-26 18:30:25 +00:00
|
|
|
GroupRepo group.Repository
|
2020-06-18 12:51:31 +00:00
|
|
|
API *sdk.SDK
|
2020-07-15 10:03:43 +00:00
|
|
|
Status string
|
2020-05-30 10:43:11 +00:00
|
|
|
}
|
|
|
|
|
2020-06-06 12:59:11 +00:00
|
|
|
func Attach(c *cron.Cron, cfg Config) {
|
2020-05-30 10:43:11 +00:00
|
|
|
h := &handler{
|
2020-06-24 14:50:29 +00:00
|
|
|
lastEnnoblementAt: make(map[string]time.Time),
|
|
|
|
serverRepo: cfg.ServerRepo,
|
|
|
|
observationRepo: cfg.ObservationRepo,
|
2020-06-26 18:30:25 +00:00
|
|
|
groupRepo: cfg.GroupRepo,
|
2020-06-24 14:50:29 +00:00
|
|
|
discord: cfg.Discord,
|
|
|
|
api: cfg.API,
|
2020-07-15 10:03:43 +00:00
|
|
|
status: cfg.Status,
|
2020-05-30 10:43:11 +00:00
|
|
|
}
|
2020-07-19 14:21:32 +00:00
|
|
|
c.AddFunc("@every 1m", h.checkEnnoblements)
|
|
|
|
c.AddFunc("@every 30m", h.checkBotServers)
|
2020-06-27 16:48:33 +00:00
|
|
|
c.AddFunc("@every 2h10m", h.deleteClosedTribalWarsServers)
|
2020-10-17 10:43:27 +00:00
|
|
|
c.AddFunc("@every 2h", h.updateBotStatus)
|
2020-06-24 14:50:29 +00:00
|
|
|
go func() {
|
2020-07-19 14:21:32 +00:00
|
|
|
h.checkBotServers()
|
2020-06-24 14:50:29 +00:00
|
|
|
h.deleteClosedTribalWarsServers()
|
2020-07-15 10:03:43 +00:00
|
|
|
h.updateBotStatus()
|
2020-08-08 12:02:32 +00:00
|
|
|
if mode.Get() == mode.DevelopmentMode {
|
|
|
|
h.checkEnnoblements()
|
|
|
|
}
|
2020-06-24 14:50:29 +00:00
|
|
|
}()
|
2020-05-30 10:43:11 +00:00
|
|
|
}
|