Akshay Rajput 5 жил өмнө
parent
commit
e14c6ecccd

+ 2 - 1
.vim/coc-settings.json

@@ -1,3 +1,4 @@
 {
-  "python.formatting.provider": "black"
+  "python.formatting.provider": "black",
+  "python.jediEnabled": false
 }

+ 1 - 1
wbb/__main__.py

@@ -30,7 +30,7 @@ from pyrogram import filters, idle
 from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
 
 from wbb import (BOT_NAME, BOT_USERNAME, LOG_GROUP_ID, USERBOT_NAME,
-                 aiohttpsession, app, app2)
+                 aiohttpsession, app)
 from wbb.modules import ALL_MODULES
 from wbb.modules.sudoers import bot_sys_stats
 from wbb.utils import paginate_modules

+ 9 - 7
wbb/core/tasks.py

@@ -4,7 +4,7 @@ from time import time
 from pyrogram import filters
 from pyrogram.types import Message
 
-from wbb import BOT_ID, SUDOERS, USERBOT_PREFIX, app, app2, eor
+from wbb import BOT_ID, SUDOERS, USERBOT_PREFIX, app2
 from wbb.core.sections import bold, section, w
 
 tasks = {}
@@ -44,11 +44,13 @@ async def rm_task(task_id=None):
             if value[0].done() or value[0].cancelled():
                 del tasks[key]
 
-        if task_id is not None:
-            if task_id in tasks:
-                if not tasks[task_id][0].done():
-                    tasks[task_id][0].cancel()
-                del tasks[task_id]
+        if (task_id is not None) and (task_id in tasks):
+            task = tasks[task_id][0]
+
+            if not task.done():
+                task.cancel()
+
+            del tasks[task_id]
 
 
 async def _get_tasks_text():
@@ -92,7 +94,7 @@ async def task_list(_, message: Message):
 
     results = await app2.get_inline_bot_results(
         BOT_ID,
-        f"tasks",
+        "tasks",
     )
     await app2.send_inline_bot_result(
         message.chat.id,

+ 11 - 7
wbb/modules/chat_watcher.py

@@ -29,13 +29,17 @@ from wbb.utils.filter_groups import chat_watcher_group
 
 @app.on_message(group=chat_watcher_group)
 async def chat_watcher_func(_, message):
-    chat_id = message.chat.id
-    blacklisted_chats_list = await blacklisted_chats()
-    if chat_id:
-        if chat_id in blacklisted_chats_list:
-            return await app.leave_chat(chat_id)
-    if chat_id:
-        await add_served_chat(chat_id)
     if message.from_user:
         user_id = message.from_user.id
         await add_served_user(user_id)
+
+    chat_id = message.chat.id
+    blacklisted_chats_list = await blacklisted_chats()
+
+    if not chat_id:
+        return
+
+    if chat_id in blacklisted_chats_list:
+        return await app.leave_chat(chat_id)
+
+    await add_served_chat(chat_id)

+ 0 - 1
wbb/modules/devs.py

@@ -10,7 +10,6 @@ import re
 import subprocess
 import sys
 import traceback
-from inspect import getfullargspec
 from io import StringIO
 from time import time
 

+ 0 - 1
wbb/modules/misc.py

@@ -25,7 +25,6 @@ import secrets
 import string
 from asyncio import Lock
 
-import aiohttp
 from pyrogram import filters
 
 from wbb import app, arq

+ 3 - 3
wbb/modules/stickers.py

@@ -23,7 +23,7 @@ SOFTWARE.
 """
 import imghdr
 import os
-from asyncio import gather, sleep
+from asyncio import gather
 from traceback import format_exc
 
 from pyrogram import filters
@@ -36,7 +36,6 @@ from pyrogram.types import (InlineKeyboardButton,
 
 from wbb import BOT_USERNAME, SUDOERS, USERBOT_PREFIX, app, app2, eor
 from wbb.core.decorators.errors import capture_err
-from wbb.core.tasks import add_task
 from wbb.utils.files import (get_document_from_file_id,
                              resize_file_to_sticker_size,
                              upload_document)
@@ -127,7 +126,8 @@ async def userbot_kang(_, message: Message):
     await ub_m.edit(bot_reply.text.markdown)
 
     # Delete all extra messages.
-    [await m.delete() for m in [bot_reply, kang_m_bot, sticker_m]]
+    for m in [bot_reply, kang_m_bot, sticker_m]:
+        await m.delete()
 
 
 @app.on_message(filters.command("kang") & ~filters.edited)

+ 24 - 24
wbb/modules/taglogger.py

@@ -27,6 +27,7 @@ from pyrogram.types import InlineKeyboardButton, Message
 
 from wbb import (BOT_ID, LOG_GROUP_ID, LOG_MENTIONS, USERBOT_ID,
                  USERBOT_NAME, USERBOT_USERNAME, app, app2)
+from wbb.core.decorators.errors import capture_err
 from wbb.utils.filter_groups import taglog_group
 
 IS_USERBOT_ONLINE = False
@@ -69,29 +70,28 @@ async def sendLog(message: Message):
     & ~filters.edited,
     group=taglog_group,
 )
+@capture_err
 async def tagLoggerFunc(_, message: Message):
-    try:
-        if not LOG_MENTIONS:
-            return
-        if IS_USERBOT_ONLINE:
-            return
-        if message.reply_to_message:
-            reply_message = message.reply_to_message
-            if reply_message.from_user:
-                if reply_message.from_user.id == USERBOT_ID:
-                    return await sendLog(message)
-
-        if message.text:
-            text = message.text
-        elif message.caption:
-            text = message.caption
-        else:
-            return
-        if (
-            str(USERBOT_ID) in text
-            or str(USERBOT_USERNAME) in text
-            or USERBOT_NAME in text
+    if not LOG_MENTIONS:
+        return
+    if IS_USERBOT_ONLINE:
+        return
+    if message.reply_to_message:
+        reply_message = message.reply_to_message
+        if reply_message.from_user and (
+            reply_message.from_user.id == USERBOT_ID
         ):
-            await sendLog(message)
-    except Exception:
-        pass  # lol
+            return await sendLog(message)
+
+    if message.text:
+        text = message.text
+    elif message.caption:
+        text = message.caption
+    else:
+        return
+    if (
+        str(USERBOT_ID) in text
+        or str(USERBOT_USERNAME) in text
+        or USERBOT_NAME in text
+    ):
+        await sendLog(message)

+ 20 - 16
wbb/modules/userbot.py

@@ -10,8 +10,10 @@ import re
 import subprocess
 import sys
 import traceback
+from asyncio import sleep
 from html import escape
 from io import StringIO
+from time import time
 
 from pyrogram import filters
 from pyrogram.errors import MessageNotModified
@@ -19,7 +21,6 @@ from pyrogram.types import Message, ReplyKeyboardMarkup
 
 from wbb import app2  # don't remove
 from wbb import SUDOERS, USERBOT_PREFIX, app, arq, eor
-from wbb.core.sections import section
 from wbb.core.tasks import add_task, rm_task
 
 # Eval and Sh module from nana-remix
@@ -27,7 +28,6 @@ from wbb.core.tasks import add_task, rm_task
 m = None
 p = print
 r = None
-arq = arq
 arrow = lambda x: (x.text if isinstance(x, Message) else "") + "\n`→`"
 
 
@@ -49,14 +49,15 @@ async def iter_edit(message: Message, text: str):
         if not m.from_user or not m.text or not m.reply_to_message:
             continue
 
-        if m.reply_to_message.message_id == message.message_id:
-            if m.from_user.id == message.from_user.id:
-
-                if "→" in m.text:
-                    try:
-                        return await m.edit(text)
-                    except MessageNotModified:
-                        return
+        if (
+            (m.reply_to_message.message_id == message.message_id)
+            and (m.from_user.id == message.from_user.id)
+            and ("→" in m.text)
+        ):
+            try:
+                return await m.edit(text)
+            except MessageNotModified:
+                return
 
 
 @app2.on_message(
@@ -81,9 +82,10 @@ async def executor(client, message: Message):
     # To prevent keyboard input attacks
     if m.reply_to_message:
         r = m.reply_to_message
-        if r.reply_markup:
-            if isinstance(r.reply_markup, ReplyKeyboardMarkup):
-                return await eor(m, text="INSECURE!")
+        if r.reply_markup and isinstance(
+            r.reply_markup, ReplyKeyboardMarkup
+        ):
+            return await eor(m, text="INSECURE!")
     status = None
     old_stderr = sys.stderr
     old_stdout = sys.stdout
@@ -167,9 +169,11 @@ async def shellrunner(_, message: Message):
 
     if message.reply_to_message:
         r = message.reply_to_message
-        if r.reply_markup:
-            if isinstance(r.reply_markup, ReplyKeyboardMarkup):
-                return await eor(message, text="INSECURE!")
+        if r.reply_markup and isinstance(
+            r.reply_markup,
+            ReplyKeyboardMarkup,
+        ):
+            return await eor(message, text="INSECURE!")
 
     text = message.text.split(None, 1)[1]
     if "\n" in text:

+ 2 - 63
wbb/utils/dbfunctions.py

@@ -68,9 +68,6 @@ def str_to_obj(string: str):
     return obj
 
 
-""" Notes functions """
-
-
 async def get_notes_count() -> dict:
     chats = notesdb.find({"chat_id": {"$lt": 0}})
     if not chats:
@@ -130,9 +127,6 @@ async def delete_note(chat_id: int, name: str) -> bool:
     return False
 
 
-""" Filters funcions """
-
-
 async def get_filters_count() -> dict:
     chats = filtersdb.find({"chat_id": {"$lt": 0}})
     if not chats:
@@ -196,9 +190,6 @@ async def delete_filter(chat_id: int, name: str) -> bool:
     return False
 
 
-""" Warn functions """
-
-
 async def int_to_alpha(user_id: int) -> str:
     alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
     text = ""
@@ -269,9 +260,6 @@ async def remove_warns(chat_id: int, name: str) -> bool:
     return False
 
 
-""" Karma functions """
-
-
 async def get_karmas_count() -> dict:
     chats = karmadb.find({"chat_id": {"$lt": 0}})
     if not chats:
@@ -296,9 +284,8 @@ async def user_global_karma(user_id) -> int:
         karma = await get_karma(
             chat["chat_id"], await int_to_alpha(user_id)
         )
-        if karma:
-            if int(karma["karma"]) > 0:
-                total_karma += int(karma["karma"])
+        if karma and (int(karma["karma"]) > 0):
+            total_karma += int(karma["karma"])
     return total_karma
 
 
@@ -346,9 +333,6 @@ async def karma_off(chat_id: int):
     return await karmadb.insert_one({"chat_id_toggle": chat_id})
 
 
-""" Chats log functions """
-
-
 async def is_served_chat(chat_id: int) -> bool:
     chat = await chatsdb.find_one({"chat_id": chat_id})
     if not chat:
@@ -380,9 +364,6 @@ async def remove_served_chat(chat_id: int):
     return await chatsdb.delete_one({"chat_id": chat_id})
 
 
-""" USER LOG FUNCTIONS """
-
-
 async def is_served_user(user_id: int) -> bool:
     user = await usersdb.find_one({"user_id": user_id})
     if not user:
@@ -407,9 +388,6 @@ async def add_served_user(user_id: int):
     return await usersdb.insert_one({"user_id": user_id})
 
 
-""" Gban functions """
-
-
 async def get_gbans_count() -> int:
     users = gbansdb.find({"user_id": {"$gt": 0}})
     users = await users.to_list(length=100000)
@@ -437,9 +415,6 @@ async def remove_gban_user(user_id: int):
     return await gbansdb.delete_one({"user_id": user_id})
 
 
-# Couple Chooser
-
-
 async def _get_lovers(chat_id: int):
     lovers = await coupledb.find_one({"chat_id": chat_id})
     if not lovers:
@@ -464,9 +439,6 @@ async def save_couple(chat_id: int, date: str, couple: dict):
     )
 
 
-# Captcha
-
-
 async def is_captcha_on(chat_id: int) -> bool:
     chat = await captchadb.find_one({"chat_id": chat_id})
     if not chat:
@@ -488,9 +460,6 @@ async def captcha_off(chat_id: int):
     return await captchadb.insert_one({"chat_id": chat_id})
 
 
-"""Anti Service System"""
-
-
 async def is_antiservice_on(chat_id: int) -> bool:
     chat = await antiservicedb.find_one({"chat_id": chat_id})
     if not chat:
@@ -512,9 +481,6 @@ async def antiservice_off(chat_id: int):
     return await antiservicedb.insert_one({"chat_id": chat_id})
 
 
-""" PM PERMIT """
-
-
 async def is_pmpermit_approved(user_id: int) -> bool:
     user = await pmpermitdb.find_one({"user_id": user_id})
     if not user:
@@ -536,9 +502,6 @@ async def disapprove_pmpermit(user_id: int):
     return await pmpermitdb.delete_one({"user_id": user_id})
 
 
-""" WELCOME FUNCTIONS """
-
-
 async def get_welcome(chat_id: int) -> str:
     text = await welcomedb.find_one({"chat_id": chat_id})
     if not text:
@@ -556,9 +519,6 @@ async def del_welcome(chat_id: int):
     return await welcomedb.delete_one({"chat_id": chat_id})
 
 
-""" CAPTCHA CACHE SYSTEM """
-
-
 async def update_captcha_cache(captcha_dict):
     pickle = obj_to_str(captcha_dict)
     await captcha_cachedb.delete_one({"captcha": "cache"})
@@ -578,9 +538,6 @@ async def get_captcha_cache():
     return str_to_obj(cache["pickled"])
 
 
-""" BLACKLIST FILTERS SYSTEM """
-
-
 async def get_blacklist_filters_count() -> dict:
     chats = blacklist_filtersdb.find({"chat_id": {"$lt": 0}})
     if not chats:
@@ -631,9 +588,6 @@ async def delete_blacklist_filter(chat_id: int, word: str) -> bool:
     return False
 
 
-""" PIPES SYSTEM """
-
-
 async def activate_pipe(
     from_chat_id: int, to_chat_id: int, fetcher: str
 ):
@@ -680,9 +634,6 @@ async def show_pipes() -> list:
     return pipes["pipes"]
 
 
-""" SUDOERS FUNCTIONS """
-
-
 async def get_sudoers() -> list:
     sudoers = await sudoersdb.find_one({"sudo": "sudo"})
     if not sudoers:
@@ -708,9 +659,6 @@ async def remove_sudo(user_id: int) -> bool:
     return True
 
 
-""" BLACKLISTED CHATS """
-
-
 async def blacklisted_chats() -> list:
     chats = blacklist_chatdb.find({"chat_id": {"$lt": 0}})
     return [
@@ -733,9 +681,6 @@ async def whitelist_chat(chat_id: int) -> bool:
     return False
 
 
-""" Restart stage """
-
-
 async def start_restart_stage(chat_id: int, message_id: int):
     await restart_stagedb.update_one(
         {"something": "something"},
@@ -760,9 +705,6 @@ async def clean_restart_stage() -> dict:
     }
 
 
-"""FLOOD System"""
-
-
 async def is_flood_on(chat_id: int) -> bool:
     chat = await flood_toggle_db.find_one({"chat_id": chat_id})
     if not chat:
@@ -784,9 +726,6 @@ async def flood_off(chat_id: int):
     return await flood_toggle_db.insert_one({"chat_id": chat_id})
 
 
-""" RSS DB """
-
-
 async def add_rss_feed(chat_id: int, url: str, last_title: str):
     return await rssdb.update_one(
         {"chat_id": chat_id},

+ 1 - 2
wbb/utils/downloader.py

@@ -1,11 +1,10 @@
-from inspect import iscoroutinefunction
 from os.path import abspath as absolute_path
 from time import time
 
 import aiofiles
 
 from wbb import aiohttpsession as session
-from wbb.core.tasks import add_task, rm_task
+from wbb.core.tasks import add_task
 
 
 def ensure_status(status_code: int):

+ 4 - 11
wbb/utils/functions.py

@@ -30,19 +30,15 @@ from random import randint
 from re import findall
 from re import sub as re_sub
 from sys import executable
-from time import time
 
 import aiofiles
-import aiohttp
 import speedtest
 from PIL import Image, ImageDraw, ImageFilter, ImageFont
-from pyrogram.errors import MessageNotModified
 from pyrogram.types import Message
 
 from wbb import aiohttpsession as aiosession
-from wbb.modules.userbot import eor
 from wbb.utils.dbfunctions import start_restart_stage
-from wbb.utils.http import get
+from wbb.utils.http import get, post
 
 
 async def restart(m: Message):
@@ -134,12 +130,9 @@ async def transfer_sh(file_or_message):
     file = file_or_message
     async with aiofiles.open(file, "rb") as f:
         params = {file: await f.read()}
-    async with aiohttp.ClientSession() as session:
-        async with session.post(
-            "https://transfer.sh/", data=params
-        ) as resp:
-            download_link = str(await resp.text()).strip()
-    return download_link
+        resp = await post("https://transfer.sh/", data=params)
+        url = resp.strip()
+    return url
 
 
 async def calc_distance_from_ip(ip1: str, ip2: str) -> float: