From 801cd2630b5d75dd3c2d132d13a87cd05da0931a Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Thu, 15 Dec 2022 00:38:24 +0200 Subject: [PATCH] fix: fix crash when decay period is 0 --- backend/src/data/GuildCounters.ts | 2 +- backend/src/plugins/Counters/CountersPlugin.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/src/data/GuildCounters.ts b/backend/src/data/GuildCounters.ts index 52f20293..a87861b1 100644 --- a/backend/src/data/GuildCounters.ts +++ b/backend/src/data/GuildCounters.ts @@ -161,7 +161,7 @@ export class GuildCounters extends BaseGuildRepository { } const decayAmountToApply = Math.round((diffFromLastDecayMs / decayPeriodMs) * decayAmount); - if (decayAmountToApply === 0) { + if (decayAmountToApply === 0 || Number.isNaN(decayAmountToApply)) { return; } diff --git a/backend/src/plugins/Counters/CountersPlugin.ts b/backend/src/plugins/Counters/CountersPlugin.ts index 6d4bf708..adec8b84 100644 --- a/backend/src/plugins/Counters/CountersPlugin.ts +++ b/backend/src/plugins/Counters/CountersPlugin.ts @@ -203,6 +203,10 @@ export const CountersPlugin = zeppelinGuildPlugin()({ const decay = counter.decay; const decayPeriodMs = convertDelayStringToMS(decay.every)!; + if (decayPeriodMs === 0) { + continue; + } + pluginData.state.decayTimers.push( setInterval(() => { decayCounter(pluginData, counterName, decayPeriodMs, decay.amount);