import sys import glob import importlib from pathlib import Path from pyrogram import idle import logging import logging.config # Get logging configurations logging.config.fileConfig('logging.conf') logging.getLogger().setLevel(logging.INFO) logging.getLogger("pyrogram").setLevel(logging.ERROR) logging.getLogger("imdbpy").setLevel(logging.ERROR) logging.basicConfig( level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s" ) logging.getLogger("aiohttp").setLevel(logging.ERROR) logging.getLogger("aiohttp.web").setLevel(logging.ERROR) from pyrogram import Client, __version__ from pyrogram.raw.all import layer from database.ia_filterdb import Media from database.users_chats_db import db from info import * from utils import temp from typing import Union, Optional, AsyncGenerator from pyrogram import types from Script import script from datetime import date, datetime import pytz from aiohttp import web from plugins import web_server import asyncio from pyrogram import idle from lazybot import LazyPrincessBot from util.keepalive import ping_server from lazybot.clients import initialize_clients ppath = "plugins/*.py" files = glob.glob(ppath) LazyPrincessBot.start() loop = asyncio.get_event_loop() async def Lazy_start(): print('\n') print('Initializing The Movie Provider Bot') # Get bot info bot_info = await LazyPrincessBot.get_me() LazyPrincessBot.username = bot_info.username # Start other clients await initialize_clients() # Load plugins for name in files: with open(name) as a: patt = Path(a.name) plugin_name = patt.stem.replace(".py", "") plugins_dir = Path(f"plugins/{plugin_name}.py") import_path = "plugins.{}".format(plugin_name) spec = importlib.util.spec_from_file_location(import_path, plugins_dir) load = importlib.util.module_from_spec(spec) spec.loader.exec_module(load) sys.modules["plugins." + plugin_name] = load print("The Movie Provider Imported => " + plugin_name) # Ping if on Heroku if ON_HEROKU: asyncio.create_task(ping_server()) # Load banned users/chats b_users, b_chats = await db.get_banned() temp.BANNED_USERS = b_users temp.BANNED_CHATS = b_chats # Ensure DB indexes await Media.ensure_indexes() # Re-fetch bot info for display me = await LazyPrincessBot.get_me() temp.ME = me.id temp.U_NAME = me.username temp.B_NAME = me.first_name LazyPrincessBot.username = '@' + me.username # Logging info logging.info(f"{me.first_name} with Pyrogram v{__version__} (Layer {layer}) started on @{me.username}.") logging.info(LOG_STR) logging.info(script.LOGO) # Get current time tz = pytz.timezone('Asia/Kolkata') today = date.today() now = datetime.now(tz) time = now.strftime("%H:%M:%S %p") # Try sending restart message to log channel try: chat = await LazyPrincessBot.get_chat(LOG_CHANNEL) await LazyPrincessBot.send_message(chat_id=LOG_CHANNEL, text=script.RESTART_TXT.format(today, time)) logging.info(f"[LOG] Sent restart message to {chat.title} ({chat.id})") except Exception as e: logging.warning(f"[LOG WARNING] Could not send message to LOG_CHANNEL: {e}") # Start aiohttp web server app = web.AppRunner(await web_server()) await app.setup() bind_address = "0.0.0.0" await web.TCPSite(app, bind_address, PORT).start() # Idle wait (Pyrogram) await idle() if __name__ == '__main__': try: loop.run_until_complete(Lazy_start()) except KeyboardInterrupt: logging.info('Service Stopped Bye 👋')