Fix support for environment variables
This commit is contained in:
parent
88c545b96f
commit
e276ef9486
@ -57,6 +57,5 @@ async def get_access_token():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
config_contents = config.load_config()
|
||||
config.validate_config(config_contents)
|
||||
config.load_config()
|
||||
bot.run(config.TOKEN)
|
||||
|
@ -45,12 +45,15 @@ create a new templated config.ini file if it doesn't exist.
|
||||
def load_config():
|
||||
# Look for variables in the environment
|
||||
if "TOKEN" in os.environ or "BOT_COLOR" in os.environ or "BOT_INVITE_LINK" in os.environ:
|
||||
LOG.info("Detected environment variables. Checking for configuration options.")
|
||||
validate_env_vars()
|
||||
else:
|
||||
LOG.info("Detected local environment. Checking for config.ini file.")
|
||||
|
||||
try:
|
||||
with open("config.ini", "r") as f:
|
||||
file_contents = f.read()
|
||||
return file_contents
|
||||
validate_config(file_contents)
|
||||
|
||||
except FileNotFoundError:
|
||||
config = configparser.ConfigParser()
|
||||
@ -221,25 +224,26 @@ def validate_env_vars():
|
||||
BOT_INVITE_LINK = os.environ["BOT_INVITE_LINK"]
|
||||
|
||||
# Make sure FEEDBACK_CHANNEL_ID is either None or 19 characters long
|
||||
if os.environ["FEEDBACK_CHANNEL_ID"] is not None:
|
||||
try:
|
||||
if len(os.environ["FEEDBACK_CHANNEL_ID"]) != 19:
|
||||
LOG.error("FEEDBACK_CHANNEL_ID is not a valid Discord channel ID.")
|
||||
errors += 1
|
||||
else:
|
||||
FEEDBACK_CHANNEL_ID = int(os.environ["FEEDBACK_CHANNEL_ID"])
|
||||
else:
|
||||
except KeyError:
|
||||
FEEDBACK_CHANNEL_ID = None
|
||||
|
||||
# Make sure BUG_CHANNEL_ID is either None or 19 characters long
|
||||
if os.environ["BUG_CHANNEL_ID"] is not None:
|
||||
try:
|
||||
if len(os.environ["BUG_CHANNEL_ID"]) != 19:
|
||||
LOG.error("BUG_CHANNEL_ID is not a valid Discord channel ID.")
|
||||
errors += 1
|
||||
else:
|
||||
BUG_CHANNEL_ID = int(os.environ["BUG_CHANNEL_ID"])
|
||||
else:
|
||||
except KeyError:
|
||||
BUG_CHANNEL_ID = None
|
||||
|
||||
|
||||
# Assign the rest of the variables
|
||||
TOKEN = os.environ["TOKEN"]
|
||||
SPOTIFY_CLIENT_ID = os.environ["SPOTIFY_CLIENT_ID"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user