-
@@ -274,6 +366,7 @@ export default function TwitchBotTimersPage(
setTimerFilter(ev.target.value)}
@@ -297,22 +390,26 @@ export default function TwitchBotTimersPage(
modifyTimer(showModifyTimer, newName, cmdData)
}
initialName={showModifyTimer}
- initialData={showModifyTimer ? timers[showModifyTimer] : null}
+ initialData={
+ showModifyTimer ? timerConfig.timers[showModifyTimer] : null
+ }
onClose={() => setShowModifyTimer(null)}
/>
) : null}
- {Object.keys(timers ?? {})
- ?.filter((cmd) => cmd.toLowerCase().includes(timerFilterLC))
- .map((timer) => (
- deleteTimer(timer)}
- onEdit={() => setShowModifyTimer(timer)}
- onToggleState={() => toggleTimer(timer)}
- />
- ))}
+ {timersActive
+ ? Object.keys(timerConfig?.timers ?? {})
+ ?.filter((cmd) => cmd.toLowerCase().includes(timerFilterLC))
+ .map((timer) => (
+ deleteTimer(timer)}
+ onEdit={() => setShowModifyTimer(timer)}
+ onToggleState={() => toggleTimer(timer)}
+ />
+ ))
+ : null}
>
);
diff --git a/modules/twitch/modules.go b/modules/twitch/modules.go
index b963ec9..3b5bc48 100644
--- a/modules/twitch/modules.go
+++ b/modules/twitch/modules.go
@@ -20,6 +20,7 @@ func (b *Bot) LoadModules() error {
}
}
if cfg.EnableTimers {
+ b.logger.Debug("starting timer module")
b.Timers = SetupTimers(b)
}
return nil
diff --git a/modules/twitch/modules.timer.go b/modules/twitch/modules.timer.go
index 879726f..c7d3bfc 100644
--- a/modules/twitch/modules.timer.go
+++ b/modules/twitch/modules.timer.go
@@ -37,18 +37,22 @@ type BotTimerModule struct {
func SetupTimers(bot *Bot) *BotTimerModule {
mod := &BotTimerModule{
- bot: bot,
- startTime: time.Now().Round(time.Minute),
+ bot: bot,
+ startTime: time.Now().Round(time.Minute),
+ lastTrigger: make(map[string]time.Time),
}
// Load config from database
err := bot.api.db.GetJSON(BotTimersKey, &mod.Config)
if err != nil {
+ bot.logger.WithError(err).Debug("config load error")
mod.Config = BotTimersConfig{
Timers: make(map[string]BotTimer),
}
}
+ bot.logger.WithField("timers", len(mod.Config.Timers)).Debug("loaded timers")
+
// Start goroutine for clearing message counters and running timers
go mod.runTimers()
@@ -89,11 +93,12 @@ func (m *BotTimerModule) runTimers() {
// Check if enough time has passed
lastTriggeredTime, ok := m.lastTrigger[name]
if !ok {
- continue
+ // If it's the first time we're checking it, start the cooldown
+ lastTriggeredTime = time.Now()
}
minDelay := timer.MinimumDelay
- if minDelay < 5 {
- minDelay = 5
+ if minDelay < 60 {
+ minDelay = 60
}
if now.Sub(lastTriggeredTime) < time.Duration(minDelay)*time.Second {
continue