|
@@ -49,6 +49,7 @@ USE_LOLS_API = os.getenv("USE_LOLS_API", "yes") == "yes"
|
|
|
bot = TelegramClient("captcha_bot", API_ID, API_HASH).start(bot_token=BOT_TOKEN)
|
|
|
pending = {peer_id: {} for peer_id in ALLOWED_GROUPS}
|
|
|
whitelist = {}
|
|
|
+blacklist = {}
|
|
|
|
|
|
|
|
|
async def lols_check(user_id):
|
|
@@ -92,6 +93,8 @@ class PendingUser:
|
|
|
async def start(self, event):
|
|
|
if USE_LOLS_API:
|
|
|
if not await lols_check(self.user_id):
|
|
|
+ blacklist[self.user_id] = time.time()
|
|
|
+
|
|
|
await self.kick(forever=True)
|
|
|
|
|
|
return
|
|
@@ -229,6 +232,11 @@ async def handler(event):
|
|
|
peer_id=event.chat_id, user_id=event.user_id
|
|
|
)
|
|
|
|
|
|
+ if event.user_id in blacklist:
|
|
|
+ await pending[peer_id][event.user_id].kick()
|
|
|
+
|
|
|
+ return
|
|
|
+
|
|
|
await pending[peer_id][event.user_id].start(event)
|
|
|
|
|
|
|
|
@@ -251,6 +259,8 @@ async def handler(event):
|
|
|
pass
|
|
|
|
|
|
if time.time() - pending_user.join_ts <= 1.0:
|
|
|
+ blacklist[event.sender.id] = time.time()
|
|
|
+
|
|
|
pending_user.ban_flag = True
|
|
|
|
|
|
if pending_user.message_id is None:
|
|
@@ -284,11 +294,23 @@ async def cleanup_whitelist():
|
|
|
if time.time() - ts >= 30 * 60:
|
|
|
del whitelist[user_id]
|
|
|
|
|
|
+ await asyncio.sleep(60 * 60)
|
|
|
+
|
|
|
+
|
|
|
+async def cleanup_blacklist():
|
|
|
+ while True:
|
|
|
+ for user_id in dict(blacklist):
|
|
|
+ ts = blacklist[user_id]
|
|
|
+
|
|
|
+ if time.time() - ts >= 604800:
|
|
|
+ del blacklist[user_id]
|
|
|
+
|
|
|
await asyncio.sleep(60)
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
bot.loop.create_task(check_pending())
|
|
|
bot.loop.create_task(cleanup_whitelist())
|
|
|
+ bot.loop.create_task(cleanup_blacklist())
|
|
|
bot.start()
|
|
|
bot.run_until_disconnected()
|