Ver Fonte

Some fixes

TheHamkerCat há 5 anos atrás
pai
commit
e0f2d48ee2

+ 54 - 1
README.md

@@ -81,6 +81,59 @@ $ sudo docker build . -t wbb
 $ sudo docker run wbb
 ```
 
+## Write new modules
+
+```py
+# Add license text here, get it from below
+
+from wbb import app # This is bot's client
+from wbb import app2 # userbot client, import it if module is related to userbot
+from pyrogram import filters # pyrogram filters
+...
+
+
+# For /help menu
+__MODULE__ = "Module Name"
+__HELP__ = "Module help message"
+
+
+@app.on_message(filters.command("start"))
+async def some_function(_, message):
+    await message.reply_text("I'm already up!!")
+
+# Many useful functions are in, wbb/utils/, wbb, and wbb/core/
+```
+
+And put that file in wbb/modules/, restart and test your bot.
+
+# LICENSE
+
+MIT
+
+```
+MIT License
+
+Copyright (c) 2021 TheHamkerCat
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+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.
+```
+
 ## Note
 
-1. Support Chat: https://t.me/wbbsupport
+1. Support Chat: [WbbSupport](https://t.me/wbbsupport)

+ 3 - 2
wbb/__init__.py

@@ -33,7 +33,6 @@ from motor.motor_asyncio import AsyncIOMotorClient as MongoClient
 from pyrogram import Client
 from Python_ARQ import ARQ
 
-
 # Setup logging
 log_file = "error.log"
 
@@ -152,7 +151,9 @@ def get_info(app, app2):
     USERBOT_MENTION = getme2.mention
     USERBOT_DC_ID = getme2.dc_id
 
-    USERBOT_BOT_CHAT_COMMON = [i.id for i in app2.get_common_chats(BOT_USERNAME)] + SPAM_CHECK_EXCEPTION_GROUPS
+    USERBOT_BOT_CHAT_COMMON = [
+        i.id for i in app2.get_common_chats(BOT_USERNAME)
+    ] + SPAM_CHECK_EXCEPTION_GROUPS
 
 
 print("[INFO]: STARTING BOT CLIENT")

+ 2 - 5
wbb/modules/admin.py

@@ -22,12 +22,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 SOFTWARE.
 """
 import asyncio
-from traceback import format_exc as err
 
 from pyrogram import filters
-from pyrogram.types import (CallbackQuery, ChatPermissions,
-                            InlineKeyboardButton, InlineKeyboardMarkup,
-                            Message)
+from pyrogram.types import CallbackQuery, ChatPermissions, Message
 
 from wbb import BOT_ID, SUDOERS, app
 from wbb.core.decorators.errors import capture_err
@@ -431,7 +428,7 @@ async def warn_user(_, message: Message):
         _, __, alpha = await asyncio.gather(
             message.chat.kick_member(user_id),
             message.reply_text(
-                "Number of warns of {mention} exceeded, BANNED!"
+                f"Number of warns of {mention} exceeded, BANNED!"
             ),
             int_to_alpha(user_id),
         )

+ 6 - 2
wbb/modules/admin_misc.py

@@ -53,9 +53,13 @@ async def set_chat_title(_, message):
 @adminsOnly("can_change_info")
 async def set_user_title(_, message):
     if not message.reply_to_message:
-        return await message.reply_text("Reply to user's message to set his admin title")
+        return await message.reply_text(
+            "Reply to user's message to set his admin title"
+        )
     if not message.reply_to_message.from_user:
-        return await message.reply_text("I can't change admin title of an unknown entity")
+        return await message.reply_text(
+            "I can't change admin title of an unknown entity"
+        )
     chat_id = message.chat.id
     from_user = message.reply_to_message.from_user
     if len(message.command) < 2:

+ 0 - 2
wbb/modules/carbon.py

@@ -1,5 +1,3 @@
-import os
-
 from pyrogram import filters
 
 from wbb import app

+ 17 - 9
wbb/modules/chatbot.py

@@ -21,7 +21,8 @@ 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.
 """
-from asyncio import sleep, gather
+from asyncio import gather, sleep
+
 from pyrogram import filters
 from pyrogram.types import Message
 
@@ -39,7 +40,8 @@ __HELP__ = """
 active_chats_bot = []
 active_chats_ubot = []
 
-async def chat_bot_toggle(db, message):
+
+async def chat_bot_toggle(db, message: Message):
     status = message.text.split(None, 1)[1].lower()
     chat_id = message.chat.id
     if status == "on":
@@ -59,21 +61,26 @@ async def chat_bot_toggle(db, message):
     else:
         await edit_or_reply(message, text="**Usage**\n/chatbot [ON|OFF]")
 
+
 # Enabled | Disable Chatbot
 
 
 @app.on_message(filters.command("chatbot") & ~filters.edited)
 @capture_err
-async def chatbot_status(_, message):
+async def chatbot_status(_, message: Message):
     if len(message.command) != 2:
-        return await edit_or_reply(message, text="**Usage**\n/chatbot [ON|OFF]")
+        return await edit_or_reply(
+            message, text="**Usage**\n/chatbot [ON|OFF]"
+        )
     await chat_bot_toggle(active_chats_bot, message)
 
+
 async def lunaQuery(query: str, user_id: int):
     luna = await arq.luna(query, user_id)
     return luna.result
 
-async def type_and_send(message):
+
+async def type_and_send(message: Message):
     chat_id = message.chat.id
     user_id = message.from_user.id if message.from_user else 0
     query = message.text.strip()
@@ -82,6 +89,7 @@ async def type_and_send(message):
     await message.reply_text(response)
     await message._client.send_chat_action(chat_id, "cancel")
 
+
 @app.on_message(
     filters.text
     & filters.reply
@@ -91,7 +99,7 @@ async def type_and_send(message):
     group=chatbot_group,
 )
 @capture_err
-async def chatbot_talk(_, message):
+async def chatbot_talk(_, message: Message):
     if message.chat.id not in active_chats_bot:
         return
     if not message.reply_to_message:
@@ -110,7 +118,7 @@ async def chatbot_talk(_, message):
     & filters.user(SUDOERS)
 )
 @capture_err
-async def chatbot_status_ubot(_, message):
+async def chatbot_status_ubot(_, message: Message):
     if len(message.text.split()) != 2:
         return await edit_or_reply(
             message, text="**Usage**\n.chatbot [ON|OFF]"
@@ -123,7 +131,7 @@ async def chatbot_status_ubot(_, message):
     group=chatbot_group,
 )
 @capture_err
-async def chatbot_talk_ubot(_, message):
+async def chatbot_talk_ubot(_, message: Message):
     if message.chat.id not in active_chats_ubot:
         return
     username = "@" + str(USERBOT_USERNAME)
@@ -146,7 +154,7 @@ async def chatbot_talk_ubot(_, message):
     group=(chatbot_group + 1),
 )
 @capture_err
-async def chatbot_talk_ubot_pm(_, message):
+async def chatbot_talk_ubot_pm(_, message: Message):
     if message.chat.id not in active_chats_ubot:
         return
     await type_and_send(message)

+ 0 - 7
wbb/modules/info.py

@@ -59,13 +59,6 @@ async def get_user_info(user):
         if spam_probab != 0
         else "Uncertain"
     )
-    isPotentialSpammer = (
-        True
-        if spam_probab > 40
-        else False
-        if spam_probab != 0
-        else "Uncertain"
-    )
     spam_probab = (
         str(round(spam_probab)) + " %" if spam_probab != 0 else "Uncertain"
     )

+ 6 - 1
wbb/modules/misc.py

@@ -76,7 +76,10 @@ async def runs(_, message):
 @app.on_message(filters.command("id"))
 async def getid(_, message):
     if len(message.command) == 2:
-        id = (await app.get_users(message.text.split(None, 1)[1])).id
+        try:
+            id = (await app.get_users(message.text.split(None, 1)[1].strip())).id
+        except Exception:
+            return await message.reply_text("No Such User")
         text = f"**ID:** `{id}`"
         return await message.reply_text(text, parse_mode="html")
     text_unping = "<b>Chat ID:</b>"
@@ -151,6 +154,7 @@ async def random(_, message):
             "Strings Won't Work!, Pass A Positive Integer Less Than 1000"
         )
 
+
 # Encrypt
 
 
@@ -217,6 +221,7 @@ async def cheat(_, message):
         await m.edit(str(e))
         print(str(e))
 
+
 # Translate
 
 

+ 1 - 1
wbb/modules/paste.py

@@ -37,7 +37,7 @@ from wbb.utils.pastebin import paste
 
 __MODULE__ = "Paste"
 __HELP__ = "/paste - To Paste Replied Text Or Document To Nekobin"
-pattern = re.compile(r'^text/|json$|yaml$|xml$|toml$')
+pattern = re.compile(r"^text/|json$|yaml$|xml$|toml$")
 
 
 async def isPreviewUp(preview: str) -> bool:

+ 4 - 3
wbb/modules/spam.py

@@ -25,8 +25,7 @@ from pyrogram import filters
 from pyrogram.types import (CallbackQuery, InlineKeyboardButton,
                             InlineKeyboardMarkup, Message)
 
-from wbb import LOG_GROUP_ID, SUDOERS, app, arq
-from wbb.core.decorators.errors import capture_err
+from wbb import LOG_GROUP_ID, SUDOERS, app
 from wbb.modules.admin import list_admins, member_permissions
 from wbb.modules.trust import get_spam_data
 from wbb.utils.filter_groups import spam_protection_group
@@ -42,7 +41,7 @@ __HELP__ = """
 
 **Commands:**
     - /spam
-        To mark a message as spam, this will help devs to 
+        To mark a message as spam, this will help devs to
         improve spam protection algorithm.
 
 As of now, you cannot turn this off, but we'll add an enable/disable command in the future
@@ -64,6 +63,8 @@ async def spam_protection_func(_, message: Message):
     if user.id in SUDOERS:
         return
     data = await get_spam_data(message, text)
+    if isinstance(data, str):
+        return
     if not data.is_spam:
         return
     if user.id in (await list_admins(chat_id)):

+ 10 - 4
wbb/modules/sudoers.py

@@ -28,6 +28,7 @@ import time
 
 import psutil
 from pyrogram import filters
+from pyrogram.errors import FloodWait
 
 from wbb import (BOT_ID, GBAN_LOG_GROUP_ID, SUDOERS, USERBOT_USERNAME, app,
                  bot_start_time)
@@ -279,19 +280,24 @@ async def unban_globally(_, message):
 async def broadcast_message(_, message):
     if len(message.command) < 2:
         return await message.reply_text("**Usage**:\n/broadcast [MESSAGE]")
+    sleep_time = 3
     text = message.text.split(None, 1)[1]
     sent = 0
-    chats = []
     schats = await get_served_chats()
-    for chat in schats:
-        chats.append(int(chat["chat_id"]))
+    chats = [int(chat["chat_id"]) for chat in schats]
+    m = await message.reply_text(
+        f"Broadcast in progress, will take {len(chats) * sleep_time} seconds."
+    )
     for i in chats:
         try:
             await app.send_message(i, text=text)
+            await asyncio.sleep(sleep_time)
             sent += 1
+        except FloodWait as e:
+            await asyncio.sleep(int(e.x))
         except Exception:
             pass
-    await message.reply_text(f"**Broadcasted Message In {sent} Chats.**")
+    await m.edit(f"**Broadcasted Message In {sent} Chats.**")
 
 
 # Update

+ 6 - 1
wbb/modules/taglogger.py

@@ -53,7 +53,12 @@ async def sendLog(message: Message):
 """
     button = InlineKeyboard(row_width=1)
     button.add(InlineKeyboardButton(text="Check Action", url=message.link))
-    await app.send_message(LOG_GROUP_ID, text=msg, reply_markup=button, disable_web_page_preview=True)
+    await app.send_message(
+        LOG_GROUP_ID,
+        text=msg,
+        reply_markup=button,
+        disable_web_page_preview=True,
+    )
 
 
 @app2.on_message(

+ 4 - 4
wbb/modules/trust.py

@@ -21,13 +21,11 @@ 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.
 """
-from asyncio import sleep
-
 from pyrogram import filters
 from pyrogram.types import Message
 
-from wbb import (BOT_ID, MESSAGE_DUMP_CHAT, USERBOT_BOT_CHAT_COMMON, app,
-                 app2, arq)
+from wbb import (BOT_ID, MESSAGE_DUMP_CHAT, USERBOT_BOT_CHAT_COMMON, app, app2,
+                 arq)
 from wbb.utils.dbfunctions import get_trust_db, update_trust_db
 from wbb.utils.filter_groups import trust_group
 
@@ -73,6 +71,8 @@ async def trust_watcher_func(_, message: Message):
     if len(text) < 2:
         return
     data = await get_spam_data(message, text)
+    if isinstance(data, str):
+        return
     spam = data.spam
     await update_trust_db(user_id, spam)
 

+ 1 - 0
wbb/modules/tts.py

@@ -35,6 +35,7 @@ from wbb import app
 __MODULE__ = "TTS"
 __HELP__ = "/tts - Convert Text To Speech."
 
+
 def convert(text):
     audio = BytesIO()
     i = Translator().translate(text, dest="en")

+ 3 - 3
wbb/modules/userbot.py

@@ -18,7 +18,7 @@ import aiofiles
 from pyrogram import filters
 from pyrogram.types import Message
 
-from wbb import SUDOERS, USERBOT_PREFIX, app, app2, arq
+from wbb import SUDOERS, USERBOT_PREFIX, app2, arq
 from wbb.core.decorators.misc import exec_time
 
 __MODULE__ = "Userbot"
@@ -166,11 +166,11 @@ async def shellrunner(client, message: Message):
         if len(output) > 4096:
             with open("output.txt", "w+") as file:
                 file.write(output)
-            await app.send_document(
+            await app2.send_document(
                 message.chat.id,
                 "output.txt",
                 reply_to_message_id=message.message_id,
-                caption="`Output`",
+                caption=escape(text),
             )
             return os.remove("output.txt")
         await edit_or_reply(

+ 21 - 0
wbb/modules/webss.py

@@ -27,4 +27,25 @@ from wbb import app
 from wbb.core.decorators.errors import capture_err
 
 __MODULE__ = "WebSS"
+__HELP__ = "/webss | .webss [URL] - Take A Screenshot Of A Webpage"
 
+
+@app.on_message(filters.command("webss"))
+@capture_err
+async def take_ss(_, message):
+    try:
+        if len(message.command) != 2:
+            return await message.reply_text("Give A Url To Fetch Screenshot.")
+        url = message.text.split(None, 1)[1]
+        m = await message.reply_text("**Taking Screenshot**")
+        await m.edit("**Uploading**")
+        try:
+            await app.send_photo(
+                message.chat.id,
+                photo=f"https://webshot.amanoteam.com/print?q={url}",
+            )
+        except TypeError:
+            return await m.edit("No Such Website.")
+        await m.delete()
+    except Exception as e:
+        await message.reply_text(str(e))