From 37a3cc20301a83bc55c36ee52f1666893184eb0f Mon Sep 17 00:00:00 2001 From: lukeroge Date: Wed, 7 Mar 2012 12:39:55 +1300 Subject: [PATCH 1/5] Update plugins/time.py --- plugins/time.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/time.py b/plugins/time.py index 3e64edf..d64d11a 100755 --- a/plugins/time.py +++ b/plugins/time.py @@ -240,7 +240,7 @@ def timecommand(inp, say=None): try: return get_time(inp) except ValueError: - return "Could not get time for " + inp + "!" + return "Could not get the time for " + inp + "!" From 800dacd274da24b9d2cd6775f4d29ac63259de7d Mon Sep 17 00:00:00 2001 From: lukeroge Date: Wed, 7 Mar 2012 14:11:15 +1300 Subject: [PATCH 2/5] Started tweaking quote.py --- plugins/quote.py | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/plugins/quote.py b/plugins/quote.py index cb20f2b..dd1680b 100755 --- a/plugins/quote.py +++ b/plugins/quote.py @@ -12,15 +12,9 @@ def format_quote(q, num, n_quotes): def create_table_if_not_exists(db): "Creates an empty quote table if one does not already exist" - db.execute('''CREATE TABLE IF NOT EXISTS quote ( - chan, - nick, - add_nick, - msg, - time real, - deleted default 0, - PRIMARY KEY (chan, nick, msg) - )''') + db.execute("create table if not exists quote" + "(chan, nick, add_nick, msg, time real, deleted default 0, " + "primary key (chan, nick, msg))") db.commit() def add_quote(db, chan, nick, add_nick, msg): @@ -37,15 +31,12 @@ def add_quote(db, chan, nick, add_nick, msg): def del_quote(db, chan, nick, add_nick, msg): "Deletes a quote from a nick" - db.execute('''UPDATE quote - SET deleted = 1 - WHERE chan=? - AND lower(nick)=lower(?) - AND msg=msg''') + db.execute('''UPDATE quote SET deleted = 1 WHERE + chan=? AND lower(nick)=lower(?) AND msg=msg''') db.commit() def get_quote_num(num, count, name): - "Returns the quote number desired from the database" + "Returns the quote number to fetch from the DB" if num: # Make sure num is a number if it isn't false num = int(num) if count == 0: # If there are no quotes in the database, raise an Exception. @@ -62,9 +53,7 @@ def get_quote_num(num, count, name): def get_quote_by_nick(db, nick, num=False): "Returns a formatted quote from a nick, random or selected by number" - count = db.execute('''SELECT COUNT(*) - FROM quote - WHERE deleted != 1 + count = db.execute('''SELECT COUNT(*) FROM quote WHERE deleted != 1 AND lower(nick) = lower(?)''', [nick]).fetchall()[0][0] try: From ac03ceb3668edfe0926a40f9d2fc88470a439b1d Mon Sep 17 00:00:00 2001 From: neersighted Date: Tue, 6 Mar 2012 23:06:41 -0800 Subject: [PATCH 3/5] fixed bug in shorten.py --- plugins/shorten.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/shorten.py b/plugins/shorten.py index 270194b..df977b1 100755 --- a/plugins/shorten.py +++ b/plugins/shorten.py @@ -12,28 +12,30 @@ class ShortenError(Exception): def __str__(self): return repr(self.value) - + def bitly(url, user, apikey): try: + if url[:7] != "http://": + url = "http://" + url params = urlencode({'longUrl': url, 'login': user, 'apiKey': apikey, 'format': 'json'}) j = http.get_json("http://api.bit.ly/v3/shorten?%s" % params) if j['status_code'] == 200: return j['data']['url'] - raise ShortenError('%s'%j['status_txt']) + raise ShortenError('%s' % j['status_txt']) except (HTTPError, ShortenError): return "Could not shorten %s!" % url @hook.command -def shorten(inp, bot=None): +def shorten(inp, bot = None): ".shorten - Makes an j.mp/bit.ly shortlink to the url provided." - api_user = bot.config.get("api_keys", {}).get("bitly_user", None) + 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) @hook.command -def expand(inp, bot=None): +def expand(inp, bot = None): ".expand - Gets the original URL from a shortened link." try: url = http.get_url(inp) From 11c500515853af25725f3a2cfab9e5da3498cd75 Mon Sep 17 00:00:00 2001 From: neersighted Date: Tue, 6 Mar 2012 23:10:40 -0800 Subject: [PATCH 4/5] fixed bug with https --- plugins/shorten.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/shorten.py b/plugins/shorten.py index df977b1..9ba15bd 100755 --- a/plugins/shorten.py +++ b/plugins/shorten.py @@ -16,6 +16,8 @@ class ShortenError(Exception): def bitly(url, user, apikey): try: if url[:7] != "http://": + if url[:8] == "https://": + url = url url = "http://" + url params = urlencode({'longUrl': url, 'login': user, 'apiKey': apikey, 'format': 'json'}) j = http.get_json("http://api.bit.ly/v3/shorten?%s" % params) From 6749bf8340f3a97b5f420c864f29fdd4f3b4e368 Mon Sep 17 00:00:00 2001 From: neersighted Date: Wed, 7 Mar 2012 09:37:37 -0800 Subject: [PATCH 5/5] Fixed (I hope) the same bug with https:// --- plugins/shorten.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/shorten.py b/plugins/shorten.py index 9ba15bd..8a028a4 100755 --- a/plugins/shorten.py +++ b/plugins/shorten.py @@ -15,9 +15,9 @@ class ShortenError(Exception): def bitly(url, user, apikey): try: - if url[:7] != "http://": - if url[:8] == "https://": - url = url + if url[:8] == "https://": + pass + elif url[:7] != "http://": url = "http://" + url params = urlencode({'longUrl': url, 'login': user, 'apiKey': apikey, 'format': 'json'}) j = http.get_json("http://api.bit.ly/v3/shorten?%s" % params)