TheHamkerCat 5 سال پیش
والد
کامیت
2b15eda19f
7فایلهای تغییر یافته به همراه120 افزوده شده و 10 حذف شده
  1. 1 5
      wbb/core/types/InlineQueryResult.py
  2. 2 0
      wbb/core/types/__init__.py
  3. 31 2
      wbb/modules/admin.py
  4. 1 1
      wbb/modules/chatbot.py
  5. 81 0
      wbb/modules/locks.py
  6. 3 1
      wbb/modules/stickers.py
  7. 1 1
      wbb/utils/inlinefuncs.py

+ 1 - 5
wbb/core/types/InlineQueryResult.py

@@ -28,9 +28,6 @@ class InlineQueryResultAudio(InlineQueryResult):
             Unique identifier for this result, 1-64 bytes.
             Defaults to a randomly generated UUID4.
 
-        voice (``bool``, *optional*):
-            True if the audio is a voice note, defaults to False.
-
         description (``str``, *optional*):
             Short description of the result.
 
@@ -68,7 +65,6 @@ class InlineQueryResultAudio(InlineQueryResult):
         title: str,
         mime_type: str,
         id: str = None,
-        voice: bool = False,
         description: str = None,
         caption: str = "",
         performer: str = "",
@@ -82,7 +78,7 @@ class InlineQueryResultAudio(InlineQueryResult):
 
         self.audio_url = audio_url
         self.thumb_url = thumb_url
-        self.voice = voice
+        self.voice = True if self.mime_type == 'audio/ogg' else False
         self.title = title
         self.caption = caption
         self.description = description

+ 2 - 0
wbb/core/types/__init__.py

@@ -0,0 +1,2 @@
+from .InlineKeyboardButtons import InlineKeyboardButtonDict
+from .InlineQueryResult import InlineQueryResultCachedDocument, InlineQueryResultAudio

+ 31 - 2
wbb/modules/admin.py

@@ -22,10 +22,10 @@ __HELP__ = '''/ban - Ban A User
 /report | @admins - Report A Message To Admins.'''
 
 
-async def list_admins(group_id):
+async def list_admins(chat_id):
     list_of_admins = []
     async for member in app.iter_chat_members(
-            group_id, filter="administrators"):
+            chat_id, filter="administrators"):
         list_of_admins.append(member.user.id)
     return list_of_admins
 
@@ -54,6 +54,35 @@ async def member_permissions(chat_id, user_id):
     return perms
 
 
+async def current_chat_permissions(chat_id):
+    perms = []
+    perm = (await app.get_chat(chat_id)).permissions
+    if perm.can_send_messages:
+        perms.append("can_send_messages")
+    if perm.can_send_media_messages:
+        perms.append("can_send_media_messages")
+    if perm.can_send_stickers:
+        perms.append("can_send_stickers")
+    if perm.can_send_animations:
+        perms.append("can_send_animations")
+    if perm.can_send_games:
+        perms.append("can_send_games")
+    if perm.can_use_inline_bots:
+        perms.append("can_use_inline_bots")
+    if perm.can_add_web_page_previews:
+        perms.append("can_add_web_page_previews")
+    if perm.can_send_polls:
+        perms.append("can_send_polls")
+    if perm.can_change_info:
+        perms.append("can_change_info")
+    if perm.can_invite_users:
+        perms.append("can_invite_users")
+    if perm.can_pin_messages:
+        perms.append("can_pin_messages")
+
+    return perms
+
+
 # Get List Of Members In A Chat
 
 

+ 1 - 1
wbb/modules/chatbot.py

@@ -87,7 +87,7 @@ async def chatbot_status_ubot(_, message):
         return
 
     elif status == "OFF" or status == "off" or status == "Off":
-        if chat_id in active_chats_bot:
+        if chat_id in active_chats_ubot:
             active_chats_bot.remove(chat_id)
             await message.edit("Chatbot Disabled!")
             return

+ 81 - 0
wbb/modules/locks.py

@@ -0,0 +1,81 @@
+from wbb import SUDOERS, app
+from wbb.modules.admin import member_permissions, current_chat_permissions
+from wbb.core.decorators.errors import capture_err
+from pyrogram import filters
+from pyrogram.types import ChatPermissions
+from pyrogram.errors.exceptions.bad_request_400 import ChatNotModified
+
+__MODULE__ = "Locks"
+__HELP__ = """
+Commands: /lock | /unlock
+
+Parameters: 
+    messages | stickers | gifs | media | games | polls | inline | url | voice | commands | forwards
+
+You can only pass the "all" parameter with /lock, not with /unlock
+
+Example:
+    /lock all
+"""
+
+incorrect_parameters = "Incorrect Parameters, Check Locks Section In Help."
+data = {
+    "messages": "can_send_messages",
+    "stickers": "can_send_stickers",
+    "gifs": "can_send_animations",
+    "media": "can_send_media_messages",
+    "games": "can_send_games",
+    "inline": "can_use_inline_bots",
+    "link_previews": "can_add_web_page_previews",
+    "polls": "can_send_polls",
+    "group_info": "can_change_info",
+    "useradd": "can_invite_users",
+    "pin": "can_pin_messages"
+}
+
+async def tg_lock(message, permissions: list, perm: str, lock: bool):
+    if lock:
+        if perm not in permissions:
+            await message.reply_text("Already locked.")
+            return
+    else:
+        if perm in permissions:
+            await message.reply_text("Already Unlocked.")
+            return
+    (permissions.remove(perm) if lock else permissions.append(perm))
+    permissions = {perm: True for perm in list(set(permissions))}
+    try:
+        await app.set_chat_permissions(message.chat.id, ChatPermissions(**permissions))
+    except ChatNotModified:
+        await message.reply_text("To unlock this, you have to unlock 'messages' first.")
+        return
+    await message.reply_text(("Locked." if lock else "Unlocked."))
+
+
+@app.on_message(filters.command(["lock", "unlock"]) & ~filters.private)
+@capture_err
+async def locks_func(_, message):
+    user_id = message.from_user.id
+    chat_id = message.chat.id
+    if len(message.command) != 2:
+        await message.reply_text(incorrect_parameters)
+        return
+
+    parameter = message.text.strip().split(None, 1)[1].lower()
+    state = message.command[0].lower()
+    if parameter not in data and parameter != "all":
+        await message.reply_text(incorrect_parameters)
+        return
+
+    permissions = await member_permissions(chat_id, user_id)
+    if "can_restrict_members" not in permissions and user_id not in SUDOERS:
+        await message.reply_text("You Don't Have Enough Permissions.")
+        return
+
+    permissions = await current_chat_permissions(chat_id)
+    if parameter in data:
+        await tg_lock(message, permissions, data[parameter], True if state == "lock" else False)
+        return
+    elif parameter == "all" and state == "lock":
+        await app.set_chat_permissions(chat_id, ChatPermissions())
+        await message.reply_text("Locked Everything.")

+ 3 - 1
wbb/modules/stickers.py

@@ -6,7 +6,7 @@ from wbb.core.decorators.errors import capture_err
 from wbb.utils.files import resize_file_to_sticker_size, upload_document, get_document_from_file_id
 from wbb.utils.stickerset import get_sticker_set_by_name, create_sticker, add_sticker_to_set, create_sticker_set
 from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
-from pyrogram.errors.exceptions.bad_request_400 import PeerIdInvalid, StickerPngNopng, UserIsBlocked
+from pyrogram.errors.exceptions.bad_request_400 import PeerIdInvalid, StickerPngNopng, UserIsBlocked, StickerPngDimensions
 
 __MODULE__ = "Stickers"
 __HELP__ = """/sticker_id - To Get File ID of A Sticker.
@@ -118,3 +118,5 @@ async def kang(client, message):
         await msg.edit("You Need To Start A Private Chat With Me.", reply_markup=keyboard)
     except StickerPngNopng:
         await message.reply_text("Stickers must be png files but the provided image was not a png")
+    except StickerPngDimensions:
+        await message.reply_text("The sticker png dimensions are invalid.")

+ 1 - 1
wbb/utils/inlinefuncs.py

@@ -21,7 +21,7 @@ from wbb.utils.fetch import fetch
 from wbb.utils.functions import test_speedtest
 from wbb.utils.formatter import convert_seconds_to_minutes as time_convert
 from wbb.utils.pastebin import paste
-from wbb.core.types.InlineQueryResult import InlineQueryResultCachedDocument
+from wbb.core.types import InlineQueryResultCachedDocument
 from wbb import (
     arq, app, app2, USERBOT_USERNAME,
     BOT_USERNAME, LOG_GROUP_ID, USERBOT_ID,