forked from OSALTDev/nya-chan-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunner.py
51 lines (40 loc) · 1.18 KB
/
runner.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
import bot
import os
import traceback
from discord.ext import commands
BotInstance = bot.BotBase()
# Helper function to load extensions
def _load_and_print_if_error(name):
try:
BotInstance.load_extension(name)
except commands.ExtensionAlreadyLoaded:
# Ignore error if already loaded
pass
except commands.ExtensionError as e:
# Display error message and log error
print(f"Failed to load cog: {name}")
if bot.Config.debug:
BotInstance.logger.error(traceback.format_exc())
BotInstance.logger.error(e)
# Populate cogs if cogs dont exist
cogs = bot.BotConfig.cogs
if not cogs:
cogs = [
f.replace('.py', '') for f in os.listdir("cogs")
if os.path.isfile(os.path.join("cogs", f))
and f.split(".")[-1] == "py"
]
# Load all cogs
for cog in cogs:
_load_and_print_if_error(f"cogs.{cog}")
# Required cogs
_load_and_print_if_error("cogs.core")
# Debug cog
if bot.Config.debug:
_load_and_print_if_error("jishaku")
# Write PID to a file for stopping with systemctl
pidfile = open(".pid", "w")
pidfile.write(str(os.getpid()))
pidfile.close()
# Begin!
BotInstance.run(bot.BotConfig.token)