twitch-bot/configRemoteUpdate.go
Knut Ahlers 61cc2d64b3
[core] Add rule-subscription feature
- Add remote url to rules
- Add cron to update remote URLs hourly
- Add frontend display for shared rules
- Add frontend feature to subscribe rules

Signed-off-by: Knut Ahlers <knut@ahlers.me>
2022-10-07 19:23:51 +02:00

48 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")
}
}