TheHamkerCat 5 лет назад
Родитель
Сommit
140ee3ad79

+ 8 - 6
wbb/modules/admin.py

@@ -124,10 +124,7 @@ async def current_chat_permissions(chat_id):
 
 
 
 
 async def list_members(group_id):
 async def list_members(group_id):
-    list_of_members = []
-    async for member in app.iter_chat_members(group_id):
-        list_of_members.append(member.user.id)
-    return list_of_members
+    return [member.user.id async for member in app.iter_chat_members(group_id)]
 
 
 
 
 # Purge Messages
 # Purge Messages
@@ -259,7 +256,9 @@ async def deleteFunc(_, message: Message):
 # Promote Members
 # Promote Members
 
 
 
 
-@app.on_message(filters.command("promote") & ~filters.edited & ~filters.private)
+@app.on_message(
+    filters.command("promote") & ~filters.edited & ~filters.private
+)
 @adminsOnly("can_promote_members")
 @adminsOnly("can_promote_members")
 async def promoteFunc(_, message: Message):
 async def promoteFunc(_, message: Message):
     user_id = await extract_user(message)
     user_id = await extract_user(message)
@@ -354,6 +353,7 @@ async def mute(_, message: Message):
 **Muted User:** {mention}
 **Muted User:** {mention}
 **Muted By:** {message.from_user.mention if message.from_user else 'Anon'}
 **Muted By:** {message.from_user.mention if message.from_user else 'Anon'}
 **Reason:** {reason or 'No Reason Provided.'}"""
 **Reason:** {reason or 'No Reason Provided.'}"""
+    
     await message.reply_text(msg, reply_markup=keyboard)
     await message.reply_text(msg, reply_markup=keyboard)
 
 
 
 
@@ -473,7 +473,9 @@ async def remove_warning(_, cq: CallbackQuery):
 # Rmwarns
 # Rmwarns
 
 
 
 
-@app.on_message(filters.command("rmwarns") & ~filters.edited & ~filters.private)
+@app.on_message(
+    filters.command("rmwarns") & ~filters.edited & ~filters.private
+)
 @adminsOnly("can_restrict_members")
 @adminsOnly("can_restrict_members")
 async def remove_warnings(_, message: Message):
 async def remove_warnings(_, message: Message):
     if not message.reply_to_message:
     if not message.reply_to_message:

+ 0 - 3
wbb/modules/carbon.py

@@ -4,9 +4,6 @@ from wbb import app
 from wbb.core.decorators.errors import capture_err
 from wbb.core.decorators.errors import capture_err
 from wbb.utils.functions import make_carbon
 from wbb.utils.functions import make_carbon
 
 
-__MODULE__ = "Carbon"
-__HELP__ = "/carbon - Make Carbon Of Code."
-
 
 
 @app.on_message(filters.command("carbon"))
 @app.on_message(filters.command("carbon"))
 @capture_err
 @capture_err

+ 5 - 7
wbb/modules/chat_watcher.py

@@ -32,13 +32,11 @@ from wbb.utils.filter_groups import chat_watcher_group
 async def chat_watcher_func(_, message):
 async def chat_watcher_func(_, message):
     chat_id = message.chat.id
     chat_id = message.chat.id
     blacklisted_chats_list = await blacklisted_chats()
     blacklisted_chats_list = await blacklisted_chats()
-    if chat_id in blacklisted_chats_list:
-        return await app.leave_chat(chat_id)
-    is_served = await is_served_chat(chat_id)
-    if not is_served:
+    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)
         await add_served_chat(chat_id)
     if message.from_user:
     if message.from_user:
         user_id = message.from_user.id
         user_id = message.from_user.id
-        is_served = await is_served_user(user_id)
-        if not is_served:
-            await add_served_user(user_id)
+        await add_served_user(user_id)

+ 2 - 0
wbb/modules/devs.py

@@ -41,6 +41,7 @@ async def edit_or_reply(msg: Message, **kwargs):
     filters.user(SUDOERS)
     filters.user(SUDOERS)
     & ~filters.forwarded
     & ~filters.forwarded
     & ~filters.via_bot
     & ~filters.via_bot
+    & ~filters.edited
     & filters.command("eval")
     & filters.command("eval")
 )
 )
 async def executor(client, message):
 async def executor(client, message):
@@ -119,6 +120,7 @@ async def runtime_func_cq(_, cq):
     filters.user(SUDOERS)
     filters.user(SUDOERS)
     & ~filters.forwarded
     & ~filters.forwarded
     & ~filters.via_bot
     & ~filters.via_bot
+    & ~filters.edited
     & filters.command("sh"),
     & filters.command("sh"),
 )
 )
 async def shellrunner(client, message):
 async def shellrunner(client, message):

+ 13 - 4
wbb/modules/flood.py

@@ -21,6 +21,7 @@ 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
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 SOFTWARE.
 SOFTWARE.
 """
 """
+from asyncio import sleep, get_running_loop
 from time import time
 from time import time
 
 
 from pyrogram import filters
 from pyrogram import filters
@@ -35,7 +36,7 @@ from wbb.utils.filter_groups import flood_group
 
 
 __MODULE__ = "Flood"
 __MODULE__ = "Flood"
 __HELP__ = """
 __HELP__ = """
-Anti-Flood system, the one who sends more than 7 messages in a row, gets muted for an hour (Except for admins).
+Anti-Flood system, the one who sends more than 10 messages in a row, gets muted for an hour (Except for admins).
 
 
 And no, you can't change the number of messages or action type.
 And no, you can't change the number of messages or action type.
 """
 """
@@ -85,8 +86,8 @@ async def flood_control_func(_, message: Message):
     if user_id in mods:
     if user_id in mods:
         return
         return
 
 
-    # Mute if user sends more than 7 messages in a row
-    if DB[chat_id][user_id] >= 7:
+    # Mute if user sends more than 10 messages in a row
+    if DB[chat_id][user_id] >= 10:
         DB[chat_id][user_id] = 0
         DB[chat_id][user_id] = 0
         try:
         try:
             await message.chat.restrict_member(
             await message.chat.restrict_member(
@@ -106,10 +107,18 @@ async def flood_control_func(_, message: Message):
                 ]
                 ]
             ]
             ]
         )
         )
-        return await message.reply_text(
+        m = await message.reply_text(
             f"Imagine flooding the chat in front of me, Muted {mention} for an hour!",
             f"Imagine flooding the chat in front of me, Muted {mention} for an hour!",
             reply_markup=keyboard,
             reply_markup=keyboard,
         )
         )
+        async def delete():
+            await sleep(3600)
+            try:
+                await m.delete()
+            except Exception:
+                pass
+        loop = get_running_loop()
+        return loop.create_task(delete())
     DB[chat_id][user_id] += 1
     DB[chat_id][user_id] += 1
 
 
 
 

+ 5 - 1
wbb/modules/misc.py

@@ -49,6 +49,8 @@ __HELP__ = """
 /json [URL] - Get JSON Response From An API or Something.
 /json [URL] - Get JSON Response From An API or Something.
 /arq - Statistics Of ARQ API.
 /arq - Statistics Of ARQ API.
 /webss [URL] - Take A Screenshot Of A Webpage
 /webss [URL] - Take A Screenshot Of A Webpage
+/reverse - Reverse search an image.
+/carbon - Make Carbon from code.
 #RTFM - Tell noobs to read the manual
 #RTFM - Tell noobs to read the manual
 """
 """
 
 
@@ -77,7 +79,9 @@ async def runs(_, message):
 async def getid(_, message):
 async def getid(_, message):
     if len(message.command) == 2:
     if len(message.command) == 2:
         try:
         try:
-            id = (await app.get_users(message.text.split(None, 1)[1].strip())).id
+            id = (
+                await app.get_users(message.text.split(None, 1)[1].strip())
+            ).id
         except Exception:
         except Exception:
             return await message.reply_text("No Such User")
             return await message.reply_text("No Such User")
         text = f"**ID:** `{id}`"
         text = f"**ID:** `{id}`"

+ 18 - 38
wbb/modules/reverse.py

@@ -4,21 +4,19 @@ from random import randint
 import aiofiles
 import aiofiles
 import aiohttp
 import aiohttp
 import requests
 import requests
+from asyncio import get_running_loop
 from bs4 import BeautifulSoup
 from bs4 import BeautifulSoup
 from pyrogram import filters
 from pyrogram import filters
 
 
-from wbb import SUDOERS, app
+from wbb import app
 from wbb.core.decorators.errors import capture_err
 from wbb.core.decorators.errors import capture_err
+from wbb.modules.nsfw import get_file_id_from_message
 
 
-__MODULE__ = "Reverse"
-__HELP__ = "/reverse  - Reverse search an image. [SUDOERS ONLY]"
 
 
 
 
 @app.on_message(filters.command("reverse"))
 @app.on_message(filters.command("reverse"))
 @capture_err
 @capture_err
 async def reverse_image_search(_, message):
 async def reverse_image_search(_, message):
-    if message.from_user.id not in SUDOERS:
-        return await message.reply_text("THIS FEATURE IS ONLY FOR SUDO USERS.")
     if not message.reply_to_message:
     if not message.reply_to_message:
         return await message.reply_text(
         return await message.reply_text(
             "Reply to a message to reverse search it."
             "Reply to a message to reverse search it."
@@ -34,37 +32,12 @@ async def reverse_image_search(_, message):
         return await message.reply_text(
         return await message.reply_text(
             "Reply to an image/document/sticker/animation to reverse search it."
             "Reply to an image/document/sticker/animation to reverse search it."
         )
         )
-    m = await message.reply_text("Searching")
-    if reply.document:
-        if int(reply.document.file_size) > 3145728:
-            return await m.edit("File too large")
-        mime_type = reply.document.mime_type
-        if mime_type != "image/png" and mime_type != "image/jpeg":
-            return await m.edit("Document Mimetype Invalid")
-        file_id = reply.document.file_id
-    if reply.sticker:
-        if reply.sticker.is_animated:
-            if not reply.sticker.thumbs:
-                return await m.edit("Sticker Has No Thumb")
-            file_id = reply.sticker.thumbs[0].file_id
-        else:
-            file_id = reply.sticker.file_id
-
-    if reply.photo:
-        file_id = reply.photo.file_id
-
-    if reply.animation:
-        if not reply.animation.thumbs:
-            return await m.edit(
-                "Gif Has No Thumbnail, so it cannot be reverse searched"
-            )
-        file_id = reply.animation.thumbs[0].file_id
-
-    if reply.video:
-        if not reply.video.thumbs:
-            return
-        file_id = reply.video.thumbs[0].file_id
+    m = await message.reply_text("Downloading")
+    file_id = await get_file_id_from_message(reply)
+    if not file_id:
+        return m.edit("Can't reverse that")
     image = await app.download_media(file_id, f"{randint(1000, 10000)}.jpg")
     image = await app.download_media(file_id, f"{randint(1000, 10000)}.jpg")
+    await m.edit("Uploading to google's server")
     async with aiofiles.open(image, "rb") as f:
     async with aiofiles.open(image, "rb") as f:
         if image:
         if image:
             search_url = "http://www.google.com/searchbyimage/upload"
             search_url = "http://www.google.com/searchbyimage/upload"
@@ -72,9 +45,12 @@ async def reverse_image_search(_, message):
                 "encoded_image": (image, await f.read()),
                 "encoded_image": (image, await f.read()),
                 "image_content": "",
                 "image_content": "",
             }
             }
-            response = requests.post(
-                search_url, files=multipart, allow_redirects=False
+            def post_non_blocking():
+                return requests.post(
+                    search_url, files=multipart, allow_redirects=False
             )
             )
+            loop = get_running_loop()
+            response = await loop.run_in_executor(None, post_non_blocking)
             location = response.headers.get("Location")
             location = response.headers.get("Location")
             os.remove(image)
             os.remove(image)
         else:
         else:
@@ -82,6 +58,7 @@ async def reverse_image_search(_, message):
     headers = {
     headers = {
         "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0"
         "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0"
     }
     }
+    await m.edit("Scraping query")
     async with aiohttp.ClientSession() as session:
     async with aiohttp.ClientSession() as session:
         async with session.get(location, headers=headers) as resp:
         async with session.get(location, headers=headers) as resp:
             soup = BeautifulSoup(await resp.text(), "html.parser")
             soup = BeautifulSoup(await resp.text(), "html.parser")
@@ -89,12 +66,15 @@ async def reverse_image_search(_, message):
     anchor_element = div.find("a")
     anchor_element = div.find("a")
     text = anchor_element.text
     text = anchor_element.text
     try:
     try:
+        await m.edit("Trying to send a photo")
         await app.send_photo(
         await app.send_photo(
             message.chat.id,
             message.chat.id,
             photo=f"https://webshot.amanoteam.com/print?q={location}",
             photo=f"https://webshot.amanoteam.com/print?q={location}",
-            caption=f"**Query** [{text}]({location})",
+            caption=f"**Result**: [{text}]({location})",
         )
         )
         await m.delete()
         await m.delete()
     except Exception:
     except Exception:
         text = f"**Result**: [Link]({location})"
         text = f"**Result**: [Link]({location})"
         await m.edit(text)
         await m.edit(text)
+
+

+ 24 - 22
wbb/modules/taglogger.py

@@ -68,27 +68,29 @@ async def sendLog(message: Message):
     & ~filters.edited,
     & ~filters.edited,
     group=taglog_group,
     group=taglog_group,
 )
 )
-@capture_err
 async def tagLoggerFunc(_, message: Message):
 async def tagLoggerFunc(_, message: Message):
-    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)
+    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
-    ):
-        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)
+    except Exception:
+        pass  # lol

+ 2 - 0
wbb/modules/trust.py

@@ -22,6 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 SOFTWARE.
 SOFTWARE.
 """
 """
 from asyncio import Lock
 from asyncio import Lock
+
 from pyrogram import filters
 from pyrogram import filters
 from pyrogram.types import Message
 from pyrogram.types import Message
 
 
@@ -34,6 +35,7 @@ spam_db = {}
 
 
 lock_access = Lock()
 lock_access = Lock()
 
 
+
 async def get_spam_data(message: Message, text: str):
 async def get_spam_data(message: Message, text: str):
     async with lock_access:
     async with lock_access:
         c, m = message.chat.id, message.message_id
         c, m = message.chat.id, message.message_id

+ 9 - 3
wbb/modules/userbot.py

@@ -18,14 +18,14 @@ import aiofiles
 from pyrogram import filters
 from pyrogram import filters
 from pyrogram.types import Message
 from pyrogram.types import Message
 
 
+from wbb import app  # don't remove
 from wbb import SUDOERS, USERBOT_PREFIX, app2, arq
 from wbb import SUDOERS, USERBOT_PREFIX, app2, arq
-from wbb import app # don't remove
 from wbb.core.decorators.misc import exec_time
 from wbb.core.decorators.misc import exec_time
 
 
 __MODULE__ = "Userbot"
 __MODULE__ = "Userbot"
 __HELP__ = """
 __HELP__ = """
 .alive - Send Alive Message.
 .alive - Send Alive Message.
-.l - Execute Python Code.
+.py - Execute Python Code.
 .sh - Execute Shell Code.
 .sh - Execute Shell Code.
 .approve | .disapprove - Approve Or Disapprove A User To PM You.
 .approve | .disapprove - Approve Or Disapprove A User To PM You.
 .block | .unblock - Block Or Unblock A User.
 .block | .unblock - Block Or Unblock A User.
@@ -58,7 +58,8 @@ async def edit_or_reply(msg: Message, **kwargs):
     filters.user(SUDOERS)
     filters.user(SUDOERS)
     & ~filters.forwarded
     & ~filters.forwarded
     & ~filters.via_bot
     & ~filters.via_bot
-    & filters.command("l", prefixes=USERBOT_PREFIX)
+    & ~filters.edited
+    & filters.command("py", prefixes=USERBOT_PREFIX)
 )
 )
 async def executor(client, message: Message):
 async def executor(client, message: Message):
     global m, p, r
     global m, p, r
@@ -112,6 +113,7 @@ async def executor(client, message: Message):
     filters.user(SUDOERS)
     filters.user(SUDOERS)
     & ~filters.forwarded
     & ~filters.forwarded
     & ~filters.via_bot
     & ~filters.via_bot
+    & ~filters.edited
     & filters.command("sh", prefixes=USERBOT_PREFIX),
     & filters.command("sh", prefixes=USERBOT_PREFIX),
 )
 )
 async def shellrunner(client, message: Message):
 async def shellrunner(client, message: Message):
@@ -198,9 +200,13 @@ async def sendFile(message: Message, text: str):
 
 
 @app2.on_message(
 @app2.on_message(
     filters.command(["c", "cpp"], prefixes=USERBOT_PREFIX)
     filters.command(["c", "cpp"], prefixes=USERBOT_PREFIX)
+    & ~filters.edited
+    & ~filters.via_bot
     & filters.user(SUDOERS)
     & filters.user(SUDOERS)
 )
 )
 async def c_cpp_eval(_, message: Message):
 async def c_cpp_eval(_, message: Message):
+    if len(message.command) < 2:
+        return await message.edit("Write Some Code..")
     code = message.text.split(None, 1)[1]
     code = message.text.split(None, 1)[1]
     file = "exec.c"
     file = "exec.c"
     compiler = "g++"
     compiler = "g++"

+ 6 - 3
wbb/utils/dbfunctions.py

@@ -746,6 +746,9 @@ async def update_trust_db(user_id: int, new_data: float):
     if len(data) >= 1000:
     if len(data) >= 1000:
         data.remove(data[0])
         data.remove(data[0])
     data.append(new_data)
     data.append(new_data)
-    await trustdb.update_one(
-        {"user_id": user_id}, {"$set": {"data": data}}, upsert=True
-    )
+    try:
+        await trustdb.update_one(
+            {"user_id": user_id}, {"$set": {"data": data}}, upsert=True
+        )
+    except Exception:
+        pass # to prevent stack overflow error