From 5d8ad6a37a9b3845d772892e28809c0cab4f5c23 Mon Sep 17 00:00:00 2001 From: dngfx Date: Sun, 9 Sep 2018 21:47:28 +0100 Subject: Replace bit.ly with is.gd. No API key, no beeping Bit. It's a win win! --- modules/bitly.py | 33 --------------------------------- modules/isgd.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 33 deletions(-) delete mode 100644 modules/bitly.py create mode 100644 modules/isgd.py (limited to 'modules') diff --git a/modules/bitly.py b/modules/bitly.py deleted file mode 100644 index a64a451c..00000000 --- a/modules/bitly.py +++ /dev/null @@ -1,33 +0,0 @@ -#--require-config bitly-api-key - -import re -import Utils - -URL_BITLYSHORTEN = "https://api-ssl.bitly.com/v3/shorten" -REGEX_URL = re.compile("https?://", re.I) - -class Module(object): - def __init__(self, bot, events, exports): - self.bot = bot - self.events = events - events.on("get.shortlink").hook(self.shortlink) - events.on("received.command.shorten").hook(self.shorten, min_args=1, - help="Shorten a URL.", usage="") - - def shortlink(self, event): - url = event["url"] - if not re.match(REGEX_URL, url): - url = "http://%s" % url - data = Utils.get_url(URL_BITLYSHORTEN, get_params={ - "access_token": self.bot.config["bitly-api-key"], - "longUrl": url}, json=True) - if data and data["data"]: - return data["data"]["url"] - - def shorten(self, event): - link = self.events.on("get.shortlink").call_for_result( - url=event["args"]) - if link: - event["stdout"].write("Short URL: %s" % link) - else: - event["stderr"].write("Unable to shorten that URL.") diff --git a/modules/isgd.py b/modules/isgd.py new file mode 100644 index 00000000..86af7447 --- /dev/null +++ b/modules/isgd.py @@ -0,0 +1,33 @@ +import re +import Utils + +ISGD_API_URL = "https://is.gd/create.php" +REGEX_URL = re.compile("https?://", re.I) + +class Module(object): + def __init__(self, bot, events, exports): + self.bot = bot + self.events = events + events.on("get.shortlink").hook(self.shortlink) + events.on("received.command.shorten").hook(self.shorten, min_args=1, + help="Shorten a URL using the is.gd service.", usage="") + + def shortlink(self, event): + url = event["url"] + if not re.match(REGEX_URL, url): + url = "http://%s" % url + data = Utils.get_url(ISGD_API_URL, get_params={ + "format": "json", + "url": url + }, json=True) + + if data and data["shorturl"]: + return data["shorturl"] + + def shorten(self, event): + link = self.events.on("get.shortlink").call_for_result( + url=event["args"]) + if link: + event["stdout"].write("Shortened URL: %s" % link) + else: + event["stderr"].write("Unable to shorten that URL.") -- cgit v1.3.1-10-gc9f91