diff options
author | Parker <contact@pkrm.dev> | 2024-06-26 18:48:53 -0500 |
---|---|---|
committer | Parker <contact@pkrm.dev> | 2024-06-26 18:48:53 -0500 |
commit | 0c741e3c2b41bac353a437a7bb1b3393b44c440e (patch) | |
tree | 646f0f78ae0b7ac79aca1dc14b215b2e14b85271 /code/config.py | |
parent | e276ef9486145d50c4b4c47cb618b4c6d3366b95 (diff) |
Add `return` for environment variables
Diffstat (limited to 'code/config.py')
-rw-r--r-- | code/config.py | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/code/config.py b/code/config.py index c7be1da..04eeff5 100644 --- a/code/config.py +++ b/code/config.py @@ -46,7 +46,7 @@ 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() + return validate_env_vars() else: LOG.info("Detected local environment. Checking for config.ini file.") @@ -172,13 +172,20 @@ def validate_config(file_contents): BUG_CHANNEL_ID = int(config["BOT_INFO"]["BUG_CHANNEL_ID"]) # Assign the rest of the variables - TOKEN = config["BOT_INFO"]["TOKEN"] - SPOTIFY_CLIENT_ID = config["SPOTIFY"]["SPOTIFY_CLIENT_ID"] - SPOTIFY_CLIENT_SECRET = config["SPOTIFY"]["SPOTIFY_CLIENT_SECRET"] - CLIENT = openai.OpenAI(api_key=config["OPENAI"]["OPENAI_API_KEY"]) - LAVALINK_HOST = config["LAVALINK"]["HOST"] - LAVALINK_PORT = config["LAVALINK"]["PORT"] - LAVALINK_PASSWORD = config["LAVALINK"]["PASSWORD"] + try: + TOKEN = config["BOT_INFO"]["TOKEN"] + SPOTIFY_CLIENT_ID = config["SPOTIFY"]["SPOTIFY_CLIENT_ID"] + SPOTIFY_CLIENT_SECRET = config["SPOTIFY"]["SPOTIFY_CLIENT_SECRET"] + CLIENT = openai.OpenAI(api_key=config["OPENAI"]["OPENAI_API_KEY"]) + LAVALINK_HOST = config["LAVALINK"]["HOST"] + LAVALINK_PORT = config["LAVALINK"]["PORT"] + LAVALINK_PASSWORD = config["LAVALINK"]["PASSWORD"] + except KeyError: + sys.exit( + LOG.critical( + "One or more requires environment variables are missing. Please check the docs." + ) + ) if errors > 0: sys.exit( |