mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-12-20 20:01:17 +00:00
49 lines
929 B
Go
49 lines
929 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"math/rand"
|
||
|
|
||
|
log "github.com/sirupsen/logrus"
|
||
|
)
|
||
|
|
||
|
func updateConfigCron() string {
|
||
|
minute := rand.Intn(60) //nolint:gomnd,gosec // Only used to distribute load
|
||
|
return fmt.Sprintf("%d * * * *", minute)
|
||
|
}
|
||
|
|
||
|
func updateConfigFromRemote() {
|
||
|
err := patchConfig(
|
||
|
cfg.Config,
|
||
|
"Remote Update", "twitch-bot@luzifer.io",
|
||
|
"update rules from subscription URLs",
|
||
|
func(cfg *configFile) error {
|
||
|
var hasUpdate bool
|
||
|
|
||
|
for _, r := range cfg.Rules {
|
||
|
logger := log.WithField("rule", r.MatcherID())
|
||
|
|
||
|
rhu, err := r.UpdateFromSubscription()
|
||
|
if err != nil {
|
||
|
logger.WithError(err).Error("updating rule")
|
||
|
continue
|
||
|
}
|
||
|
|
||
|
if rhu {
|
||
|
hasUpdate = true
|
||
|
logger.Info("updated rule from remote URL")
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
if !hasUpdate {
|
||
|
return errSaveNotRequired
|
||
|
}
|
||
|
return nil
|
||
|
},
|
||
|
)
|
||
|
if err != nil {
|
||
|
log.WithError(err).Error("updating config rules from subscriptions")
|
||
|
}
|
||
|
}
|