Quellcode durchsuchen

Fixed /purge and added admin checking module

thehamkercat vor 5 Jahren
Ursprung
Commit
8f9ace1c57
3 geänderte Dateien mit 49 neuen und 7 gelöschten Zeilen
  1. 1 2
      wbb/__main__.py
  2. 16 5
      wbb/modules/admin.py
  3. 32 0
      wbb/utils/is_admin.py

+ 1 - 2
wbb/__main__.py

@@ -8,7 +8,6 @@ import importlib
 from wbb.modules import ALL_MODULES
 import uvloop
 
-
 loop = asyncio.get_event_loop()
 
 
@@ -43,7 +42,7 @@ async def start_bot():
     print("+===============+===============+===============+===============+")
     print(bot_modules)
     print("+===============+===============+===============+===============+")
-    print("Bot run successfully as {}!".format(botinfo.BOT_NAME))
+    print("Bot Started Successfully as {}!".format(botinfo.BOT_NAME))
     await idle()
 
 

+ 16 - 5
wbb/modules/admin.py

@@ -2,15 +2,20 @@ import asyncio
 from pyrogram import Client, filters
 from wbb.utils import cust_filter
 from wbb import app, Command
+from wbb.utils.is_admin import is_admin
 
 @app.on_message(cust_filter.command(commands=(["purge"])))
 async def purge(client, message):
     app.set_parse_mode("markdown")
     if message.chat.type not in (("supergroup", "channel")):
         return
+    
+    admin = await is_admin(message)
+
+    if not admin:
+        return
 
     message_ids = []
-    count_del_etion_s = 0
 
     if message.reply_to_message:
         for a_s_message_id in range(
@@ -18,16 +23,22 @@ async def purge(client, message):
             message.message_id
         ):
             message_ids.append(a_s_message_id)
+            if len(message_ids) == 100:
+                await client.delete_messages(
+                    chat_id=message.chat.id,
+                    message_ids=message_ids,
+                    revoke=True
+                )
+                message_ids = []
         if len(message_ids) > 0:
             await client.delete_messages(
                 chat_id=message.chat.id,
                 message_ids=message_ids,
                 revoke=True
             )
-            count_del_etion_s += len(message_ids)
 
-    status_message = await message.reply_text(
+    m = await message.reply_text(
         f"```Purged!```"
     )
-    await asyncio.sleep(5)
-    await status_message.delete()
+    await asyncio.sleep(2)
+    await m.delete()

+ 32 - 0
wbb/utils/is_admin.py

@@ -0,0 +1,32 @@
+from pyrogram.types import Message
+
+
+async def is_admin(message: Message) -> bool:
+    if not message.from_user:
+        return False
+
+    if message.chat.type not in ["supergroup", "channel"]:
+        return False
+
+    if message.from_user.id in [
+        777000,  # Telegram Service Notifications
+        1087968824  # GroupAnonymousBot
+    ]:
+        return True
+
+    client = message._client
+    chat_id = message.chat.id
+    user_id = message.from_user.id
+
+    check_status = await client.get_chat_member(
+        chat_id=chat_id,
+        user_id=user_id
+    )
+    admin_strings = [
+        "creator",
+        "administrator"
+    ]
+    if check_status.status not in admin_strings:
+        return False
+    else:
+        return True