aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorGravatar dngfx2018-09-09 21:47:28 +0100
committerGravatar dongfix2018-09-09 21:47:28 +0100
commit5d8ad6a37a9b3845d772892e28809c0cab4f5c23 (patch)
treedc04f0d4882ea55c67dc69a216335fcece6f4ebc /modules
parentThere's nothing regular about these expressions. (diff)
Replace bit.ly with is.gd. No API key, no beeping Bit. It's a win win!
Diffstat (limited to 'modules')
-rw-r--r--modules/isgd.py (renamed from modules/bitly.py)20
1 files changed, 10 insertions, 10 deletions
diff --git a/modules/bitly.py b/modules/isgd.py
index a64a451c..86af7447 100644
--- a/modules/bitly.py
+++ b/modules/isgd.py
@@ -1,9 +1,7 @@
-#--require-config bitly-api-key
-
import re
import Utils
-URL_BITLYSHORTEN = "https://api-ssl.bitly.com/v3/shorten"
+ISGD_API_URL = "https://is.gd/create.php"
REGEX_URL = re.compile("https?://", re.I)
class Module(object):
@@ -12,22 +10,24 @@ class Module(object):
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="<url>")
+ help="Shorten a URL using the is.gd service.", usage="<url>")
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"]
+ 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("Short URL: %s" % link)
+ event["stdout"].write("Shortened URL: %s" % link)
else:
event["stderr"].write("Unable to shorten that URL.")