forked from Aveygo/LXMBridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcooldown.py
More file actions
34 lines (25 loc) · 847 Bytes
/
cooldown.py
File metadata and controls
34 lines (25 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import time
class AntiSpam:
def __init__(self):
self.in_cooldown = False
self.history = []
self.min_cooldown = 10
self.cooldown = self.min_cooldown
def is_allowed(self):
return len([i for i in self.history if i > time.time() - self.cooldown]) < 3
def try_perform_action(self):
if not self.is_allowed():
return False
self.cooldown = max(self.cooldown * 0.7, self.min_cooldown)
self.history.append(time.time())
self.history = self.history[-10:]
if not self.is_allowed():
self.in_cooldown = True
self.cooldown = (self.cooldown + 1) ** 2
return False
return True
if __name__ == "__main__":
a = AntiSpam()
while True:
input()
print(a.try_perform_action())