txlyre 2 ay önce
ebeveyn
işleme
d8b37b6adb
1 değiştirilmiş dosya ile 23 ekleme ve 7 silme
  1. 23 7
      main.py

+ 23 - 7
main.py

@@ -50,10 +50,13 @@ bot = TelegramClient("captcha_bot", API_ID, API_HASH).start(bot_token=BOT_TOKEN)
 pending = {peer_id: {} for peer_id in ALLOWED_GROUPS}
 whitelist = {}
 
+
 async def lols_check(user_id):
     try:
         async with aiohttp.ClientSession() as session:
-            async with session.get(f"https://api.lols.bot/account?id={user_id}") as response:
+            async with session.get(
+                f"https://api.lols.bot/account?id={user_id}"
+            ) as response:
                 data = await response.json()
 
                 banned = data.get("banned", False)
@@ -65,11 +68,14 @@ async def lols_check(user_id):
 
     return True
 
+
 class PendingUser:
     def __init__(self, peer_id, user_id):
         self.peer_id = peer_id
         self.user_id = user_id
 
+        self.ban_flag = False
+
         self.text = None
         self.message_id = None
 
@@ -129,6 +135,11 @@ class PendingUser:
                 pass
 
     async def check_captcha(self, captcha):
+        if self.ban_flag:
+            await self.kick()
+
+            return False
+
         captcha = captcha.replace(" ", "").strip().upper()
 
         if captcha == self.captcha:
@@ -176,7 +187,9 @@ class PendingUser:
                     self.peer_id,
                     self.user_id,
                     ChatBannedRights(
-                        until_date=None if forever else datetime.now() + timedelta(minutes=5),
+                        until_date=None
+                        if forever
+                        else datetime.now() + timedelta(minutes=5),
                         view_messages=True,
                     ),
                 )
@@ -184,6 +197,7 @@ class PendingUser:
         except Exception:
             pass
 
+
 @bot.on(events.ChatAction)
 async def handler(event):
     if event.chat_id not in ALLOWED_GROUPS:
@@ -202,7 +216,9 @@ async def handler(event):
     if event.user_id in whitelist:
         return
 
-    pending[peer_id][event.user_id] = PendingUser(peer_id=event.chat_id, user_id=event.user_id)
+    pending[peer_id][event.user_id] = PendingUser(
+        peer_id=event.chat_id, user_id=event.user_id
+    )
 
     await pending[peer_id][event.user_id].start(event)
 
@@ -226,9 +242,7 @@ async def handler(event):
         pass
 
     if time.time() - pending_user.join_ts <= 1.0:
-        await pending_user.kick()
-
-        return
+        pending_user.ban_flag = True
 
     if pending_user.message_id is None:
         return
@@ -254,16 +268,18 @@ async def check_pending():
 
         await asyncio.sleep(1)
 
+
 async def cleanup_whitelist():
     while True:
         for user_id in dict(whitelist):
             ts = whitelist[user_id]
 
-            if time.time() - ts >= 30*60:
+            if time.time() - ts >= 30 * 60:
                 del whitelist[user_id]
 
         await asyncio.sleep(60)
 
+
 if __name__ == "__main__":
     bot.loop.create_task(check_pending())
     bot.loop.create_task(cleanup_whitelist())