phenny-1/modules/linx.py

41 lines
1021 B
Python
Raw Normal View History

2012-03-27 23:20:18 -04:00
#!/usr/bin/python3
"""
linx.py - linx.li tools
author: andreim <andreim@andreim.net>
author: mutantmonkey <mutantmonkey@mutantmonkey.in>
2012-03-27 23:20:18 -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
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:
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):
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'(.*)')
def lnx(phenny, input):
"""
same as .linx but returns a short url.
"""
linx(phenny, input, True)
lnx.rule = (['lnx'], r'(.*)')