Answer the question
In order to leave comments, you need to log in
How to make flood protection in tg bot?
If a person will spam, for example, 5+ messages per second came from him, then the bot should write so that he does not flood, how can this be done?
Should he build a timer into the database? Or is there a better method?
Answer the question
In order to leave comments, you need to log in
DB is not for that. Do it right in the app. create a list. Insert the user's id into the list each time you request it. Reset this list every second. And with each request, check how many id of this user are in this list using count.
This is the easiest way.
can be counted.
In a sheet with 1 million elements, the time is 15 ms.
Its own implementation of 0.5 ms works, that is, 30 times faster. But everything depends on the case. It doesn't matter in your situation. It is unlikely that there will be 1 million requests per second
count = listix.count(555)
listix = []
counter = 0
for i in listix:
if i == 555:
counter += 1
if counter >= 5:
print('DDOS')
break
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question