2012-03-27 23:20:18 -04:00
|
|
|
#!/usr/bin/python3
|
|
|
|
"""
|
|
|
|
linx.py - linx.li tools
|
2012-09-24 21:55:58 -04:00
|
|
|
author: andreim <andreim@andreim.net>
|
|
|
|
author: mutantmonkey <mutantmonkey@mutantmonkey.in>
|
2012-03-27 23:20:18 -04:00
|
|
|
"""
|
|
|
|
|
2012-06-02 01:17:09 -04:00
|
|
|
from tools import GrumbleError
|
2012-03-27 23:20:18 -04:00
|
|
|
import web
|
|
|
|
import json
|
|
|
|
|
2012-06-21 19:29:31 -04:00
|
|
|
|
2012-08-30 01:43:05 -04:00
|
|
|
def linx(phenny, input, short=False):
|
|
|
|
""".linx <url> - Upload a remote URL to linx.li."""
|
2012-03-27 23:20:18 -04:00
|
|
|
|
|
|
|
url = input.group(2)
|
|
|
|
if not url:
|
|
|
|
phenny.reply("No URL provided. CAN I HAS?")
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
2014-04-01 18:53:17 -04:00
|
|
|
req = web.post("https://linx.li/upload/remote", {'url': url, 'short': short, 'api_key': phenny.config.linx_api_key})
|
2013-06-09 01:27:24 -04:00
|
|
|
except (web.HTTPError, web.ConnectionError):
|
2014-04-01 18:53:17 -04:00
|
|
|
raise GrumbleError("Couldn't reach linx.li")
|
2012-03-27 23:20:18 -04:00
|
|
|
|
|
|
|
data = json.loads(req)
|
|
|
|
if len(data) <= 0 or not data['success']:
|
|
|
|
phenny.reply('Sorry, upload failed.')
|
|
|
|
return
|
|
|
|
|
|
|
|
phenny.reply(data['url'])
|
|
|
|
linx.rule = (['linx'], r'(.*)')
|
|
|
|
|
|
|
|
|
2012-08-30 01:43:05 -04:00
|
|
|
def lnx(phenny, input):
|
|
|
|
"""
|
|
|
|
same as .linx but returns a short url.
|
|
|
|
"""
|
|
|
|
linx(phenny, input, True)
|
|
|
|
lnx.rule = (['lnx'], r'(.*)')
|