3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-07-06 10:37:19 +00:00
zeppelin/backend/src/utils/DecayingCounter.ts

24 lines
459 B
TypeScript

/**
* This is not related to Zeppelin's counters feature
*/
export class DecayingCounter {
protected value = 0;
protected decayInterval: number;
constructor(decayInterval: number) {
this.decayInterval = decayInterval;
setInterval(() => {
this.value = Math.max(0, this.value - 1);
}, decayInterval);
}
add(count = 1): number {
this.value += count;
return this.value;
}
get(): number {
return this.value;
}
}