Last active
May 30, 2023 16:33
-
-
Save AmirSbss/7804ba2e6af7ef53d46d6ba421291ef3 to your computer and use it in GitHub Desktop.
Cached anti spam system for telegram bots written in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time as tm | |
spams = {} | |
msgs = 4 # Messages in | |
max = 5 # Seconds | |
ban = 300 # Seconds | |
def is_spam(user_id): | |
try: | |
usr = spams[user_id] | |
usr["messages"] += 1 | |
except: | |
spams[user_id] = {"next_time": int(tm.time()) + max, "messages": 1, "banned": 0} | |
usr = spams[user_id] | |
if usr["banned"] >= int(tm.time()): | |
return True | |
else: | |
if usr["next_time"] >= int(tm.time()): | |
if usr["messages"] >= msgs: | |
spams[user_id]["banned"] = tm.time() + ban | |
# text = """You're banned for {} minutes""".format(ban/60) | |
# bot.send_message(user_id, text) | |
# User is banned! alert him... | |
return True | |
else: | |
spams[user_id]["messages"] = 1 | |
spams[user_id]["next_time"] = int(tm.time()) + max | |
return False |
Man, is an Anti-flood, not an Anti-scam...
it is an anti-"sPam" bot not "scam"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Man, is an Anti-flood, not an Anti-scam...