diff --git a/plugins/github.py b/plugins/github.py index 942b1ab..a3ed88a 100644 --- a/plugins/github.py +++ b/plugins/github.py @@ -1,6 +1,6 @@ from util import hook, http import json -import gitio +import urllib2 shortcuts = {"cloudbot": "ClouDev/CloudBot"} @@ -64,3 +64,52 @@ def ghissues(inp): return fmt1 % (number, state, user, title, gitiourl) else: return fmt % (number, state, user, title, summary, gitiourl) + + +@hook.command +def gitio(inp): + "gitio [code] -- Shorten Github URLs with git.io. [code] is" \ + " a optional custom short code." + split = inp.split(" ") + url = split[0] + + try: + code = split[1] + except: + code = None + + # if the first 8 chars of "url" are not "https://" then append + # "https://" to the url, also convert "http://" to "https://" + if url[:8] != "https://": + if url[:7] != "http://": + url = "https://" + url + else: + url = "https://" + url[7:] + url = 'url=' + str(url) + if code: + url = url + '&code=' + str(code) + req = urllib2.Request(url='http://git.io', data=url) + + # try getting url, catch http error + try: + f = urllib2.urlopen(req) + except urllib2.HTTPError: + return "Failed to get URL!" + urlinfo = str(f.info()) + + # loop over the rows in urlinfo and pick out location and + # status (this is pretty odd code, but urllib2.Request is weird) + for row in urlinfo.split("\n"): + if row.find("Status") != -1: + status = row + if row.find("Location") != -1: + location = row + + print status + if not "201" in status: + return "Failed to get URL!" + + # this wont work for some reason, so lets ignore it ^ + + # return location, minus the first 10 chars + return location[10:] diff --git a/plugins/gitio.py b/plugins/gitio.py deleted file mode 100755 index 9844282..0000000 --- a/plugins/gitio.py +++ /dev/null @@ -1,52 +0,0 @@ -# Plugin by neersighted and Lukeroge -from util import hook -import urllib2 - - -@hook.command -def gitio(inp): - "gitio [code] -- Shorten Github URLs with git.io. [code] is" \ - " a optional custom short code." - split = inp.split(" ") - url = split[0] - - try: - code = split[1] - except: - code = None - - # if the first 8 chars of "url" are not "https://" then append - # "https://" to the url, also convert "http://" to "https://" - if url[:8] != "https://": - if url[:7] != "http://": - url = "https://" + url - else: - url = "https://" + url[7:] - url = 'url=' + str(url) - if code: - url = url + '&code=' + str(code) - req = urllib2.Request(url='http://git.io', data=url) - - # try getting url, catch http error - try: - f = urllib2.urlopen(req) - except urllib2.HTTPError: - return "Failed to get URL!" - urlinfo = str(f.info()) - - # loop over the rows in urlinfo and pick out location and - # status (this is pretty odd code, but urllib2.Request is weird) - for row in urlinfo.split("\n"): - if row.find("Status") != -1: - status = row - if row.find("Location") != -1: - location = row - - print status - if not "201" in status: - return "Failed to get URL!" - - # this wont work for some reason, so lets ignore it ^ - - # return location, minus the first 10 chars - return location[10:]