mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2024-11-05 07:20:13 +01:00
Improve banned forgiveness logic
This commit is contained in:
parent
cda2d3ed96
commit
3a7527c418
15
app/flood.py
15
app/flood.py
@ -7,10 +7,19 @@ active = False
|
||||
threshold = -1
|
||||
|
||||
|
||||
def clear_banned():
|
||||
def forgive_banned():
|
||||
global banned
|
||||
banned = {}
|
||||
|
||||
clear_list = []
|
||||
|
||||
for ip in banned:
|
||||
if banned[ip] <= 0:
|
||||
clear_list.append(ip)
|
||||
else:
|
||||
banned[ip] -= 1
|
||||
|
||||
for ip in clear_list:
|
||||
del banned[ip]
|
||||
|
||||
def setup(violations_threshold=100):
|
||||
global active
|
||||
@ -20,7 +29,7 @@ def setup(violations_threshold=100):
|
||||
threshold = violations_threshold
|
||||
|
||||
scheduler = BackgroundScheduler()
|
||||
scheduler.add_job(func=clear_banned, trigger="interval", weeks=4)
|
||||
scheduler.add_job(func=forgive_banned, trigger="interval", minutes=5)
|
||||
scheduler.start()
|
||||
|
||||
# Shut down the scheduler when exiting the app
|
||||
|
Loading…
Reference in New Issue
Block a user