-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy path__main__.py
67 lines (56 loc) · 2.11 KB
/
__main__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# This file is a part of TG-FileStreamBot
# Coding : Jyothis Jayanth [@EverythingSuckz]
import sys
import asyncio
import logging
from logging import handlers
from aiohttp import web
from pyrogram import idle
from WebStreamer import utils
from WebStreamer import StreamBot
from WebStreamer.server import web_server
from WebStreamer.bot.clients import initialize_clients
from .vars import Var
logging.basicConfig(
level=logging.DEBUG if Var.DEBUG else logging.INFO,
datefmt="%d/%m/%Y %H:%M:%S",
format="[%(asctime)s][%(name)s][%(levelname)s] ==> %(message)s",
handlers=[logging.StreamHandler(stream=sys.stdout),
handlers.RotatingFileHandler("streambot.log", mode="a", maxBytes=1048576*25, backupCount=2, encoding="utf-8")],)
logging.getLogger("aiohttp").setLevel(logging.DEBUG if Var.DEBUG else logging.ERROR)
logging.getLogger("pyrogram").setLevel(logging.INFO if Var.DEBUG else logging.ERROR)
logging.getLogger("aiohttp.web").setLevel(logging.DEBUG if Var.DEBUG else logging.ERROR)
server = web.AppRunner(web_server())
loop = asyncio.get_event_loop()
async def start_services():
logging.info("Initializing Telegram Bot")
await StreamBot.start()
bot_info = await StreamBot.get_me()
logging.debug(bot_info)
StreamBot.username = bot_info.username
logging.info("Initialized Telegram Bot")
await initialize_clients()
if Var.KEEP_ALIVE:
asyncio.create_task(utils.ping_server())
await server.setup()
await web.TCPSite(server, Var.BIND_ADDRESS, Var.PORT).start()
logging.info("Service Started")
logging.info("bot =>> %s", bot_info.first_name)
if bot_info.dc_id:
logging.info("DC ID =>> %d", bot_info.dc_id)
logging.info("URL =>> %s", Var.URL)
await idle()
async def cleanup():
await server.cleanup()
await StreamBot.stop()
if __name__ == "__main__":
try:
loop.run_until_complete(start_services())
except KeyboardInterrupt:
pass
except Exception as err:
logging.error(err.with_traceback(None))
finally:
loop.run_until_complete(cleanup())
loop.stop()
logging.info("Stopped Services")