Add support for a configuration file.

This commit is contained in:
Ske
2019-03-07 16:29:46 +01:00
parent 6794f0ab03
commit f21fd968fd
9 changed files with 51 additions and 82 deletions

View File

@@ -1,4 +1,7 @@
import asyncio
import json
import os
import sys
try:
# uvloop doesn't work on Windows, therefore an optional dependency
@@ -7,5 +10,13 @@ try:
except ImportError:
pass
from pluralkit import bot
bot.run()
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:
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:
print("Config file must contain key 'token', or the environment variable TOKEN must be present.")
else:
from pluralkit import bot
bot.run(os.environ.get("TOKEN", config["token"]), os.environ.get("DATABASE_URI", config["database_uri"]), int(config.get("log_channel", 0)))