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"
|
|
|
|
"github.com/tribalwarshelp/dcbot/server"
|
|
|
|
"github.com/tribalwarshelp/dcbot/tribe"
|
2020-05-30 10:43:11 +00:00
|
|
|
|
|
|
|
"github.com/robfig/cron/v3"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
ServerRepo server.Repository
|
|
|
|
TribeRepo tribe.Repository
|
|
|
|
Discord *discord.Session
|
2020-06-05 12:36:29 +00:00
|
|
|
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-12 16:28:07 +00:00
|
|
|
lastEnnobledAt: make(map[string]time.Time),
|
|
|
|
serverRepo: cfg.ServerRepo,
|
|
|
|
tribeRepo: cfg.TribeRepo,
|
|
|
|
discord: cfg.Discord,
|
|
|
|
api: cfg.API,
|
2020-05-30 10:43:11 +00:00
|
|
|
}
|
2020-06-07 15:49:33 +00:00
|
|
|
c.AddFunc("@every 1m", h.checkLastEnnoblements)
|
2020-05-30 10:43:11 +00:00
|
|
|
}
|