-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmain.py
More file actions
46 lines (38 loc) · 1.78 KB
/
main.py
File metadata and controls
46 lines (38 loc) · 1.78 KB
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
import asyncio
import os
import subprocess
import sys
from core.colors import Color
try:
from core.discord_bot import DiscordBridgeBot
from core.config import DiscordConfig, SettingsConfig
except ModuleNotFoundError as e:
missing_module = str(e).split("'")[1]
print(f"Module {missing_module} not found. Installing...")
subprocess.check_call([sys.executable, "-m", "pip", "install", missing_module])
print(f"Module {missing_module} installed. Restarting bot...")
os.execv(sys.executable, ['python'] + sys.argv)
if "update" in sys.argv:
print(f"{Color.YELLOW}Updating...{Color.RESET}")
directory = os.path.dirname(os.path.realpath(__file__))
subprocess.check_call(["git", "pull"], cwd=directory)
subprocess.check_call([sys.executable, "-m", "pip", "install", "-U", "-r", directory + "/requirements.txt"])
print(f"{Color.GREEN}Updated!{Color.RESET}")
sys.exit(0)
bot = DiscordBridgeBot()
async def main():
async with bot:
await bot.load_extension("discord_extensions.admin")
await bot.load_extension("discord_extensions.bridge")
await bot.load_extension("discord_extensions.generic")
if SettingsConfig.extensions:
print(f"{Color.MAGENTA}Extensions{Color.RESET} > Loading {len(SettingsConfig.extensions)} extensions...")
for extension in SettingsConfig.extensions:
await bot.load_extension(extension, package="extensions" if extension.startswith(".") else None)
print(f"{Color.MAGENTA}Extensions{Color.RESET} > {extension} loaded!")
print(f"{Color.MAGENTA}Extensions{Color.RESET} > Extensions loaded!")
await bot.start(DiscordConfig.token)
try:
asyncio.run(main())
except KeyboardInterrupt:
pass