mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-09-07 20:39:07 +00:00
and fix some newly appearing linter errors Signed-off-by: Knut Ahlers <knut@ahlers.me>
51 lines
1.0 KiB
Go
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")
|
|
}
|
|
}
|