forked from EverythingSuckz/TG-FileStreamBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8cbc9cb
commit fe6ba2a
Showing
4 changed files
with
32 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,74 @@ | ||
# This file is a part of TG-FileStreamBot | ||
# Coding : Jyothis Jayanth [@EverythingSuckz] | ||
|
||
import sys | ||
import asyncio | ||
import logging | ||
from .vars import Var | ||
from aiohttp import web | ||
from pyrogram import idle | ||
from WebStreamer import utils | ||
from WebStreamer import bot_info | ||
from WebStreamer import StreamBot | ||
from WebStreamer.server import web_server | ||
from WebStreamer.bot.clients import initialize_clients | ||
|
||
|
||
logging.basicConfig( | ||
level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s" | ||
) | ||
logging.getLogger("pyrogram").setLevel(logging.ERROR) | ||
logging.getLogger("aiohttp").setLevel(logging.ERROR) | ||
logging.getLogger("pyrogram").setLevel(logging.ERROR) | ||
logging.getLogger("aiohttp.web").setLevel(logging.ERROR) | ||
|
||
loop = asyncio.get_event_loop() | ||
server = web.AppRunner(web_server()) | ||
|
||
loop = asyncio.get_event_loop() | ||
|
||
async def start_services(): | ||
print("----------------------------- DONE -----------------------------") | ||
print() | ||
print("-------------------- Initializing Telegram Bot --------------------") | ||
await StreamBot.start() | ||
bot_info = await StreamBot.get_me() | ||
StreamBot.username = bot_info.username | ||
print("------------------------------ DONE ------------------------------") | ||
print() | ||
print( | ||
"----------------------------- Initializing Clients -----------------------------" | ||
"---------------------- Initializing Clients ----------------------" | ||
) | ||
await initialize_clients() | ||
print("----------------------------- DONE -----------------------------") | ||
print("------------------------------ DONE ------------------------------") | ||
if Var.ON_HEROKU: | ||
print("------------------ Starting Keep Alive Service ------------------") | ||
print() | ||
asyncio.create_task(utils.ping_server()) | ||
print("-------------------- Initalizing Web Server --------------------") | ||
app = web.AppRunner(await web_server()) | ||
await app.setup() | ||
print("--------------------- Initalizing Web Server ---------------------") | ||
await server.setup() | ||
bind_address = "0.0.0.0" if Var.ON_HEROKU else Var.BIND_ADDRESS | ||
await web.TCPSite(app, bind_address, Var.PORT).start() | ||
print("----------------------------- DONE -----------------------------") | ||
await web.TCPSite(server, bind_address, Var.PORT).start() | ||
print("------------------------------ DONE ------------------------------") | ||
print() | ||
print("----------------------- Service Started -----------------------") | ||
print("------------------------- Service Started -------------------------") | ||
print(" bot =>> {}".format(bot_info.first_name)) | ||
if bot_info.dc_id: | ||
print(" DC ID =>> {}".format(str(bot_info.dc_id))) | ||
print(" server ip =>> {}".format(bind_address, Var.PORT)) | ||
if Var.ON_HEROKU: | ||
print(" app running on =>> {}".format(Var.FQDN)) | ||
print("---------------------------------------------------------------") | ||
print("------------------------------------------------------------------") | ||
await idle() | ||
|
||
async def cleanup(): | ||
await server.cleanup() | ||
await StreamBot.stop() | ||
|
||
if __name__ == "__main__": | ||
try: | ||
loop.run_until_complete(start_services()) | ||
except KeyboardInterrupt: | ||
logging.info("----------------------- Service Stopped -----------------------") | ||
pass | ||
except Exception as err: | ||
logging.error(err.with_traceback(None)) | ||
finally: | ||
loop.run_until_complete(cleanup()) | ||
loop.stop() | ||
print("------------------------ Stopped Services ------------------------") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters