Selaa lähdekoodia

Fixed some deepsource things (#106)

Akshay Rajput 5 vuotta sitten
vanhempi
sitoutus
d50a9ad859

+ 2 - 2
sample_config.py

@@ -14,9 +14,9 @@ if HEROKU:
     )
     SESSION_STRING = environ.get("SESSION_STRING", None)
     USERBOT_PREFIX = environ.get("USERBOT_PREFIX", ".")
-    SUDO_USERS_ID = list(
+    SUDO_USERS_ID = [
         int(x) for x in environ.get("SUDO_USERS_ID", "").split()
-    )
+    ]
     LOG_GROUP_ID = int(environ.get("LOG_GROUP_ID", None))
     GBAN_LOG_GROUP_ID = int(environ.get("GBAN_LOG_GROUP_ID", None))
     MESSAGE_DUMP_CHAT = int(environ.get("MESSAGE_DUMP_CHAT", None))

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

@@ -104,7 +104,7 @@ class InlineQueryResultAudio(InlineQueryResult):
 
         self.audio_url = audio_url
         self.thumb_url = thumb_url
-        self.voice = True if mime_type == "audio/ogg" else False
+        self.voice = bool(mime_type == "audio/ogg")
         self.title = title
         self.caption = caption
         self.description = description

+ 3 - 3
wbb/modules/admin.py

@@ -144,7 +144,7 @@ async def list_members(group_id):
     filters.command("purge") & ~filters.edited & ~filters.private
 )
 @adminsOnly("can_delete_messages")
-async def purgeFunc(client, message: Message):
+async def purgeFunc(_, message: Message):
     await message.delete()
 
     if not message.reply_to_message:
@@ -402,8 +402,8 @@ async def pin(_, message: Message):
         disable_web_page_preview=True,
     )
     msg = "Please check the pinned message: ~ " + f"[Check, {r.link}]"
-    filter = dict(type="text", data=msg)
-    await save_filter(message.chat.id, "~pinned", filter)
+    filter_ = dict(type="text", data=msg)
+    await save_filter(message.chat.id, "~pinned", filter_)
 
 
 # Mute members

+ 1 - 1
wbb/modules/anonymize.py

@@ -34,7 +34,7 @@ from pyrogram.types import Chat, Message
 from wbb import LOG_GROUP_ID, SUDOERS, USERBOT_ID, USERBOT_PREFIX
 from wbb import aiohttpsession as session
 from wbb import app, app2
-from wbb.modules.userbot import eor as eor
+from wbb.modules.userbot import eor
 from wbb.utils.functions import extract_user
 
 

+ 3 - 1
wbb/modules/crypto.py

@@ -22,7 +22,9 @@ async def crypto(_, message):
     currency = message.text.split(None, 1)[1].lower()
 
     btn = ikb(
-        {"Available Currencies": "https://plotcryptoprice.herokuapp.com"},
+        {
+            "Available Currencies": "https://plotcryptoprice.herokuapp.com"
+        },
     )
 
     m = await message.reply("`Processing...`")

+ 3 - 3
wbb/modules/devs.py

@@ -38,7 +38,7 @@ async def aexec(code, client, message):
     & ~filters.edited
     & filters.command("eval")
 )
-async def executor(client, message):
+async def executor(client, message: Message):
     try:
         cmd = message.text.split(" ", maxsplit=1)[1]
     except IndexError:
@@ -118,7 +118,7 @@ async def runtime_func_cq(_, cq):
     & ~filters.edited
     & filters.command("sh"),
 )
-async def shellrunner(client, message):
+async def shellrunner(_, message: Message):
     if len(message.command) < 2:
         return await eor(message, text="**Usage:**\n/sh git pull")
     text = message.text.split(None, 1)[1]
@@ -143,7 +143,7 @@ async def shellrunner(client, message):
             output += "\n"
     else:
         shell = re.split(""" (?=(?:[^'"]|'[^']*'|"[^"]*")*$)""", text)
-        for a in range(len(shell)):
+        for a, _ in enumerate(shell):
             shell[a] = shell[a].replace('"', "")
         try:
             process = subprocess.Popen(

+ 0 - 1
wbb/modules/download_upload.py

@@ -33,7 +33,6 @@ from pyrogram.types import Message
 from wbb import SUDOERS, USERBOT_PREFIX, app2, eor
 from wbb.core.sections import section
 from wbb.core.tasks import add_task, rm_task
-from wbb.modules.userbot import eor
 from wbb.utils.downloader import download
 
 

+ 10 - 8
wbb/modules/filters.py

@@ -149,18 +149,20 @@ async def filters_re(_, message):
                         reply_markup=keyb,
                         disable_web_page_preview=True,
                     )
+
                     if text.startswith("~"):
-                        return await message.delete()
+                        await message.delete()
                     return
+
                 return await message.reply_text(
                     data,
                     reply_markup=keyb,
                     disable_web_page_preview=True,
                 )
-            else:
-                if message.reply_to_message:
-                    await message.reply_to_message.reply_sticker(data)
-                    if text.startswith("~"):
-                        return await message.delete()
-                    return
-                return await message.reply_sticker(data)
+            if message.reply_to_message:
+                await message.reply_to_message.reply_sticker(data)
+
+                if text.startswith("~"):
+                    await message.delete()
+                return
+            return await message.reply_sticker(data)

+ 52 - 51
wbb/modules/greetings.py

@@ -231,59 +231,60 @@ async def callback_query_welcome_button(_, callback_query):
             ):
                 correct_answer = i["answer"]
                 keyboard = i["keyboard"]
-    if pending_user_id == pressed_user_id:
-        if answer != correct_answer:
-            await callback_query.answer("Yeah, It's Wrong.")
-            for iii in answers_dicc:
-                if (
-                    iii["user_id"] == pending_user_id
-                    and iii["chat_id"] == button_message.chat.id
-                ):
-                    attempts = iii["attempts"]
-                    if attempts >= 3:
-                        answers_dicc.remove(iii)
-                        await button_message.chat.kick_member(
-                            pending_user_id
-                        )
-                        await asyncio.sleep(1)
-                        await button_message.chat.unban_member(
-                            pending_user_id
-                        )
-                        await button_message.delete()
-                        await update_captcha_cache(answers_dicc)
-                        return
-                    else:
-                        iii["attempts"] += 1
-                        break
-            shuffle(keyboard[0])
-            shuffle(keyboard[1])
-            shuffle(keyboard[2])
-            shuffle(keyboard)
-            keyboard = InlineKeyboardMarkup(keyboard)
-            await button_message.edit(
-                text=button_message.caption.markdown,
-                reply_markup=keyboard,
-            )
-            return
-        await callback_query.answer("Captcha passed successfully!")
-        await button_message.chat.unban_member(pending_user_id)
-        await button_message.delete()
-        if len(answers_dicc) != 0:
-            for ii in answers_dicc:
-                if (
-                    ii["user_id"] == pending_user_id
-                    and ii["chat_id"] == button_message.chat.id
-                ):
-                    answers_dicc.remove(ii)
+
+    if pending_user_id != pressed_user_id:
+        return await callback_query.answer("This is not for you")
+
+    if answer != correct_answer:
+        await callback_query.answer("Yeah, It's Wrong.")
+        for iii in answers_dicc:
+            if (
+                iii["user_id"] == pending_user_id
+                and iii["chat_id"] == button_message.chat.id
+            ):
+                attempts = iii["attempts"]
+                if attempts >= 3:
+                    answers_dicc.remove(iii)
+                    await button_message.chat.kick_member(
+                        pending_user_id
+                    )
+                    await asyncio.sleep(1)
+                    await button_message.chat.unban_member(
+                        pending_user_id
+                    )
+                    await button_message.delete()
                     await update_captcha_cache(answers_dicc)
-        """ send welcome message """
-        await send_welcome_message(
-            callback_query.message.chat, pending_user_id
+                    return
+
+                iii["attempts"] += 1
+                break
+
+        shuffle(keyboard[0])
+        shuffle(keyboard[1])
+        shuffle(keyboard[2])
+        shuffle(keyboard)
+        keyboard = InlineKeyboardMarkup(keyboard)
+        return await button_message.edit(
+            text=button_message.caption.markdown,
+            reply_markup=keyboard,
         )
-        return
-    else:
-        await callback_query.answer("This is not for you")
-        return
+
+    await callback_query.answer("Captcha passed successfully!")
+    await button_message.chat.unban_member(pending_user_id)
+    await button_message.delete()
+
+    if len(answers_dicc) != 0:
+        for ii in answers_dicc:
+            if (
+                ii["user_id"] == pending_user_id
+                and ii["chat_id"] == button_message.chat.id
+            ):
+                answers_dicc.remove(ii)
+                await update_captcha_cache(answers_dicc)
+
+    return await send_welcome_message(
+        callback_query.message.chat, pending_user_id
+    )
 
 
 async def kick_restricted_after_delay(

+ 3 - 1
wbb/modules/img_pdf.py

@@ -83,7 +83,9 @@ async def convert(
 
     await m.delete()
     pdf.close()
-    [remove(file) for file in documents if path.exists(file)]
+    for file in documents:
+        if path.exists(file):
+            remove(file)
 
 
 @app.on_message(filters.command("pdf"))

+ 13 - 9
wbb/modules/info.py

@@ -27,7 +27,6 @@ from pyrogram import filters
 from pyrogram.types import Message
 
 from wbb import SUDOERS, app
-from wbb.core.decorators.errors import capture_err
 from wbb.core.sections import section
 from wbb.utils.dbfunctions import is_gbanned_user, user_global_karma
 
@@ -72,7 +71,7 @@ async def get_chat_info(chat, already=False):
     chat_id = chat.id
     username = chat.username
     title = chat.title
-    type = chat.type
+    type_ = chat.type
     is_scam = chat.is_scam
     description = chat.description
     members = chat.members_count
@@ -83,7 +82,7 @@ async def get_chat_info(chat, already=False):
     body = {
         "ID": chat_id,
         "DC": dc_id,
-        "Type": type,
+        "Type": type_,
         "Name": [title],
         "Username": [("@" + username) if username else None],
         "Mention": [link],
@@ -97,7 +96,6 @@ async def get_chat_info(chat, already=False):
 
 
 @app.on_message(filters.command("info"))
-@capture_err
 async def info_func(_, message: Message):
     if message.reply_to_message:
         user = message.reply_to_message.from_user.id
@@ -105,16 +103,20 @@ async def info_func(_, message: Message):
         user = message.from_user.id
     elif not message.reply_to_message and len(message.command) != 1:
         user = message.text.split(None, 1)[1]
+
     m = await message.reply_text("Processing")
+
     try:
         info_caption, photo_id = await get_user_info(user)
     except Exception as e:
         return await m.edit(str(e))
+
     if not photo_id:
         return await m.edit(
             info_caption, disable_web_page_preview=True
         )
     photo = await app.download_media(photo_id)
+
     await message.reply_photo(
         photo, caption=info_caption, quote=False
     )
@@ -123,30 +125,32 @@ async def info_func(_, message: Message):
 
 
 @app.on_message(filters.command("chat_info"))
-@capture_err
 async def chat_info_func(_, message: Message):
     try:
         if len(message.command) > 2:
             return await message.reply_text(
                 "**Usage:**/chat_info [USERNAME|ID]"
             )
-        elif len(message.command) == 1:
+
+        if len(message.command) == 1:
             chat = message.chat.id
         elif len(message.command) == 2:
             chat = message.text.split(None, 1)[1]
+
         m = await message.reply_text("Processing")
+
         info_caption, photo_id = await get_chat_info(chat)
         if not photo_id:
             return await m.edit(
                 info_caption, disable_web_page_preview=True
             )
+
         photo = await app.download_media(photo_id)
         await message.reply_photo(
             photo, caption=info_caption, quote=False
         )
+
         await m.delete()
         os.remove(photo)
     except Exception as e:
-        await message.reply_text(e)
-        print(e)
-        await m.delete()
+        await m.edit(e)

+ 0 - 1
wbb/modules/inline.py

@@ -42,7 +42,6 @@ async def inline_query_handler(client, query):
             await client.answer_inline_query(
                 query.id, results=answerss, cache_time=10
             )
-            return
         elif text.split()[0] == "alive":
             answerss = await alive_function(answers)
             await client.answer_inline_query(

+ 18 - 9
wbb/modules/locks.py

@@ -71,11 +71,14 @@ async def tg_lock(message, permissions: list, perm: str, lock: bool):
     if lock:
         if perm not in permissions:
             return await message.reply_text("Already locked.")
+        permissions.remove(perm)
     else:
         if perm in permissions:
             return await message.reply_text("Already Unlocked.")
-    (permissions.remove(perm) if lock else permissions.append(perm))
+        permissions.append(perm)
+
     permissions = {perm: True for perm in list(set(permissions))}
+
     try:
         await app.set_chat_permissions(
             message.chat.id, ChatPermissions(**permissions)
@@ -84,6 +87,7 @@ async def tg_lock(message, permissions: list, perm: str, lock: bool):
         return await message.reply_text(
             "To unlock this, you have to unlock 'messages' first."
         )
+
     await message.reply_text(("Locked." if lock else "Unlocked."))
 
 
@@ -94,18 +98,22 @@ async def tg_lock(message, permissions: list, perm: str, lock: bool):
 async def locks_func(_, message):
     if len(message.command) != 2:
         return await message.reply_text(incorrect_parameters)
+
     chat_id = message.chat.id
     parameter = message.text.strip().split(None, 1)[1].lower()
     state = message.command[0].lower()
+
     if parameter not in data and parameter != "all":
         return await message.reply_text(incorrect_parameters)
+
     permissions = await current_chat_permissions(chat_id)
+
     if parameter in data:
-        return await tg_lock(
+        await tg_lock(
             message,
             permissions,
             data[parameter],
-            True if state == "lock" else False,
+            bool(state == "lock"),
         )
     elif parameter == "all" and state == "lock":
         await app.set_chat_permissions(chat_id, ChatPermissions())
@@ -116,11 +124,14 @@ async def locks_func(_, message):
 @capture_err
 async def locktypes(_, message):
     permissions = await current_chat_permissions(message.chat.id)
+
     if not permissions:
         return await message.reply_text("No Permissions.")
+
     perms = ""
     for i in permissions:
         perms += f"__**{i}**__\n"
+
     await message.reply_text(perms)
 
 
@@ -129,14 +140,12 @@ 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:
+
+    if not text or not user:
         return
-    if user.id in await list_admins(chat_id):
+    if user.id in (SUDOERS + (await list_admins(chat_id))):
         return
+
     check = get_urls_from_text(text)
     if check:
         permissions = await current_chat_permissions(chat_id)

+ 2 - 2
wbb/modules/music.py

@@ -54,7 +54,7 @@ def get_file_extension_from_url(url):
     return basename.split(".")[-1]
 
 
-def download_youtube_audio(url: str, m=0):
+def download_youtube_audio(url: str):
     global is_downloading
     with youtube_dl.YoutubeDL(
         {
@@ -109,7 +109,7 @@ async def music(_, message):
     try:
         loop = get_running_loop()
         music = await loop.run_in_executor(
-            None, partial(download_youtube_audio, url, message)
+            None, partial(download_youtube_audio, url)
         )
         if not music:
             await m.edit("Too Long, Can't Download.")

+ 2 - 2
wbb/modules/purge_me.py

@@ -119,12 +119,12 @@ async def purge_me_func(_, message: Message):
     # because we can't delete more than 100 messages at once,
     # we have to do it in chunks of 100, i'll choose 99 just
     # to be safe.
-    to_delete = list(
+    to_delete = [
         (
             message_ids[i : i + 99]
             for i in range(0, len(message_ids), 99)
         )
-    )
+    ]
 
     for hundred_messages_or_less in to_delete:
         await app2.delete_messages(

+ 6 - 8
wbb/modules/quotly.py

@@ -88,19 +88,17 @@ async def quotly_func(client, message: Message):
         if arg[0]:
             if arg[1] < 2 or arg[1] > 10:
                 return await m.edit("Argument must be between 2-10.")
+
             count = arg[1]
+
             messages = [
                 i
                 for i in await client.get_messages(
                     message.chat.id,
-                    [
-                        i
-                        for i in range(
-                            message.reply_to_message.message_id,
-                            message.reply_to_message.message_id
-                            + count,
-                        )
-                    ],
+                    range(
+                        message.reply_to_message.message_id,
+                        message.reply_to_message.message_id + count,
+                    ),
                     replies=0,
                 )
                 if not i.empty

+ 1 - 4
wbb/modules/regex.py

@@ -80,10 +80,7 @@ def infinite_checker(repl):
     ]
     for match in regex:
         status = re.search(match, repl)
-        if status:
-            return True
-        else:
-            return False
+        return bool(status)
 
 
 def separate_sed(sed_string):

+ 3 - 4
wbb/modules/userbot.py

@@ -146,8 +146,7 @@ async def executor(client, message: Message):
         status_ = await iter_edit(message, final_output)
         if status_ == 0:
             return await message.reply(final_output, quote=True)
-        else:
-            return
+        return
     if not status.from_user:
         status = await app2.get_messages(
             status.chat.id, status.message_id
@@ -162,7 +161,7 @@ async def executor(client, message: Message):
     & ~filters.edited
     & filters.command("sh", prefixes=USERBOT_PREFIX),
 )
-async def shellrunner(client, message: Message):
+async def shellrunner(_, message: Message):
     if len(message.command) < 2:
         return await eor(message, text="**Usage:**\n/sh git pull")
 
@@ -197,7 +196,7 @@ async def shellrunner(client, message: Message):
             output += "\n"
     else:
         shell = re.split(""" (?=(?:[^'"]|'[^']*'|"[^"]*")*$)""", text)
-        for a in range(len(shell)):
+        for a, _ in enumerate(shell):
             shell[a] = shell[a].replace('"', "")
         try:
             process = subprocess.Popen(

+ 8 - 11
wbb/utils/dbfunctions.py

@@ -56,16 +56,16 @@ flood_toggle_db = db.flood_toggle
 rssdb = db.rss
 
 
-def obj_to_str(object):
-    if not object:
+def obj_to_str(obj):
+    if not obj:
         return False
-    string = codecs.encode(pickle.dumps(object), "base64").decode()
+    string = codecs.encode(pickle.dumps(obj), "base64").decode()
     return string
 
 
 def str_to_obj(string: str):
-    object = pickle.loads(codecs.decode(string.encode(), "base64"))
-    return object
+    obj = pickle.loads(codecs.decode(string.encode(), "base64"))
+    return obj
 
 
 """ Notes functions """
@@ -103,8 +103,7 @@ async def get_note(chat_id: int, name: str) -> Union[bool, dict]:
     _notes = await _get_notes(chat_id)
     if name in _notes:
         return _notes[name]
-    else:
-        return False
+    return False
 
 
 async def save_note(chat_id: int, name: str, note: dict):
@@ -169,8 +168,7 @@ async def get_filter(chat_id: int, name: str) -> Union[bool, dict]:
     _filters = await _get_filters(chat_id)
     if name in _filters:
         return _filters[name]
-    else:
-        return False
+    return False
 
 
 async def save_filter(chat_id: int, name: str, _filter: dict):
@@ -453,8 +451,7 @@ async def get_couple(chat_id: int, date: str):
     lovers = await _get_lovers(chat_id)
     if date in lovers:
         return lovers[date]
-    else:
-        return False
+    return False
 
 
 async def save_couple(chat_id: int, date: str, couple: dict):

+ 4 - 1
wbb/utils/formatter.py

@@ -38,10 +38,13 @@ def get_readable_time(seconds: int) -> str:
             break
         time_list.append(int(result))
         seconds = int(remainder)
-    for i in range(len(time_list)):
+
+    for i, _ in enumerate(time_list):
         time_list[i] = str(time_list[i]) + time_suffix_list[i]
+
     if len(time_list) == 4:
         ping_time += time_list.pop() + ", "
+
     time_list.reverse()
     ping_time += ":".join(time_list)
     return ping_time

+ 6 - 4
wbb/utils/functions.py

@@ -240,8 +240,9 @@ async def extract_user_and_reason(message):
     if len(args) == 2:
         user = text.split(None, 1)[1]
         return await extract_userid(message, user), None
+
     # if reason is given
-    elif len(args) > 2:
+    if len(args) > 2:
         user, reason = text.split(None, 2)[1:]
         return await extract_userid(message, user), reason
 
@@ -261,10 +262,11 @@ def get_file_id_from_message(
     if message.document:
         if int(message.document.file_size) > max_file_size:
             return
+
         mime_type = message.document.mime_type
-        if mime_types:
-            if mime_type not in mime_types:
-                return
+
+        if mime_type not in mime_types:
+            return
         file_id = message.document.file_id
 
     if message.sticker:

+ 1 - 6
wbb/utils/json_prettify.py

@@ -27,12 +27,7 @@ async def json_object_prettify(objecc):
     dicc = objecc.__dict__
     output = ""
     for key, value in dicc.items():
-        if (
-            key == "pinned_message"
-            or key == "photo"
-            or key == "_"
-            or key == "_client"
-        ):
+        if key in ["pinned_message", "photo", "_", "_client"]:
             continue
         output += f"**{key}:** `{value}`\n"
     return output

+ 4 - 2
wbb/utils/read_lines.py

@@ -21,8 +21,10 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 SOFTWARE.
 """
-import random
+from random import choice
 
 
 async def random_line(fname):
-    return random.choice(open(fname).read().splitlines())
+    with open(fname) as f:
+        data = f.read().splitlines()
+    return choice(data)

+ 4 - 5
wbb/utils/rss.py

@@ -28,10 +28,9 @@ class Feed:
             text += f"**Published:** `{self.published}`\n"
         if self.updated:
             text += f"**Last Updated:** `{self.updated}`\n"
-        if self.summary:
-            if "<div" not in self.summary:
-                text += f"**Summary:** {self.summary.strip()}\n"
+
+        if self.summary and "<div" not in self.summary:
+            text += f"**Summary:** {self.summary.strip()}\n"
 
         if text:
-            text = "\n".join([i.strip() for i in text.splitlines()])
-        return text
+            return "\n".join([i.strip() for i in text.splitlines()])