forked from weebzone/Surf-TG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__main__.py
61 lines (48 loc) · 1.73 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
from asyncio import get_event_loop, sleep as asleep, gather
from traceback import format_exc
from aiohttp import web
from pyrogram import idle
from bot import __version__, LOGGER
from bot.config import Telegram
from bot.server import web_server
from bot.telegram import StreamBot, UserBot
from bot.telegram.clients import initialize_clients
loop = get_event_loop()
async def start_services():
LOGGER.info(f'Initializing Surf-TG v-{__version__}')
await asleep(1.2)
await StreamBot.start()
StreamBot.username = StreamBot.me.username
LOGGER.info(f"Bot Client : [@{StreamBot.username}]")
if len(Telegram.SESSION_STRING) != 0:
await UserBot.start()
UserBot.username = UserBot.me.username or UserBot.me.first_name or UserBot.me.id
LOGGER.info(f"User Client : {UserBot.username}")
await asleep(1.2)
LOGGER.info("Initializing Multi Clients")
await initialize_clients()
await asleep(2)
LOGGER.info('Initalizing Surf Web Server..')
server = web.AppRunner(await web_server())
LOGGER.info("Server CleanUp!")
await server.cleanup()
await asleep(2)
LOGGER.info("Server Setup Started !")
await server.setup()
await web.TCPSite(server, '0.0.0.0', Telegram.PORT).start()
LOGGER.info("Surf-TG Started Revolving !")
await idle()
async def stop_clients():
await StreamBot.stop()
if len(Telegram.SESSION_STRING) != 0:
await UserBot.stop()
if __name__ == '__main__':
try:
loop.run_until_complete(start_services())
except KeyboardInterrupt:
LOGGER.info('Service Stopping...')
except Exception:
LOGGER.error(format_exc())
finally:
loop.run_until_complete(stop_clients())
loop.stop()