PluralKit/src/bot_main.py

22 lines
866 B
Python
Raw Normal View History

2018-07-11 22:47:44 +00:00
import asyncio
2019-03-07 15:29:46 +00:00
import json
import os
import sys
2018-12-10 18:32:31 +00:00
try:
# uvloop doesn't work on Windows, therefore an optional dependency
import uvloop
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
except ImportError:
pass
2018-07-11 22:47:44 +00:00
2019-03-07 15:29:46 +00:00
with open(sys.argv[1] if len(sys.argv) > 1 else "pluralkit.conf") as f:
config = json.load(f)
if "database_uri" not in config and "DATABASE_URI" not in os.environ:
2019-03-07 15:29:46 +00:00
print("Config file must contain key 'database_uri', or the environment variable DATABASE_URI must be present.")
elif "token" not in config and "TOKEN" not in os.environ:
2019-03-07 15:29:46 +00:00
print("Config file must contain key 'token', or the environment variable TOKEN must be present.")
else:
from pluralkit import bot
2019-03-08 14:19:08 +00:00
bot.run(os.environ.get("TOKEN", config.get("token")), os.environ.get("DATABASE_URI", config.get("database_uri")), int(config.get("log_channel", 0)))