Move isgd.py to shorturl.py and switch back to using bit.ly
This commit is contained in:
parent
44b15073e7
commit
ed57ac7c17
2 changed files with 13 additions and 5 deletions
|
@ -75,3 +75,6 @@ spotify-client-secret =
|
||||||
|
|
||||||
# https://opencagedata.com/users/sign_up
|
# https://opencagedata.com/users/sign_up
|
||||||
opencagedata-api-key =
|
opencagedata-api-key =
|
||||||
|
|
||||||
|
# https://bitly.com/a/oauth_apps
|
||||||
|
bitly-api-key =
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
|
#--require-config bitly-api-key
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from src import ModuleManager, utils
|
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):
|
class Module(ModuleManager.BaseModule):
|
||||||
|
_name = "Short"
|
||||||
|
|
||||||
def on_load(self):
|
def on_load(self):
|
||||||
self.exports.add("shortlink", self._shortlink)
|
self.exports.add("shortlink", self._shortlink)
|
||||||
|
|
||||||
|
@ -11,11 +15,12 @@ class Module(ModuleManager.BaseModule):
|
||||||
if not re.match(utils.http.REGEX_URL, url):
|
if not re.match(utils.http.REGEX_URL, url):
|
||||||
url = "http://%s" % url
|
url = "http://%s" % url
|
||||||
|
|
||||||
page = utils.http.request(ISGD_API_URL, get_params=
|
page = utils.http.request(URL_BITLYSHORTEN, get_params={
|
||||||
{"format": "json", "url": url}, json=True)
|
"access_token": self.bot.config["bitly-api-key"],
|
||||||
|
"longUrl": url}, json=True)
|
||||||
|
|
||||||
if page and page.data["shorturl"]:
|
if page and page.data["data"]:
|
||||||
return page.data["shorturl"]
|
return page.data["data"]["url"]
|
||||||
|
|
||||||
@utils.hook("received.command.shorten")
|
@utils.hook("received.command.shorten")
|
||||||
def shorten(self, event):
|
def shorten(self, event):
|
Loading…
Reference in a new issue