Move isgd.py to shorturl.py and switch back to using bit.ly

This commit is contained in:
jesopo 2019-05-01 08:17:48 +01:00
parent 44b15073e7
commit ed57ac7c17
2 changed files with 13 additions and 5 deletions

View file

@ -75,3 +75,6 @@ spotify-client-secret =
# https://opencagedata.com/users/sign_up
opencagedata-api-key =
# https://bitly.com/a/oauth_apps
bitly-api-key =

View file

@ -1,9 +1,13 @@
#--require-config bitly-api-key
import re
from src import ModuleManager, utils
ISGD_API_URL = "https://is.gd/create.php"
URL_BITLYSHORTEN = "https://api-ssl.bitly.com/v3/shorten"
class Module(ModuleManager.BaseModule):
_name = "Short"
def on_load(self):
self.exports.add("shortlink", self._shortlink)
@ -11,11 +15,12 @@ class Module(ModuleManager.BaseModule):
if not re.match(utils.http.REGEX_URL, url):
url = "http://%s" % url
page = utils.http.request(ISGD_API_URL, get_params=
{"format": "json", "url": url}, json=True)
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["shorturl"]:
return page.data["shorturl"]
if page and page.data["data"]:
return page.data["data"]["url"]
@utils.hook("received.command.shorten")
def shorten(self, event):