From 4dcad8d24852e8e658a17cd267111eb8f6789248 Mon Sep 17 00:00:00 2001 From: Kamal Curi Date: Sat, 20 Aug 2022 12:54:18 -0300 Subject: [PATCH] CHANGE: Unset environment variables won't let the weather command be executed --- settings/config.py | 2 +- utils/commands.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/settings/config.py b/settings/config.py index 7435b77..61fa33f 100644 --- a/settings/config.py +++ b/settings/config.py @@ -81,7 +81,7 @@ PERMISSIONS = { } OW_API_CONFIG = { - 'api_id' : os.environ.get('OPENWEATHER_API_TOKEN'), + 'api_id' : os.environ.get('OPENWEATHER_API_TOKEN', 'no'), 'gc_url' : 'http://api.openweathermap.org/geo/1.0/direct?q=,,&limit=1&appid=', 'wh_url' : 'https://api.openweathermap.org/data/2.5/weather?lat=&lon=&units=metric&appid=' } diff --git a/utils/commands.py b/utils/commands.py index e0f2c89..d29cc0f 100644 --- a/utils/commands.py +++ b/utils/commands.py @@ -10,7 +10,7 @@ from discord.ext import commands from utils.database import get_by_id, get_quotes, remove_quote, set_quote, count_quotes from utils.weather import geocode, getweatherdata, displayweather -from settings.config import PERMISSIONS +from settings.config import PERMISSIONS, OW_API_CONFIG client = commands.Bot(command_prefix='--') logger = logging.getLogger(__name__) @@ -187,6 +187,9 @@ async def weather(bot: object, *location: str) -> str: """ Displays the weather information for a given place """ + if OW_API_CONFIG['api_id'] == 'no': + return await bot.send("You haven't set up an API key! Make an user and set up an API key in https://openweathermap.org/\n \ + (The weather command hansn't been set up properly, make sure you have `OPENWEATHER_API_TOKEN` set up") if location: location = str(location) stripped = re2.sub(" ", "", location) # Strips all whitespace