aboutsummaryrefslogtreecommitdiff
path: root/modules/bitly.py
diff options
context:
space:
mode:
authorGravatar jesopo2019-06-25 17:53:00 +0100
committerGravatar jesopo2019-06-25 17:53:00 +0100
commit12181bfec6c3219571d50779a21e649f23e2b030 (patch)
tree957f74cce2eea46a53bd643e46d4e576012d4e2d /modules/bitly.py
parentcatch and format "unknown record type" exceptions (diff)
signature
Add system to have multiple url shorteners and chose which to use
Diffstat (limited to 'modules/bitly.py')
-rw-r--r--modules/bitly.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/modules/bitly.py b/modules/bitly.py
new file mode 100644
index 00000000..52703fe9
--- /dev/null
+++ b/modules/bitly.py
@@ -0,0 +1,22 @@
+#--depends-on commands
+#--require-config bitly-api-key
+
+import re
+from src import ModuleManager, utils
+
+URL_BITLYSHORTEN = "https://api-ssl.bitly.com/v3/shorten"
+
+class Module(ModuleManager.BaseModule):
+ def on_load(self):
+ self.exports.add("shorturl-s-bitly", self._shorturl)
+ def _shorturl(self, url):
+ if len(url) < 22:
+ return None
+
+ page = utils.http.request(URL_BITLYSHORTEN, get_params={
+ "access_token": self.bot.config["bitly-api-key"],
+ "longUrl": url}, json=True)
+
+ if page and page.data["data"]:
+ return page.data["data"]["url"]
+ return None