-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy path__main__.py
86 lines (81 loc) · 3.97 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import os
import sys
import glob
import asyncio
import logging
import importlib
from pathlib import Path
from pyrogram import idle
from .bot import DxStreamBot
from .vars import Var
from aiohttp import web
from .server import web_server
from .utils.keepalive import ping_server
from Dxbots.bot.clients import initialize_clients
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
logging.getLogger("aiohttp").setLevel(logging.ERROR)
logging.getLogger("pyrogram").setLevel(logging.ERROR)
logging.getLogger("aiohttp.web").setLevel(logging.ERROR)
ppath = "Dxbots/bot/plugins/*.py"
files = glob.glob(ppath)
DxStreamBot.start()
loop = asyncio.get_event_loop()
async def start_services():
print('\n')
print('------------------- Initalizing Telegram Bot -------------------')
bot_info = await DxStreamBot.get_me()
DxStreamBot.username = bot_info.username
print("------------------------------ DONE ------------------------------")
print()
print(
"---------------------- Initializing Clients ----------------------"
)
await initialize_clients()
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"Dxbots/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["Dxbots.bot.plugins." + plugin_name] = load
print("Imported => " + plugin_name)
if Var.ON_HEROKU:
print("------------------ Starting Keep Alive Service ------------------")
print()
asyncio.create_task(ping_server())
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.BIND_ADRESS
await web.TCPSite(app, bind_address, Var.PORT).start()
print('----------------------------- DONE ---------------------------------------------------------------------')
print('\n')
print('---------------------------------------------------------------------------------------------------------')
print('---------------------------------------------------------------------------------------------------------')
print(' follow me for more such exciting bots! https://github.com/DX-MODS/DxStreamerBot')
print('---------------------------------------------------------------------------------------------------------')
print('\n')
print('----------------------- Service Started -----------------------------------------------------------------')
print(' bot =>> {}'.format((await DxStreamBot.get_me()).first_name))
print(' server ip =>> {}:{}'.format(bind_address, Var.PORT))
print(' Owner =>> {}'.format((Var.OWNER_USERNAME)))
if Var.ON_HEROKU:
print(' app runnng on =>> {}'.format(Var.FQDN))
print('---------------------------------------------------------------------------------------------------------')
print('Give a star to my repo https://github.com/DX-MODS/DxStreamerBot also follow me for new bots')
print('---------------------------------------------------------------------------------------------------------')
await idle()
if __name__ == '__main__':
try:
loop.run_until_complete(start_services())
except KeyboardInterrupt:
logging.info('----------------------- Service Stopped -----------------------')