From 12181bfec6c3219571d50779a21e649f23e2b030 Mon Sep 17 00:00:00 2001 From: jesopo Date: Tue, 25 Jun 2019 17:53:00 +0100 Subject: Add system to have multiple url shorteners and chose which to use --- modules/bitly.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 modules/bitly.py (limited to 'modules/bitly.py') 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 -- cgit v1.3.1-10-gc9f91