Procházet zdrojové kódy

/lock url (#88)

* /lock url

* a

Co-authored-by: Akshay Rajput <thehamkercat@gmail.com>
iamajneya před 5 roky
rodič
revize
c862c7c86e
1 změnil soubory, kde provedl 31 přidání a 4 odebrání
  1. 31 4
      wbb/modules/locks.py

+ 31 - 4
wbb/modules/locks.py

@@ -25,10 +25,12 @@ from pyrogram import filters
 from pyrogram.errors.exceptions.bad_request_400 import ChatNotModified
 from pyrogram.types import ChatPermissions
 
-from wbb import app
+from wbb import SUDOERS, app
 from wbb.core.decorators.errors import capture_err
+from wbb.utils.functions import get_urls_from_text
 from wbb.core.decorators.permissions import adminsOnly
-from wbb.modules.admin import current_chat_permissions
+from wbb.modules.admin import current_chat_permissions, list_admins
+
 
 __MODULE__ = "Locks"
 __HELP__ = """
@@ -37,7 +39,7 @@ Commands: /lock | /unlock | /locks [No Parameters Required]
 Parameters:
     messages | stickers | gifs | media | games | polls
 
-    inline  | link_previews | group_info | user_add | pin
+    inline  | url | group_info | user_add | pin
 
 You can only pass the "all" parameter with /lock, not with /unlock
 
@@ -48,6 +50,9 @@ Example:
 incorrect_parameters = (
     "Incorrect Parameters, Check Locks Section In Help."
 )
+# Using disable_preview as a switch for url checker
+# That way we won't need an additional db to check 
+# If url lock is enabled/disabled for a chat
 data = {
     "messages": "can_send_messages",
     "stickers": "can_send_stickers",
@@ -55,7 +60,7 @@ data = {
     "media": "can_send_media_messages",
     "games": "can_send_games",
     "inline": "can_use_inline_bots",
-    "link_previews": "can_add_web_page_previews",
+    "url": "can_add_web_page_previews",
     "polls": "can_send_polls",
     "group_info": "can_change_info",
     "useradd": "can_invite_users",
@@ -118,3 +123,25 @@ async def locktypes(_, message):
     for i in permissions:
         perms += f"__**{i}**__\n"
     await message.reply_text(perms)
+    
+
+@app.on_message(filters.text & ~filters.private)
+async def url_detector(_, message):
+    user = message.from_user
+    chat_id = message.chat.id
+    text = message.text.lower().strip()
+    if not text: return
+    if not user: return
+    if user.id in SUDOERS: return
+    if user.id in await list_admins(chat_id): return
+    check = get_urls_from_text(text)
+    if check:
+        permissions = await current_chat_permissions(chat_id)
+        if 'can_add_web_page_previews' not in permissions:
+            try:
+                await message.delete()
+            except Exception:
+                await message.reply_text(
+                         "This message contains a URL, "
+                         + "but i don't have enough permissions to delete it"
+                )