diff --git a/core/config.py b/core/config.py index b0c3862..4ffb53b 100644 --- a/core/config.py +++ b/core/config.py @@ -32,6 +32,7 @@ if not os.path.exists('config'): "tvdb": "INSERT API KEY FROM thetvdb.com HERE", "bitly_user": "INSERT USERNAME FROM bitly.com HERE", "bitly_api": "INSERT API KEY FROM bitly.com HERE", + "woflramalpha": "INSERT API KEY FROM wolframalpha.com HERE", "mc_user": "INSERT MINECRAFT USERNAME HERE (used to check login servers in mclogin.py)", "mc_pass": "INSERT MINECRAFT PASSWORD HERE (used to check login servers in mclogin.py)" }, diff --git a/plugins/geoip.py b/plugins/geoip.py index 6c05a78..9030372 100644 --- a/plugins/geoip.py +++ b/plugins/geoip.py @@ -23,8 +23,10 @@ def timezone(ip): @hook.command("location") def geoip(inp, say = None, bot = None): ".geoip - Performs a location check on the ip given." - api = bot.config['api_keys']['geoip'] - give = find_location(inp, api) + api_key = bot.config.get("api_keys", {}).get("geoip", None) + if api_key is None: + return "error: no api key set" + give = find_location(inp, api_key) if give["country"] not in [""," ","-"," - "]: if give["state"] == give["city"]: localstring = give["city"] diff --git a/plugins/shorten.py b/plugins/shorten.py index 55714e2..0586ac6 100644 --- a/plugins/shorten.py +++ b/plugins/shorten.py @@ -22,6 +22,8 @@ def tiny(url, user, apikey): @hook.command def shorten(inp, bot = None): ".shorten - Makes an j.mp/bit.ly shortlink to the url provided" - user = bot.config['api_keys']['bitly_user'] - api = bot.config['api_keys']['bitly_api'] - return tiny(inp, user, api) + api_user = bot.config.get("api_keys", {}).get("bitly_user", None) + api_key = bot.config.get("api_keys", {}).get("bitly_api", None) + if api_key is None: + return "error: no api key set" + return tiny(inp, api_user, api_key) diff --git a/plugins/tvdb.py b/plugins/tvdb.py index 75c1212..b1496ed 100644 --- a/plugins/tvdb.py +++ b/plugins/tvdb.py @@ -25,7 +25,7 @@ def get_zipped_xml(*args, **kwargs): return etree.parse(ZipFile(zip_buffer, "r").open(path)) -def get_episodes_for_series(seriesname): +def get_episodes_for_series(seriesname, api_key): res = {"error": None, "ended": False, "episodes": None, "name": None} # http://thetvdb.com/wiki/index.php/API:GetSeries try: @@ -59,7 +59,7 @@ def get_episodes_for_series(seriesname): return res -def get_episode_info(episode): +def get_episode_info(episode, api_key): first_aired = episode.findtext("FirstAired") try: @@ -84,9 +84,13 @@ def get_episode_info(episode): @hook.command @hook.command('tv') -def tv_next(inp): +def tv_next(inp, bot = None): ".tv_next -- get the next episode of " - episodes = get_episodes_for_series(inp) + + api_key = bot.config.get("api_keys", {}).get("tvdb", None) + if api_key is None: + return "error: no api key set" + episodes = get_episodes_for_series(inp, api_key) if episodes["error"]: return episodes["error"] @@ -102,7 +106,7 @@ def tv_next(inp): today = datetime.date.today() for episode in reversed(episodes): - ep_info = get_episode_info(episode) + ep_info = get_episode_info(episode, api_key) if ep_info is None: continue @@ -130,9 +134,13 @@ def tv_next(inp): @hook.command @hook.command('tv_prev') -def tv_last(inp): +def tv_last(inp, bot = None): ".tv_last -- gets the most recently aired episode of " - episodes = get_episodes_for_series(inp) + + api_key = bot.config.get("api_keys", {}).get("tvdb", None) + if api_key is None: + return "error: no api key set" + episodes = get_episodes_for_series(inp, api_key) if episodes["error"]: return episodes["error"] @@ -145,7 +153,7 @@ def tv_last(inp): today = datetime.date.today() for episode in reversed(episodes): - ep_info = get_episode_info(episode) + ep_info = get_episode_info(episode, api_key) if ep_info is None: continue diff --git a/plugins/wolframalpha.py b/plugins/wolframalpha.py index ce2812b..720230d 100644 --- a/plugins/wolframalpha.py +++ b/plugins/wolframalpha.py @@ -34,7 +34,7 @@ def wolframalpha(inp, bot=None): ret = '. '.join(pod_texts) if not pod_texts: - return 'no results' + return 'No results.' ret = re.sub(r'\\(.)', r'\1', ret) @@ -48,6 +48,6 @@ def wolframalpha(inp, bot=None): ret = re.sub(r'\W+$', '', ret) + '...' if not ret: - return 'no results' + return 'No results.' return ret