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