twitch-bot/configRemoteUpdate.go
Knut Ahlers c63793be2d
Lint: Update linter config
and fix some newly appearing linter errors

Signed-off-by: Knut Ahlers <knut@ahlers.me>
2024-06-09 13:01:32 +02:00

51 lines
1.0 KiB
Go

package main
import (
"context"
"fmt"
"math/rand"
log "github.com/sirupsen/logrus"
)
func updateConfigCron() string {
minute := rand.Intn(60) //nolint:mnd,gosec // Only used to distribute load
return fmt.Sprintf("0 %d * * * *", minute)
}
func updateConfigFromRemote() {
log.Debug("starting remote rule update")
err := patchConfig(
cfg.Config,
"Remote Update", "twitch-bot@luzifer.io",
"update rules from subscription URLs",
func(cfg *configFile) error {
var updates int
for _, r := range cfg.Rules {
logger := log.WithField("rule", r.MatcherID())
rhu, err := r.UpdateFromSubscription(context.Background())
if err != nil {
logger.WithError(err).Error("updating rule")
continue
}
if rhu {
updates++
logger.Info("updated rule from remote URL")
}
}
log.WithField("updates", updates).Debug("remote rule update finished")
if updates == 0 {
return errSaveNotRequired
}
return nil
},
)
if err != nil {
log.WithError(err).Error("updating config rules from subscriptions")
}
}