TheHamkerCat %!s(int64=5) %!d(string=hai) anos
pai
achega
91d4c39cd1

+ 0 - 1
requirements.txt

@@ -1,6 +1,5 @@
 ffmpeg-python
 gTTS
-spamwatch
 carbonnow
 aiohttp
 aiofiles

+ 44 - 18
wbb/__init__.py

@@ -22,15 +22,15 @@ 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 pyrogram import Client
-from pyromod import listen
-import aiohttp
-from motor.motor_asyncio import AsyncIOMotorClient as MongoClient
-from Python_ARQ import ARQ
-from telegraph import Telegraph
-from os import path
 import time
-import spamwatch as spamwatch_
+from os import path
+from telegraph import Telegraph
+from Python_ARQ import ARQ
+from motor.motor_asyncio import AsyncIOMotorClient as MongoClient
+import asyncio
+from pyromod import listen
+from pyrogram import Client
+print("[INFO]: INITIALIZING")
 is_config = path.exists('config.py')
 if is_config:
     from config import *
@@ -39,9 +39,8 @@ else:
 
 listen = listen
 USERBOT_PREFIX = USERBOT_PREFIX
-SPAMWATCH_API_KEY = SPAMWATCH_API_KEY
-SUDOERS = SUDO_USERS_ID
 GBAN_LOG_GROUP_ID = GBAN_LOG_GROUP_ID
+SUDOERS = SUDO_USERS_ID
 FERNET_ENCRYPTION_KEY = FERNET_ENCRYPTION_KEY
 WELCOME_DELAY_KICK_SEC = WELCOME_DELAY_KICK_SEC
 LOG_GROUP_ID = LOG_GROUP_ID
@@ -50,25 +49,48 @@ MOD_LOAD = []
 MOD_NOLOAD = []
 bot_start_time = time.time()
 
+# MongoDB client
+print("[INFO]: LOADING MONGODB")
+mongo_client = MongoClient(MONGO_DB_URI)
+db = mongo_client.wbb
+
+async def load_sudoers():
+    global SUDOERS
+    print("[INFO]: LOADING SUDOERS")
+    sudoersdb = db.sudoers
+    sudoers = await sudoersdb.find_one({"sudo": "sudo"})
+    sudoers = [] if not sudoers else sudoers['sudoers']
+    for user_id in SUDOERS:
+        if user_id not in sudoers:
+            sudoers.append(user_id)
+            await sudoersdb.update_one(
+                {"sudo": "sudo"},
+                {"$set": {"sudoers": sudoers}},
+                upsert=True
+            )
+    SUDOERS = (SUDOERS + sudoers) if sudoers else SUDOERS
+
+loop = asyncio.get_event_loop()
+loop.run_until_complete(load_sudoers())
 
 if not HEROKU:
-    app2 = Client("userbot", phone_number=PHONE_NUMBER, api_id=API_ID, api_hash=API_HASH)
+    print("[INFO]: LOADING USERBOT CLIENT")
+    app2 = Client("userbot", phone_number=PHONE_NUMBER,
+                  api_id=API_ID, api_hash=API_HASH)
 else:
+    print("[INFO]: LOADING USERBOT CLIENT")
     app2 = Client(SESSION_STRING, api_id=API_ID, api_hash=API_HASH)
 
 # Bot client
+print("[INFO]: LOADING BOT CLIENT")
 app = Client("wbb", bot_token=BOT_TOKEN, api_id=API_ID, api_hash=API_HASH)
-# MongoDB client
-mongo_client = MongoClient(MONGO_DB_URI)
-db = mongo_client.wbb
 # ARQ client
+print("[INFO]: LOADING ARQ")
 arq = ARQ(ARQ_API_BASE_URL)
 # Telegram client
+print("[INFO]: LOADING TELEGRAPH")
 telegraph = Telegraph()
 telegraph.create_account(short_name="wbb")
-session = aiohttp.ClientSession()
-# Spamwatch client
-spamwatch = spamwatch_.Client(SPAMWATCH_API_KEY)
 
 BOT_ID = 0
 BOT_NAME = ""
@@ -106,7 +128,11 @@ def get_info(app, app2):
     USERBOT_DC_ID = getme2.dc_id
 
 
+print("[INFO]: STARTING BOT CLIENT")
 app.start()
+print("[info]: starting userbot client")
 app2.start()
 get_info(app, app2)
-SUDOERS.append(USERBOT_ID)
+
+if USERBOT_ID not in SUDOERS:
+    SUDOERS.append(USERBOT_ID)

+ 2 - 2
wbb/__main__.py

@@ -67,8 +67,8 @@ async def start_bot():
     print("+===============+===============+===============+===============+")
     print(bot_modules)
     print("+===============+===============+===============+===============+")
-    print(f"BOT Started Successfully as {BOT_NAME}!")
-    print(f"USERBOT Started Successfully as {USERBOT_NAME}!")
+    print(f"[INFO]: BOT STARTED AS {BOT_NAME}!")
+    print(f"[INFO]: USERBOT STARTED AS {USERBOT_NAME}!")
     await idle()
 
 

+ 1 - 2
wbb/modules/alive.py

@@ -33,6 +33,5 @@ async def alive_command_func(_, message):
     await app2.send_inline_bot_result(
         message.chat.id,
         results.query_id,
-        results.results[0].id,
-        hide_via=True
+        results.results[0].id
     )

+ 7 - 6
wbb/modules/chatbot.py

@@ -26,6 +26,7 @@ from wbb import (
     USERBOT_USERNAME, USERBOT_PREFIX
 )
 from wbb.core.decorators.errors import capture_err
+from wbb.modules.userbot import edit_or_reply
 from wbb.utils.filter_groups import chatbot_group
 from pyrogram import filters
 
@@ -98,7 +99,7 @@ async def chatbot_talk(_, message):
 async def chatbot_status_ubot(_, message):
     global active_chats_ubot
     if len(message.text.split()) != 2:
-        await message.edit("**Usage**\n.chatbot [ON|OFF]")
+        await edit_or_reply(message, text="**Usage**\n.chatbot [ON|OFF]")
         return
     status = message.text.split(None, 1)[1]
     chat_id = message.chat.id
@@ -107,21 +108,21 @@ async def chatbot_status_ubot(_, message):
             active_chats_ubot.append(chat_id)
             text = "Chatbot Enabled Reply To Any Message " \
                    + "Of Mine To Get A Reply"
-            await message.edit(text)
+            await edit_or_reply(message, text=text)
             return
-        await message.edit("ChatBot Is Already Enabled.")
+        await edit_or_reply(message, text="ChatBot Is Already Enabled.")
         return
 
     elif status == "OFF" or status == "off" or status == "Off":
         if chat_id in active_chats_ubot:
             active_chats_ubot.remove(chat_id)
-            await message.edit("Chatbot Disabled!")
+            await edit_or_reply(message, text="Chatbot Disabled!")
             return
-        await message.edit("ChatBot Is Already Disabled.")
+        await edit_or_reply(message, text="ChatBot Is Already Disabled.")
         return
 
     else:
-        await message.edit("**Usage**\n/chatbot [ON|OFF]")
+        await edit_or_reply(message, text="**Usage**\n/chatbot [ON|OFF]")
 
 
 @app2.on_message(~filters.me & ~filters.private & filters.text & ~filters.edited, group=chatbot_group)

+ 1 - 3
wbb/modules/info.py

@@ -1,4 +1,4 @@
-from wbb import app, SUDOERS, spamwatch
+from wbb import app, SUDOERS
 from pyrogram import filters
 from pyrogram.types import Message
 from wbb.core.decorators.errors import capture_err
@@ -24,7 +24,6 @@ async def get_user_info(user):
     is_gbanned = await is_gbanned_user(user_id)
     is_sudo = user_id in SUDOERS
     karma = await user_global_karma(user_id)
-    banned_in_spamwatch = False if not spamwatch.get_ban(user_id) else True
     caption = f"""
 **ID:** `{user_id}`
 **DC:** {dc_id}
@@ -35,7 +34,6 @@ async def get_user_info(user):
 **Sudo:** {is_sudo}
 **Karma:** {karma}
 **Gbanned:** {is_gbanned}
-**Spamwatch Restricted:** {banned_in_spamwatch}
 """
     return [caption, photo_id]
 

+ 1 - 0
wbb/modules/pipes.py

@@ -58,6 +58,7 @@ pipes_list_userbot = []
 
 
 async def load_pipes():
+    print("[INFO]: LOADING PIPES")
     global pipes_list_bot, pipes_list_userbot
     pipes_list_bot = []
     pipes_list_userbot = []

+ 10 - 10
wbb/modules/pmpermit.py

@@ -61,14 +61,14 @@ async def pmpermit_func(_, message):
 @capture_err
 async def pm_approve(_, message):
     if not message.reply_to_message:
-        await message.edit("Reply to a user's message to approve.")
+        await edit_or_reply(message, text="Reply to a user's message to approve.")
         return
     user_id = message.reply_to_message.from_user.id
     if await is_pmpermit_approved(user_id):
-        await message.edit("User is already approved to pm")
+        await edit_or_reply(message, text="User is already approved to pm")
         return
     await approve_pmpermit(user_id)
-    m = await message.edit("User is approved to pm")
+    m = await edit_or_reply(message, text="User is approved to pm")
     await asyncio.sleep(2)
     await m.delete()
 
@@ -76,11 +76,11 @@ async def pm_approve(_, message):
 @app2.on_message(filters.command("disapprove", prefixes=USERBOT_PREFIX) & filters.user(SUDOERS) & ~filters.via_bot)
 async def pm_disapprove(_, message):
     if not message.reply_to_message:
-        await message.edit("Reply to a user's message to approve.")
+        await edit_or_reply(message, text="Reply to a user's message to approve.")
         return
     user_id = message.reply_to_message.from_user.id
     if not await is_pmpermit_approved(user_id):
-        await message.edit("User is already disapproved to pm")
+        await edit_or_reply(message, text="User is already disapproved to pm")
         async for m in app2.iter_history(user_id, limit=6):
             if m.reply_markup:
                 try:
@@ -89,28 +89,28 @@ async def pm_disapprove(_, message):
                     pass
         return
     await disapprove_pmpermit(user_id)
-    await message.edit("User is disapproved to pm")
+    await edit_or_reply(message, text="User is disapproved to pm")
 
 
 @app2.on_message(filters.command("block", prefixes=USERBOT_PREFIX) & filters.user(SUDOERS) & ~filters.via_bot)
 @capture_err
 async def block_user_func(_, message):
     if not message.reply_to_message:
-        await message.edit("Reply to a user's message to approve.")
+        await edit_or_reply(message, text="Reply to a user's message to block.")
         return
     user_id = message.reply_to_message.from_user.id
     await app2.block_user(user_id)
-    await message.edit("Successfully blocked the user")
+    await edit_or_reply(message, text="Successfully blocked the user")
 
 
 @app2.on_message(filters.command("unblock", prefixes=USERBOT_PREFIX) & filters.user(SUDOERS) & ~filters.via_bot)
 async def unblock_user_func(_, message):
     if not message.reply_to_message:
-        await message.edit("Reply to a user's message to approve.")
+        await edit_or_reply(message, text="Reply to a user's message to unblock.")
         return
     user_id = message.reply_to_message.from_user.id
     await app2.unblock_user(user_id)
-    await message.edit("Successfully Unblocked the user")
+    await edit_or_reply(message, text="Successfully Unblocked the user")
 
 
 """ CALLBACK QUERY HANDLER """

+ 91 - 0
wbb/modules/sudo.py

@@ -0,0 +1,91 @@
+"""
+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.
+"""
+from wbb import app2, SUDOERS, USERBOT_ID, BOT_ID, USERBOT_PREFIX
+from wbb.core.decorators.errors import capture_err
+from wbb.utils.dbfunctions import add_sudo, remove_sudo, get_sudoers
+from wbb.modules.userbot import edit_or_reply
+from pyrogram import filters
+from pyrogram.types import Message
+import asyncio
+
+__MODULE__ = "Sudo"
+__HELP__ = """
+**THIS MODULE IS ONLY FOR DEVS**
+
+.useradd - To Add A User In Sudoers.
+.userdel - To Remove A User From Sudoers.
+.sudoers - To List Sudo Users.
+
+**NOTE:**
+
+Never add anyone to sudoers unless you trust them,
+sudo users can do anything with your account, they
+can even delete your account.
+"""
+
+
+@app2.on_message(filters.command("useradd", prefixes=USERBOT_PREFIX) & filters.user(SUDOERS))
+async def useradd(_, message):
+    if not message.reply_to_message:
+        await edit_or_reply(message, text="Reply to someone's message to add him to sudoers.")
+        return
+    user_id = message.reply_to_message.from_user.id
+    sudoers = await get_sudoers()
+    if user_id in sudoers:
+        await edit_or_reply(message, text="User is already in sudoers.")
+        return
+    added = await add_sudo(user_id)
+    if added:
+        await edit_or_reply(message, text="Successfully added user in sudoers, Bot will be restarted now.")
+        os.execvp("python3", ["python3", "-m", "wbb"])
+        return
+    await edit_or_reply(message, text="Something wrong happened, check logs.")
+
+
+@app2.on_message(filters.command("userdel", prefixes=USERBOT_PREFIX) & filters.user(SUDOERS))
+async def userdel(_, message):
+    if not message.reply_to_message:
+        await edit_or_reply(message, text="Reply to someone's message to remove him to sudoers.")
+        return
+    user_id = message.reply_to_message.from_user.id
+    if user_id not in await get_sudoers():
+        await edit_or_reply(message, text="User is not in sudoers.")
+        return
+    removed = await remove_sudo(user_id)
+    if removed:
+        await edit_or_reply(message, text="Successfully removed user from sudoers, Bot will be restarted now.")
+        os.execvp("python3", ["python3", "-m", "wbb"])
+        return
+    await edit_or_reply(message, text="Something wrong happened, check logs.")
+
+
+@app2.on_message(filters.command("sudoers", prefixes=USERBOT_PREFIX) & filters.user(SUDOERS))
+async def sudoers_list(_, message):
+    sudoers = await get_sudoers()
+    text = ""
+    for count, user_id in enumerate(sudoers, 1):
+        user = await app2.get_users(user_id)
+        user = user.first_name if not user.mention else user.mention
+        text += f"{count}. {user}\n"
+    await edit_or_reply(message, text=text)

+ 43 - 1
wbb/utils/dbfunctions.py

@@ -40,6 +40,7 @@ nsfwdb = db.nsfw
 captcha_cachedb = db.captcha_cache
 blacklist_filtersdb = db.blaclist_filters
 pipesdb = db.pipes
+sudoersdb = db.sudoers
 
 """ Notes functions """
 
@@ -139,7 +140,7 @@ async def get_filters_count() -> dict:
 async def _get_filters(chat_id: int) -> Dict[str, int]:
     _filters = await filtersdb.find_one({"chat_id": chat_id})
     if not _filters:
-        return []
+        return {}
     return _filters['filters']
 
 
@@ -708,3 +709,44 @@ async def show_pipes() -> list:
     if not pipes:
         return []
     return pipes['pipes']
+
+
+""" SUDOERS FUNCTIONS """
+
+
+async def get_sudoers() -> list:
+    sudoers = await sudoersdb.find_one({"sudo": "sudo"})
+    if not sudoers:
+        return []
+    return sudoers['sudoers']
+
+
+async def add_sudo(user_id: int) -> bool:
+    sudoers = await get_sudoers()
+    sudoers.append(user_id)
+    await sudoersdb.update_one(
+        {"sudo": "sudo"},
+        {
+            "$set": {
+                "sudoers": sudoers
+            }
+        },
+        upsert=True
+    )
+    return True
+
+
+async def remove_sudo(user_id: int) -> bool:
+    sudoers = await get_sudoers()
+    sudoers.remove(user_id)
+    await sudoersdb.update_one(
+        {"sudo": "sudo"},
+        {
+            "$set": {
+                "sudoers": sudoers
+            }
+        },
+        upsert=True
+    )
+    return True
+