diff options
author | Parker <contact@pkrm.dev> | 2024-06-26 18:41:37 -0500 |
---|---|---|
committer | Parker <contact@pkrm.dev> | 2024-06-26 18:41:37 -0500 |
commit | e276ef9486145d50c4b4c47cb618b4c6d3366b95 (patch) | |
tree | db14922502922c0365bda7451227e41d8a9cd671 /code/config.py | |
parent | 88c545b96f54b053208c3f668852608cee14bb74 (diff) |
Fix support for environment variables
Diffstat (limited to 'code/config.py')
-rw-r--r-- | code/config.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/code/config.py b/code/config.py index 1e7c5ba..c7be1da 100644 --- a/code/config.py +++ b/code/config.py @@ -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"] |