TheHamkerCat 5 лет назад
Родитель
Сommit
452ef501a4
5 измененных файлов с 29 добавлено и 121 удалено
  1. 20 73
      wbb/__init__.py
  2. 5 4
      wbb/__main__.py
  3. 1 2
      wbb/modules/__init__.py
  4. 0 41
      wbb/modules/log.py
  5. 3 1
      wbb/modules/userbot.py

+ 20 - 73
wbb/__init__.py

@@ -22,9 +22,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.
 """
 """
-print("[INFO]: INITIALIZING")
 import asyncio
 import asyncio
-import logging
 import time
 import time
 from inspect import getfullargspec
 from inspect import getfullargspec
 from os import path
 from os import path
@@ -36,22 +34,6 @@ from pyrogram.types import Message
 from pyromod import listen
 from pyromod import listen
 from Python_ARQ import ARQ
 from Python_ARQ import ARQ
 
 
-# Setup logging
-log_file = "error.log"
-
-with open(log_file, "w") as f:
-    f.write("PEAK OF LOG FILE")
-logging.basicConfig(
-    level=logging.ERROR,
-    format="[%(asctime)s.%(msecs)03d] %(filename)s:%(lineno)s %(levelname)s: %(message)s",
-    datefmt="%m-%d %H:%M",
-    filename=log_file,
-    filemode="w",
-)
-console = logging.StreamHandler()
-logging.getLogger("").addHandler(console)
-log = logging.getLogger()
-
 is_config = path.exists("config.py")
 is_config = path.exists("config.py")
 
 
 if is_config:
 if is_config:
@@ -97,7 +79,6 @@ loop = asyncio.get_event_loop()
 loop.run_until_complete(load_sudoers())
 loop.run_until_complete(load_sudoers())
 
 
 if not HEROKU:
 if not HEROKU:
-    print("[INFO]: INITIALIZING USERBOT CLIENT")
     app2 = Client(
     app2 = Client(
         "userbot",
         "userbot",
         phone_number=PHONE_NUMBER,
         phone_number=PHONE_NUMBER,
@@ -105,73 +86,39 @@ if not HEROKU:
         api_hash=API_HASH,
         api_hash=API_HASH,
     )
     )
 else:
 else:
-    print("[INFO]: INITIALIZING USERBOT CLIENT")
     app2 = Client(SESSION_STRING, api_id=API_ID, api_hash=API_HASH)
     app2 = Client(SESSION_STRING, api_id=API_ID, api_hash=API_HASH)
 
 
-# Aiohttp Client
-print("[INFO]: INITIALZING AIOHTTP SESSION")
 aiohttpsession = ClientSession()
 aiohttpsession = ClientSession()
-# ARQ Client
-print("[INFO]: INITIALIZING ARQ CLIENT")
+
 arq = ARQ(ARQ_API_URL, ARQ_API_KEY, aiohttpsession)
 arq = ARQ(ARQ_API_URL, ARQ_API_KEY, aiohttpsession)
-# Bot client
-print("[INFO]: INITIALIZING BOT CLIENT")
+
 app = Client(
 app = Client(
     "wbb", bot_token=BOT_TOKEN, api_id=API_ID, api_hash=API_HASH
     "wbb", bot_token=BOT_TOKEN, api_id=API_ID, api_hash=API_HASH
 )
 )
 
 
+print("[INFO]: STARTING BOT CLIENT")
+app.start()
+print("[INFO]: STARTING USERBOT CLIENT")
+app2.start()
 
 
-BOT_ID = 0
-BOT_NAME = ""
-BOT_USERNAME = ""
-BOT_MENTION = ""
-BOT_DC_ID = 0
-USERBOT_ID = 0
-USERBOT_NAME = ""
-USERBOT_USERNAME = ""
-USERBOT_DC_ID = 0
-USERBOT_MENTION = ""
-USERBOT_BOT_CHAT_COMMON = []
-
-
-def get_info(app, app2):
-    global BOT_ID, BOT_NAME, BOT_USERNAME, BOT_DC_ID, BOT_MENTION
-    global USERBOT_ID, USERBOT_NAME, USERBOT_USERNAME, USERBOT_DC_ID, USERBOT_MENTION
-    global USERBOT_BOT_CHAT_COMMON
-    getme = app.get_me()
-    getme2 = app2.get_me()
-    BOT_ID = getme.id
-    USERBOT_ID = getme2.id
-    BOT_NAME = (
-        f"{getme.first_name} {getme.last_name}"
-        if getme.last_name
-        else getme.first_name
-    )
-    BOT_USERNAME = getme.username
-    BOT_MENTION = getme.mention
-    BOT_DC_ID = getme.dc_id
-
-    USERBOT_NAME = (
-        f"{getme2.first_name} {getme2.last_name}"
-        if getme2.last_name
-        else getme2.first_name
-    )
-    USERBOT_USERNAME = getme2.username
-    USERBOT_MENTION = getme2.mention
-    USERBOT_DC_ID = getme2.dc_id
+print("[INFO]: GATHERING PROFILE INFO")
+x = app.get_me()
+y = app2.get_me()
 
 
+BOT_ID = x.id
+BOT_NAME = x.first_name + (x.last_name or "")
+BOT_USERNAME = x.username
+BOT_MENTION = x.mention
+BOT_DC_ID = x.dc_id
+
+USERBOT_ID = y.id
+USERBOT_NAME = y.first_name + (y.last_name or "")
+USERBOT_USERNAME = y.username
+USERBOT_MENTION = y.mention
+USERBOT_DC_ID = y.dc_id
 
 
-print("[INFO]: STARTING BOT CLIENT TEMPORARILY")
-app.start()
-print("[INFO]: STARTING USERBOT CLIENT TEMPORARILY")
-app2.start()
-print("[INFO]: LOADING UB/BOT PROFILE INFO")
-get_info(app, app2)
-print("[INFO]: LOADED UB/BOT PROFILE INFO")
 if USERBOT_ID not in SUDOERS:
 if USERBOT_ID not in SUDOERS:
     SUDOERS.append(USERBOT_ID)
     SUDOERS.append(USERBOT_ID)
-app.stop()
-app2.stop()
 
 
 
 
 async def eor(msg: Message, **kwargs):
 async def eor(msg: Message, **kwargs):

+ 5 - 4
wbb/__main__.py

@@ -42,10 +42,7 @@ HELPABLE = {}
 
 
 
 
 async def start_bot():
 async def start_bot():
-    print("[INFO]: STARTING BOT CLIENT")
-    await app.start()
-    print("[INFO]: STARTING USERBOT CLIENT")
-    await app2.start()
+
     for module in ALL_MODULES:
     for module in ALL_MODULES:
         imported_module = importlib.import_module(
         imported_module = importlib.import_module(
             "wbb.modules." + module
             "wbb.modules." + module
@@ -86,7 +83,9 @@ async def start_bot():
     )
     )
     print(f"[INFO]: BOT STARTED AS {BOT_NAME}!")
     print(f"[INFO]: BOT STARTED AS {BOT_NAME}!")
     print(f"[INFO]: USERBOT STARTED AS {USERBOT_NAME}!")
     print(f"[INFO]: USERBOT STARTED AS {USERBOT_NAME}!")
+
     restart_data = await clean_restart_stage()
     restart_data = await clean_restart_stage()
+
     try:
     try:
         print("[INFO]: SENDING ONLINE STATUS")
         print("[INFO]: SENDING ONLINE STATUS")
         if restart_data:
         if restart_data:
@@ -100,7 +99,9 @@ async def start_bot():
             await app.send_message(LOG_GROUP_ID, "Bot started!")
             await app.send_message(LOG_GROUP_ID, "Bot started!")
     except Exception:
     except Exception:
         pass
         pass
+
     await idle()
     await idle()
+
     print("[INFO]: STOPPING BOT AND CLOSING AIOHTTP SESSION")
     print("[INFO]: STOPPING BOT AND CLOSING AIOHTTP SESSION")
     await aiohttpsession.close()
     await aiohttpsession.close()
 
 

+ 1 - 2
wbb/modules/__init__.py

@@ -26,7 +26,7 @@ import importlib
 import sys
 import sys
 from os.path import basename, dirname, isfile
 from os.path import basename, dirname, isfile
 
 
-from wbb import MOD_LOAD, MOD_NOLOAD, log
+from wbb import MOD_LOAD, MOD_NOLOAD
 
 
 
 
 def __list_all_modules():
 def __list_all_modules():
@@ -49,7 +49,6 @@ def __list_all_modules():
                 any(mod == module_name for module_name in all_modules)
                 any(mod == module_name for module_name in all_modules)
                 for mod in to_load
                 for mod in to_load
             ):
             ):
-                log.error("Invalid Module name!")
                 sys.exit()
                 sys.exit()
 
 
         else:
         else:

+ 0 - 41
wbb/modules/log.py

@@ -1,41 +0,0 @@
-from datetime import datetime
-
-import aiofiles
-from pyrogram import filters
-from pyrogram.types import CallbackQuery, Message
-
-from wbb import SUDOERS, app, log_file
-from wbb.core.keyboard import ikb
-from wbb.utils.pastebin import paste
-
-callback = "log_paste"
-
-
-@app.on_message(filters.command("logs") & filters.user(SUDOERS))
-async def logs_chat(_, message):
-    keyboard = ikb({"📎   Pastebin   📎": callback})
-    time = (datetime.now()).strftime("%d/%m/%Y %H:%M:%S")
-    caption = f"""
-**Time:** `{time}`
-**Log Type:** `ERROR`
-"""
-    try:
-        await message.reply_document(
-            log_file, caption=caption, reply_markup=keyboard
-        )
-    except ValueError:
-        await message.reply_text("**LOGS ARE EMPTY**")
-
-
-@app.on_callback_query(filters.regex(callback))
-async def paste_log_neko(_, cq: CallbackQuery):
-    if cq.from_user.id not in SUDOERS:
-        return await cq.answer(
-            "Stop clicking at whichever thing you come across."
-        )
-    async with aiofiles.open(log_file, mode="r") as f:
-        link = await paste(await f.read())
-    message: Message = cq.message
-    return await message.edit_caption(
-        f"{message.caption.markdown}\n**Paste:** {link}"
-    )

+ 3 - 1
wbb/modules/userbot.py

@@ -149,7 +149,9 @@ async def executor(client, message: Message):
         else:
         else:
             return
             return
     if not status.from_user:
     if not status.from_user:
-        status = await app2.get_messages(status.chat.id, status.message_id)
+        status = await app2.get_messages(
+            status.chat.id, status.message_id
+        )
     await eor(status, text=final_output, quote=True)
     await eor(status, text=final_output, quote=True)