.BANCHO. .FIX. Fix reset spam rate
This commit is contained in:
parent
6cde5b2e68
commit
f0f90b0c53
|
@ -238,14 +238,9 @@ class token:
|
|||
|
||||
increaseSpamRate -- pass True if the user has sent a new message. Optional. Default: True
|
||||
"""
|
||||
# Increase the spam rate if needed
|
||||
if increaseSpamRate == True:
|
||||
# Reset spam rate every 10 seconds
|
||||
if int(time.time())-self.lastMessagetime >= 10:
|
||||
self.spamRate = 0
|
||||
else:
|
||||
self.spamRate += 1
|
||||
# Update last message time
|
||||
self.lastMessagetime = time.time()
|
||||
self.spamRate += 1
|
||||
|
||||
# Silence the user if needed
|
||||
if self.spamRate > 10:
|
||||
|
|
|
@ -3,8 +3,6 @@ import time
|
|||
import threading
|
||||
from events import logoutEvent
|
||||
from helpers import logHelper as log
|
||||
from constants import serverPackets
|
||||
from helpers import userHelper
|
||||
|
||||
class tokenList:
|
||||
"""
|
||||
|
@ -13,7 +11,11 @@ class tokenList:
|
|||
tokens -- dictionary. key: token string, value: token object
|
||||
"""
|
||||
|
||||
tokens = {}
|
||||
def __init__(self):
|
||||
"""
|
||||
Initialize a tokens list
|
||||
"""
|
||||
self.tokens = {}
|
||||
|
||||
def addToken(self, __userID):
|
||||
"""
|
||||
|
@ -166,3 +168,17 @@ class tokenList:
|
|||
|
||||
# Schedule a new check (endless loop)
|
||||
threading.Timer(__checkTime, self.usersTimeoutCheckLoop, [__timeoutTime, __checkTime]).start()
|
||||
|
||||
def spamProtectionResetLoop(self):
|
||||
"""
|
||||
Reset spam rate every 10 seconds.
|
||||
CALL THIS FUNCTION ONLY ONCE!
|
||||
"""
|
||||
log.debug("Resetting spam protection...")
|
||||
|
||||
# Reset spamRate for every token
|
||||
for _, value in self.tokens.items():
|
||||
value.spamRate = 0
|
||||
|
||||
# Schedule a new check (endless loop)
|
||||
threading.Timer(10, self.spamProtectionResetLoop).start()
|
||||
|
|
5
pep.py
5
pep.py
|
@ -113,6 +113,11 @@ if __name__ == "__main__":
|
|||
glob.tokens.usersTimeoutCheckLoop()
|
||||
consoleHelper.printDone()
|
||||
|
||||
# Initialize spam protection reset loop
|
||||
consoleHelper.printNoNl("> Initializing spam protection reset loop... ")
|
||||
glob.tokens.spamProtectionResetLoop()
|
||||
consoleHelper.printDone()
|
||||
|
||||
# Localize warning
|
||||
glob.localize = generalFunctions.stringToBool(glob.conf.config["server"]["localize"])
|
||||
if glob.localize == False:
|
||||
|
|
Loading…
Reference in New Issue
Block a user