diff --git a/main.go b/main.go index ea5efae..ba2159f 100644 --- a/main.go +++ b/main.go @@ -47,9 +47,10 @@ func init() { func main() { var ( - crontab = cron.New() - discord *discordgo.Session - err error + crontab = cron.New() + discord *discordgo.Session + err error + activeModules []module ) if config, err = newConfigFromFile(cfg.Config); err != nil { @@ -63,7 +64,6 @@ func main() { discord.Identify.Intents = discordgo.IntentsAll - var enabledModules int for i, mc := range config.ModuleConfigs { logger := log.WithFields(log.Fields{ "idx": i, @@ -78,11 +78,12 @@ func main() { logger.WithError(err).Fatal("Unable to initialize module") } - enabledModules++ + activeModules = append(activeModules, mod) + logger.Debug("Enabled module") } - if enabledModules == 0 { + if len(activeModules) == 0 { log.Warn("No modules were enabled, quitting now") return } @@ -98,6 +99,13 @@ func main() { defer crontab.Stop() log.Debug("Crontab started") + // Execute Setup methods now after we're connected + for i, mod := range activeModules { + if err = mod.Setup(); err != nil { + log.WithError(err).WithField("idx", i).Fatal("Unable to run setup for module") + } + } + // Run HTTP server var h http.Handler = http.DefaultServeMux h = httpHelpers.GzipHandler(h) diff --git a/mod_clearChannel.go b/mod_clearChannel.go index 69f97c8..e738034 100644 --- a/mod_clearChannel.go +++ b/mod_clearChannel.go @@ -49,6 +49,8 @@ func (m *modClearChannel) Initialize(crontab *cron.Cron, discord *discordgo.Sess return nil } +func (m modClearChannel) Setup() error { return nil } + func (m modClearChannel) cronClearChannel() { var ( after = "0" diff --git a/mod_livePosting.go b/mod_livePosting.go index 2749e64..5b941e3 100644 --- a/mod_livePosting.go +++ b/mod_livePosting.go @@ -66,6 +66,8 @@ func (m *modLivePosting) Initialize(crontab *cron.Cron, discord *discordgo.Sessi return nil } +func (m modLivePosting) Setup() error { return nil } + func (m modLivePosting) cronFetchChannelStatus() { // @attr poll_usernames optional []string "[]" Check these usernames for active streams when executing the `cron` (at most 100 users can be checked) usernames, err := m.attrs.StringSlice("poll_usernames") diff --git a/mod_liveRole.go b/mod_liveRole.go index 2ed714c..a044bdf 100644 --- a/mod_liveRole.go +++ b/mod_liveRole.go @@ -43,6 +43,8 @@ func (m *modLiveRole) Initialize(crontab *cron.Cron, discord *discordgo.Session, return nil } +func (m modLiveRole) Setup() error { return nil } + func (m modLiveRole) addLiveStreamerRole(guildID, userID string, presentRoles []string) error { // @attr role_streamers_live required string "" Role ID to assign to live streamers roleID := m.attrs.MustString("role_streamers_live", nil) diff --git a/mod_presence.go b/mod_presence.go index 38aa7a5..2e88233 100644 --- a/mod_presence.go +++ b/mod_presence.go @@ -51,6 +51,8 @@ func (m *modPresence) Initialize(crontab *cron.Cron, discord *discordgo.Session, return nil } +func (m modPresence) Setup() error { return nil } + func (m modPresence) cronUpdatePresence() { var nextStream *time.Time diff --git a/mod_streamSchedule.go b/mod_streamSchedule.go index d349f66..579b34b 100644 --- a/mod_streamSchedule.go +++ b/mod_streamSchedule.go @@ -58,6 +58,8 @@ func (m *modStreamSchedule) Initialize(crontab *cron.Cron, discord *discordgo.Se return nil } +func (m modStreamSchedule) Setup() error { return nil } + func (m modStreamSchedule) cronUpdateSchedule() { twitch := newTwitchAdapter( // @attr twitch_client_id required string "" Twitch client ID the token was issued for diff --git a/modules.go b/modules.go index 846277b..7182160 100644 --- a/modules.go +++ b/modules.go @@ -16,6 +16,7 @@ var ( type ( module interface { Initialize(crontab *cron.Cron, discord *discordgo.Session, attrs moduleAttributeStore) error + Setup() error } moduleInitFn func() module diff --git a/wiki/Home.md b/wiki/Home.md index 1fda109..b5ad300 100644 --- a/wiki/Home.md +++ b/wiki/Home.md @@ -105,6 +105,13 @@ Updates the presence status of the bot to display the next stream | `cron` | | string | `* * * * *` | When to execute the module | | `schedule_past_time` | | duration | `15m` | How long in the past should the schedule contain an entry | +## Type: `reactionrole` + +Creates a post with pre-set reactions and assigns roles on reaction + +| Attribute | Req. | Type | Default Value | Description | +| --------- | :--: | ---- | ------------- | ----------- | + ## Type: `schedule` Posts stream schedule derived from Twitch schedule as embed in Discord channel