diff --git a/action_core.go b/action_core.go index 4852f26..4f11a48 100644 --- a/action_core.go +++ b/action_core.go @@ -36,6 +36,7 @@ func getRegistrationArguments() plugins.RegistrationArguments { FormatMessage: formatMessage, GetLogger: func(moduleName string) *log.Entry { return log.WithField("module", moduleName) }, RegisterActor: registerAction, + RegisterCron: cronService.AddFunc, RegisterTemplateFunction: tplFuncs.Register, SendMessage: sendMessage, } diff --git a/main.go b/main.go index b2f78a9..307601e 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "github.com/go-irc/irc" "github.com/pkg/errors" + "github.com/robfig/cron/v3" log "github.com/sirupsen/logrus" "github.com/Luzifer/go_helpers/v2/str" @@ -35,6 +36,8 @@ var ( config *configFile configLock = new(sync.RWMutex) + cronService *cron.Cron + sendMessage func(m *irc.Message) error store = newStorageFile(false) @@ -73,12 +76,13 @@ func init() { func main() { var err error + cronService = cron.New() + twitchClient = twitch.New(cfg.TwitchClient, cfg.TwitchToken) + if err = loadPlugins(cfg.PluginDir); err != nil { log.WithError(err).Fatal("Unable to load plugins") } - twitchClient = twitch.New(cfg.TwitchClient, cfg.TwitchToken) - if err = loadConfig(cfg.Config); err != nil { log.WithError(err).Fatal("Initial config load failed") } @@ -107,6 +111,8 @@ func main() { autoMessageTicker = time.NewTicker(time.Second) ) + cronService.Start() + ircDisconnected <- struct{}{} for { diff --git a/plugins/interface.go b/plugins/interface.go index dfd5c67..3e48d22 100644 --- a/plugins/interface.go +++ b/plugins/interface.go @@ -2,6 +2,7 @@ package plugins import ( "github.com/go-irc/irc" + "github.com/robfig/cron/v3" log "github.com/sirupsen/logrus" ) @@ -22,6 +23,8 @@ type ( ActorRegistrationFunc func(ActorCreationFunc) + CronRegistrationFunc func(spec string, cmd func()) (cron.EntryID, error) + LoggerCreationFunc func(moduleName string) *log.Entry MsgFormatter func(tplString string, m *irc.Message, r *Rule, fields map[string]interface{}) (string, error) @@ -36,6 +39,8 @@ type ( GetLogger LoggerCreationFunc // RegisterActor is used to register a new IRC rule-actor implementing the Actor interface RegisterActor ActorRegistrationFunc + // RegisterCron is a method to register cron functions in the global cron instance + RegisterCron CronRegistrationFunc // RegisterTemplateFunction can be used to register a new template functions RegisterTemplateFunction TemplateFuncRegister // SendMessage can be used to send a message not triggered by an event