From 8dbf9b6a656dbc1a4f80d8ecf464dba370247cf6 Mon Sep 17 00:00:00 2001 From: lukeroge Date: Sun, 26 Feb 2012 00:43:14 +1300 Subject: [PATCH] Somehow the last commit stuffed up. Lets try it again --- plugins/shorten.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/plugins/shorten.py b/plugins/shorten.py index b435308..b4e06da 100644 --- a/plugins/shorten.py +++ b/plugins/shorten.py @@ -1,4 +1,6 @@ -# # Lukeroge +# Plugin by Lukeroge +# + from util import hook, http try: @@ -15,7 +17,7 @@ class ShortenError(Exception): def __str__(self): return repr(self.value) -def tiny(url, user, apikey): +def bitly(url, user, apikey): try: params = urlencode({'longUrl': url, 'login': user, 'apiKey': apikey, 'format': 'json'}) j = http.get_json("http://api.bit.ly/v3/shorten?%s" % params) @@ -28,6 +30,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 bitly(inp, api_user, api_key) \ No newline at end of file