forked from avipatilpro/FileStreamBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__main__.py
61 lines (55 loc) · 2.22 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
# This file is a part of TG-FileStreamBot
# Coding: @AvishkarPatil & @EverythingSuckz & @AbirHasan2005
import os
import sys
import glob
import asyncio
import logging
import importlib
from pathlib import Path
from pyrogram import idle
from .bot import StreamBot
from .vars import Var
from aiohttp import web
from .server import web_server
ppath = "WebStreamer/bot/plugins/*.py"
files = glob.glob(ppath)
loop = asyncio.get_event_loop()
async def start_services():
print('\n')
print('------------------- Initalizing Telegram Bot -------------------')
await StreamBot.start()
print('\n')
print('---------------------- DONE ----------------------')
print('\n')
print('------------------- Importing -------------------')
for name in files:
with open(name) as a:
patt = Path(a.name)
plugin_name = patt.stem.replace(".py", "")
plugins_dir = Path(f"WebStreamer/bot/plugins/{plugin_name}.py")
import_path = ".plugins.{}".format(plugin_name)
spec = importlib.util.spec_from_file_location(import_path, plugins_dir)
load = importlib.util.module_from_spec(spec)
spec.loader.exec_module(load)
sys.modules["WebStreamer.bot.plugins." + plugin_name] = load
print("Imported => " + plugin_name)
print('\n')
print('------------------- Initalizing Web Server -------------------')
app = web.AppRunner(await web_server())
await app.setup()
bind_address = "0.0.0.0" if Var.ON_HEROKU else Var.FQDN
await web.TCPSite(app, bind_address, Var.PORT).start()
print('\n')
print('----------------------- Service Started -----------------------')
print(' bot =>> {}'.format((await StreamBot.get_me()).first_name))
print(' server ip =>> {}:{}'.format(bind_address, Var.PORT))
if Var.ON_HEROKU:
print(' app runnng on =>> {}'.format(Var.FQDN))
print('---------------------------------------------------------------')
await idle()
if __name__ == '__main__':
try:
loop.run_until_complete(start_services())
except KeyboardInterrupt:
print('----------------------- Service Stopped -----------------------')