11# This file is a part of TG-FileStreamBot
22# Coding : Jyothis Jayanth [@EverythingSuckz]
33
4+ import sys
45import asyncio
56import logging
67from .vars import Var
78from aiohttp import web
89from pyrogram import idle
910from WebStreamer import utils
10- from WebStreamer import bot_info
11+ from WebStreamer import StreamBot
1112from WebStreamer .server import web_server
1213from WebStreamer .bot .clients import initialize_clients
1314
1415
1516logging .basicConfig (
1617 level = logging .INFO , format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
1718)
18- logging .getLogger ("pyrogram" ).setLevel (logging .ERROR )
1919logging .getLogger ("aiohttp" ).setLevel (logging .ERROR )
20+ logging .getLogger ("pyrogram" ).setLevel (logging .ERROR )
2021logging .getLogger ("aiohttp.web" ).setLevel (logging .ERROR )
2122
22- loop = asyncio . get_event_loop ( )
23+ server = web . AppRunner ( web_server () )
2324
25+ loop = asyncio .get_event_loop ()
2426
2527async def start_services ():
26- print ("----------------------------- DONE -----------------------------" )
28+ print ()
29+ print ("-------------------- Initializing Telegram Bot --------------------" )
30+ await StreamBot .start ()
31+ bot_info = await StreamBot .get_me ()
32+ StreamBot .username = bot_info .username
33+ print ("------------------------------ DONE ------------------------------" )
2734 print ()
2835 print (
29- "----------------------------- Initializing Clients ------- ----------------------"
36+ "---------------------- Initializing Clients ----------------------"
3037 )
3138 await initialize_clients ()
32- print ("----------------------------- DONE -----------------------------" )
39+ print ("------------------------------ DONE - -----------------------------" )
3340 if Var .ON_HEROKU :
3441 print ("------------------ Starting Keep Alive Service ------------------" )
3542 print ()
3643 asyncio .create_task (utils .ping_server ())
37- print ("-------------------- Initalizing Web Server --------------------" )
38- app = web .AppRunner (await web_server ())
39- await app .setup ()
44+ print ("--------------------- Initalizing Web Server ---------------------" )
45+ await server .setup ()
4046 bind_address = "0.0.0.0" if Var .ON_HEROKU else Var .BIND_ADDRESS
41- await web .TCPSite (app , bind_address , Var .PORT ).start ()
42- print ("----------------------------- DONE -----------------------------" )
47+ await web .TCPSite (server , bind_address , Var .PORT ).start ()
48+ print ("------------------------------ DONE - -----------------------------" )
4349 print ()
44- print ("----------------------- Service Started -----------------------" )
50+ print ("------------------------- Service Started -- -----------------------" )
4551 print (" bot =>> {}" .format (bot_info .first_name ))
4652 if bot_info .dc_id :
4753 print (" DC ID =>> {}" .format (str (bot_info .dc_id )))
4854 print (" server ip =>> {}" .format (bind_address , Var .PORT ))
4955 if Var .ON_HEROKU :
5056 print (" app running on =>> {}" .format (Var .FQDN ))
51- print ("---------------------------------------------------------------" )
57+ print ("------------------------------------------------------------------ " )
5258 await idle ()
5359
60+ async def cleanup ():
61+ await server .cleanup ()
62+ await StreamBot .stop ()
5463
5564if __name__ == "__main__" :
5665 try :
5766 loop .run_until_complete (start_services ())
5867 except KeyboardInterrupt :
59- logging .info ("----------------------- Service Stopped -----------------------" )
68+ pass
69+ except Exception as err :
70+ logging .error (err .with_traceback (None ))
71+ finally :
72+ loop .run_until_complete (cleanup ())
73+ loop .stop ()
74+ print ("------------------------ Stopped Services ------------------------" )
0 commit comments