This repository has been archived on 2022-10-02. You can view files and clone it, but cannot push or open issues or pull requests.
dcbot-old/cron/cron.go

41 lines
1015 B
Go
Raw Normal View History

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-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"
"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 {
ServerRepo server.Repository
ObservationRepo observation.Repository
Discord *discord.Session
2020-06-26 18:30:25 +00:00
GroupRepo group.Repository
API *sdk.SDK
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-05-30 10:43:11 +00:00
}
c.AddFunc("@every 1m", h.checkLastEnnoblements)
c.AddFunc("@every 30m", h.checkBotMembershipOnServers)
2020-06-24 14:50:29 +00:00
c.AddFunc("@every 2h", h.deleteClosedTribalWarsServers)
go func() {
h.checkBotMembershipOnServers()
h.deleteClosedTribalWarsServers()
}()
2020-05-30 10:43:11 +00:00
}