mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-09 08:40:01 +00:00
[core] Fix: Don't initialize twitch client before start checks
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
293a7d9e30
commit
afe2963d33
1 changed files with 23 additions and 22 deletions
45
main.go
45
main.go
|
@ -146,28 +146,6 @@ func main() {
|
||||||
log.WithError(err).Fatal("applying timer migration")
|
log.WithError(err).Fatal("applying timer migration")
|
||||||
}
|
}
|
||||||
|
|
||||||
if twitchClient, err = accessService.GetBotTwitchClient(access.ClientConfig{
|
|
||||||
TwitchClient: cfg.TwitchClient,
|
|
||||||
TwitchClientSecret: cfg.TwitchClientSecret,
|
|
||||||
TokenUpdateHook: func() {
|
|
||||||
// make frontend reload its state as of token change
|
|
||||||
frontendNotifyHooks.Ping(frontendNotifyTypeReload)
|
|
||||||
},
|
|
||||||
}); err != nil {
|
|
||||||
if !errors.Is(err, access.ErrChannelNotAuthorized) {
|
|
||||||
log.WithError(err).Fatal("initializing Twitch client")
|
|
||||||
}
|
|
||||||
twitchClient = twitch.New(cfg.TwitchClient, cfg.TwitchClientSecret, "", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
twitchWatch := newTwitchWatcher()
|
|
||||||
// Query may run that often as the twitchClient has an internal
|
|
||||||
// cache but shouldn't run more often as EventSub subscriptions
|
|
||||||
// are retried on error each time
|
|
||||||
if _, err = cronService.AddFunc("@every 30s", twitchWatch.Check); err != nil {
|
|
||||||
log.WithError(err).Fatal("registering twitchWatch cron")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allow config to subscribe to external rules
|
// Allow config to subscribe to external rules
|
||||||
updCron := updateConfigCron()
|
updCron := updateConfigCron()
|
||||||
if _, err = cronService.AddFunc(updCron, updateConfigFromRemote); err != nil {
|
if _, err = cronService.AddFunc(updCron, updateConfigFromRemote); err != nil {
|
||||||
|
@ -251,6 +229,29 @@ func main() {
|
||||||
log.WithError(err).Fatal("Missing required parameters")
|
log.WithError(err).Fatal("Missing required parameters")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if twitchClient, err = accessService.GetBotTwitchClient(access.ClientConfig{
|
||||||
|
TwitchClient: cfg.TwitchClient,
|
||||||
|
TwitchClientSecret: cfg.TwitchClientSecret,
|
||||||
|
TokenUpdateHook: func() {
|
||||||
|
// make frontend reload its state as of token change
|
||||||
|
frontendNotifyHooks.Ping(frontendNotifyTypeReload)
|
||||||
|
},
|
||||||
|
}); err != nil {
|
||||||
|
if !errors.Is(err, access.ErrChannelNotAuthorized) {
|
||||||
|
log.WithError(err).Fatal("initializing Twitch client")
|
||||||
|
}
|
||||||
|
twitchClient = twitch.New(cfg.TwitchClient, cfg.TwitchClientSecret, "", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
twitchWatch := newTwitchWatcher()
|
||||||
|
|
||||||
|
// Query may run that often as the twitchClient has an internal
|
||||||
|
// cache but shouldn't run more often as EventSub subscriptions
|
||||||
|
// are retried on error each time
|
||||||
|
if _, err = cronService.AddFunc("@every 30s", twitchWatch.Check); err != nil {
|
||||||
|
log.WithError(err).Fatal("registering twitchWatch cron")
|
||||||
|
}
|
||||||
|
|
||||||
fsEvents := make(chan configChangeEvent, 1)
|
fsEvents := make(chan configChangeEvent, 1)
|
||||||
go watchConfigChanges(cfg.Config, fsEvents)
|
go watchConfigChanges(cfg.Config, fsEvents)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue