Spaces:
Paused
Paused
Update bot.py
Browse files
bot.py
CHANGED
|
@@ -49,10 +49,16 @@ loop = asyncio.get_event_loop()
|
|
| 49 |
|
| 50 |
async def Lazy_start():
|
| 51 |
print('\n')
|
| 52 |
-
print('
|
|
|
|
|
|
|
| 53 |
bot_info = await LazyPrincessBot.get_me()
|
| 54 |
LazyPrincessBot.username = bot_info.username
|
|
|
|
|
|
|
| 55 |
await initialize_clients()
|
|
|
|
|
|
|
| 56 |
for name in files:
|
| 57 |
with open(name) as a:
|
| 58 |
patt = Path(a.name)
|
|
@@ -64,32 +70,56 @@ async def Lazy_start():
|
|
| 64 |
spec.loader.exec_module(load)
|
| 65 |
sys.modules["plugins." + plugin_name] = load
|
| 66 |
print("The Movie Provider Imported => " + plugin_name)
|
|
|
|
|
|
|
| 67 |
if ON_HEROKU:
|
| 68 |
asyncio.create_task(ping_server())
|
|
|
|
|
|
|
| 69 |
b_users, b_chats = await db.get_banned()
|
| 70 |
temp.BANNED_USERS = b_users
|
| 71 |
temp.BANNED_CHATS = b_chats
|
|
|
|
|
|
|
| 72 |
await Media.ensure_indexes()
|
|
|
|
|
|
|
| 73 |
me = await LazyPrincessBot.get_me()
|
| 74 |
temp.ME = me.id
|
| 75 |
temp.U_NAME = me.username
|
| 76 |
temp.B_NAME = me.first_name
|
| 77 |
LazyPrincessBot.username = '@' + me.username
|
| 78 |
-
|
|
|
|
|
|
|
| 79 |
logging.info(LOG_STR)
|
| 80 |
logging.info(script.LOGO)
|
|
|
|
|
|
|
| 81 |
tz = pytz.timezone('Asia/Kolkata')
|
| 82 |
today = date.today()
|
| 83 |
now = datetime.now(tz)
|
| 84 |
time = now.strftime("%H:%M:%S %p")
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
app = web.AppRunner(await web_server())
|
| 87 |
await app.setup()
|
| 88 |
bind_address = "0.0.0.0"
|
| 89 |
await web.TCPSite(app, bind_address, PORT).start()
|
|
|
|
|
|
|
| 90 |
await idle()
|
| 91 |
|
| 92 |
|
|
|
|
| 93 |
if __name__ == '__main__':
|
| 94 |
try:
|
| 95 |
loop.run_until_complete(Lazy_start())
|
|
|
|
| 49 |
|
| 50 |
async def Lazy_start():
|
| 51 |
print('\n')
|
| 52 |
+
print('Initializing The Movie Provider Bot')
|
| 53 |
+
|
| 54 |
+
# Get bot info
|
| 55 |
bot_info = await LazyPrincessBot.get_me()
|
| 56 |
LazyPrincessBot.username = bot_info.username
|
| 57 |
+
|
| 58 |
+
# Start other clients
|
| 59 |
await initialize_clients()
|
| 60 |
+
|
| 61 |
+
# Load plugins
|
| 62 |
for name in files:
|
| 63 |
with open(name) as a:
|
| 64 |
patt = Path(a.name)
|
|
|
|
| 70 |
spec.loader.exec_module(load)
|
| 71 |
sys.modules["plugins." + plugin_name] = load
|
| 72 |
print("The Movie Provider Imported => " + plugin_name)
|
| 73 |
+
|
| 74 |
+
# Ping if on Heroku
|
| 75 |
if ON_HEROKU:
|
| 76 |
asyncio.create_task(ping_server())
|
| 77 |
+
|
| 78 |
+
# Load banned users/chats
|
| 79 |
b_users, b_chats = await db.get_banned()
|
| 80 |
temp.BANNED_USERS = b_users
|
| 81 |
temp.BANNED_CHATS = b_chats
|
| 82 |
+
|
| 83 |
+
# Ensure DB indexes
|
| 84 |
await Media.ensure_indexes()
|
| 85 |
+
|
| 86 |
+
# Re-fetch bot info for display
|
| 87 |
me = await LazyPrincessBot.get_me()
|
| 88 |
temp.ME = me.id
|
| 89 |
temp.U_NAME = me.username
|
| 90 |
temp.B_NAME = me.first_name
|
| 91 |
LazyPrincessBot.username = '@' + me.username
|
| 92 |
+
|
| 93 |
+
# Logging info
|
| 94 |
+
logging.info(f"{me.first_name} with Pyrogram v{__version__} (Layer {layer}) started on @{me.username}.")
|
| 95 |
logging.info(LOG_STR)
|
| 96 |
logging.info(script.LOGO)
|
| 97 |
+
|
| 98 |
+
# Get current time
|
| 99 |
tz = pytz.timezone('Asia/Kolkata')
|
| 100 |
today = date.today()
|
| 101 |
now = datetime.now(tz)
|
| 102 |
time = now.strftime("%H:%M:%S %p")
|
| 103 |
+
|
| 104 |
+
# Try sending restart message to log channel
|
| 105 |
+
try:
|
| 106 |
+
chat = await LazyPrincessBot.get_chat(LOG_CHANNEL)
|
| 107 |
+
await LazyPrincessBot.send_message(chat_id=LOG_CHANNEL, text=script.RESTART_TXT.format(today, time))
|
| 108 |
+
logging.info(f"[LOG] Sent restart message to {chat.title} ({chat.id})")
|
| 109 |
+
except Exception as e:
|
| 110 |
+
logging.warning(f"[LOG WARNING] Could not send message to LOG_CHANNEL: {e}")
|
| 111 |
+
|
| 112 |
+
# Start aiohttp web server
|
| 113 |
app = web.AppRunner(await web_server())
|
| 114 |
await app.setup()
|
| 115 |
bind_address = "0.0.0.0"
|
| 116 |
await web.TCPSite(app, bind_address, PORT).start()
|
| 117 |
+
|
| 118 |
+
# Idle wait (Pyrogram)
|
| 119 |
await idle()
|
| 120 |
|
| 121 |
|
| 122 |
+
|
| 123 |
if __name__ == '__main__':
|
| 124 |
try:
|
| 125 |
loop.run_until_complete(Lazy_start())
|