diff --git a/bot.py b/bot.py index 7246b0c..e7f9620 100644 --- a/bot.py +++ b/bot.py @@ -1,61 +1,29 @@ # (c) @RknDeveloperr # Rkn Developer # Don't Remove Credit 😔 -# Telegram Channel @RknDeveloper & @Rkn_Botz -# Developer @RknDeveloperr -# Special Thanks To @ReshamOwner -# Update Channel @Digital_Botz & @DigitalBotz_Support -""" -Apache License 2.0 -Copyright (c) 2022 @Digital_Botz - -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. - -Telegram Link : https://t.me/Digital_Botz -Repo Link : https://github.com/DigitalBotz/Digital-Rename-Bot -License Link : https://github.com/DigitalBotz/Digital-Rename-Bot/blob/main/LICENSE -""" - -# extra imports + import aiohttp, asyncio, warnings, pytz, datetime import logging -import logging.config import glob, sys import importlib.util from pathlib import Path -# pyrogram imports -from pyrogram import Client, __version__, errors +from pyrogram import Client, __version__, errors, idle from pyrogram.raw.all import layer -from pyrogram import idle -# bots imports from config import Config from plugins.web_support import web_server from plugins.file_rename import app -# Get logging configurations +# Logging logging.basicConfig( - level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", - handlers=[logging.FileHandler('BotLog.txt'), - logging.StreamHandler()] + level=logging.INFO, + format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", + handlers=[logging.FileHandler('BotLog.txt'), logging.StreamHandler()] ) -#logger = logging.getLogger(__name__) logging.getLogger("pyrofork").setLevel(logging.WARNING) + class DigitalRenameBot(Client): def __init__(self): super().__init__( @@ -63,110 +31,107 @@ def __init__(self): api_id=Config.API_ID, api_hash=Config.API_HASH, bot_token=Config.BOT_TOKEN, + + # 🔥🔥🔥 LOCAL BOT API (MAIN FIX) + base_url=Config.BOT_API_URL, + workers=200, plugins={"root": "plugins"}, sleep_threshold=5, max_concurrent_transmissions=50 ) - - + async def start(self): await super().start() me = await self.get_me() + self.mention = me.mention - self.username = me.username + self.username = me.username self.uptime = Config.BOT_UPTIME self.premium = Config.PREMIUM_MODE self.uploadlimit = Config.UPLOAD_LIMIT_MODE Config.BOT = self - - app = aiohttp.web.AppRunner(await web_server()) - await app.setup() - bind_address = "0.0.0.0" - await aiohttp.web.TCPSite(app, bind_address, Config.PORT).start() - - path = "plugins/*.py" - files = glob.glob(path) - for name in files: - with open(name) as a: - patt = Path(a.name) - plugin_name = patt.stem.replace(".py", "") - plugins_path = Path(f"plugins/{plugin_name}.py") - import_path = "plugins.{}".format(plugin_name) - spec = importlib.util.spec_from_file_location(import_path, plugins_path) - load = importlib.util.module_from_spec(spec) - spec.loader.exec_module(load) - sys.modules["plugins" + plugin_name] = load - print("Digital Botz Imported " + plugin_name) - - print(f"{me.first_name} Iꜱ Sᴛᴀʀᴛᴇᴅ.....✨️") - - - for id in Config.ADMIN: - if Config.STRING_SESSION: - try: await self.send_message(id, f"𝟮𝗚𝗕+ ғɪʟᴇ sᴜᴘᴘᴏʀᴛ ʜᴀs ʙᴇᴇɴ ᴀᴅᴅᴇᴅ ᴛᴏ ʏᴏᴜʀ ʙᴏᴛ.\n\nNote: 𝐓𝐞𝐥𝐞𝐠𝐫𝐚𝐦 𝐩𝐫𝐞𝐦𝐢𝐮𝐦 𝐚𝐜𝐜𝐨𝐮𝐧𝐭 𝐬𝐭𝐫𝐢𝐧𝐠 𝐬𝐞𝐬𝐬𝐢𝐨𝐧 𝐫𝐞𝐪𝐮𝐢𝐫𝐞𝐝 𝐓𝐡𝐞𝐧 𝐬𝐮𝐩𝐩𝐨𝐫𝐭𝐬 𝟐𝐆𝐁+ 𝐟𝐢𝐥𝐞𝐬.\n\n**__{me.first_name} Iꜱ Sᴛᴀʀᴛᴇᴅ.....✨️__**") - except: pass - else: - try: await self.send_message(id, f"𝟮𝗚𝗕- ғɪʟᴇ sᴜᴘᴘᴏʀᴛ ʜᴀs ʙᴇᴇɴ ᴀᴅᴅᴇᴅ ᴛᴏ ʏᴏᴜʀ ʙᴏᴛ.\n\n**__{me.first_name} Iꜱ Sᴛᴀʀᴛᴇᴅ.....✨️__**") - except: pass - + + runner = aiohttp.web.AppRunner(await web_server()) + await runner.setup() + await aiohttp.web.TCPSite(runner, "0.0.0.0", Config.PORT).start() + + for file in glob.glob("plugins/*.py"): + plugin_name = Path(file).stem + spec = importlib.util.spec_from_file_location( + f"plugins.{plugin_name}", file + ) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + sys.modules[f"plugins.{plugin_name}"] = module + print(f"Loaded Plugin: {plugin_name}") + + print(f"{me.first_name} Bot Started Successfully ✅") + + for admin in Config.ADMIN: + try: + if Config.STRING_SESSION: + await self.send_message( + admin, + "✅ Local Bot API + STRING_SESSION ENABLED\n" + "🚀 2GB+ / 4GB+ file support ACTIVE" + ) + else: + await self.send_message( + admin, + "✅ Local Bot API ENABLED\n" + "🚀 2GB+ file support ACTIVE" + ) + except: + pass + if Config.LOG_CHANNEL: try: - curr = datetime.datetime.now(pytz.timezone("Asia/Kolkata")) - date = curr.strftime('%d %B, %Y') - time = curr.strftime('%I:%M:%S %p') - await self.send_message(Config.LOG_CHANNEL, f"**__{me.mention} Iꜱ Rᴇsᴛᴀʀᴛᴇᴅ !!**\n\n📅 Dᴀᴛᴇ : `{date}`\n⏰ Tɪᴍᴇ : `{time}`\n🌐 Tɪᴍᴇᴢᴏɴᴇ : `Asia/Kolkata`\n\n🉐 Vᴇʀsɪᴏɴ : `v{__version__} (Layer {layer})`") + now = datetime.datetime.now(pytz.timezone("Asia/Kolkata")) + await self.send_message( + Config.LOG_CHANNEL, + f"🤖 {me.mention} Restarted\n" + f"📅 {now.strftime('%d %B %Y')}\n" + f"⏰ {now.strftime('%I:%M:%S %p')}\n" + f"🧩 Pyrogram v{__version__} (Layer {layer})" + ) except: - print("Pʟᴇᴀꜱᴇ Mᴀᴋᴇ Tʜɪꜱ Iꜱ Aᴅᴍɪɴ Iɴ Yᴏᴜʀ Lᴏɢ Cʜᴀɴɴᴇʟ") + pass async def stop(self, *args): - for id in Config.ADMIN: - try: await self.send_message(id, f"**Bot Stopped....**") - except: pass - - print("Bot Stopped 🙄") + for admin in Config.ADMIN: + try: + await self.send_message(admin, "🛑 Bot Stopped") + except: + pass await super().stop() digital_instance = DigitalRenameBot() + def main(): - async def start_services(): + async def runner(): if Config.STRING_SESSION: await asyncio.gather(app.start(), digital_instance.start()) else: - await asyncio.gather(digital_instance.start()) - - # Idle mode start karo + await digital_instance.start() + await idle() - - # Bot stop karo + if Config.STRING_SESSION: await asyncio.gather(app.stop(), digital_instance.stop()) else: - await asyncio.gather(digital_instance.stop()) + await digital_instance.stop() loop = asyncio.get_event_loop() - try: - loop.run_until_complete(start_services()) - except KeyboardInterrupt: - print("\n🛑 Bot stopped by user!") - finally: - loop.close() + loop.run_until_complete(runner()) + if __name__ == "__main__": - warnings.filterwarnings("ignore", message="There is no current event loop") + warnings.filterwarnings("ignore") try: main() - except errors.FloodWait as ft: - print(f"⏳ FloodWait: Sleeping for {ft.value} seconds") - asyncio.run(asyncio.sleep(ft.value)) - print("Now Ready For Deploying!") + except errors.FloodWait as e: + asyncio.run(asyncio.sleep(e.value)) main() - - -# Rkn Developer -# Don't Remove Credit 😔 -# Telegram Channel @RknDeveloper & @Rkn_Botz -# Developer @RknDeveloperr -# Update Channel @Digital_Botz & @DigitalBotz_Support