mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-09 16:50:01 +00:00
Provide central cron service to plugins
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
984223e6ac
commit
47f314af4e
3 changed files with 14 additions and 2 deletions
|
@ -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,
|
||||
}
|
||||
|
|
10
main.go
10
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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue