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-11-26 22:04:36 -05:00
|
|
|
def get_title(phenny, url, channel):
|
2012-09-24 21:55:58 -04:00
|
|
|
""" Have linx retrieve the (augmented) title """
|
|
|
|
try:
|
2013-06-08 20:28:44 -04:00
|
|
|
return web.post("https://linx.li/vtluuggettitle", {'url': url, 'channel': channel, 'api_key': phenny.config.linx_api_key})
|
2012-09-24 21:55:58 -04:00
|
|
|
except:
|
|
|
|
return
|
|
|
|
|
|
|
|
|
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:
|
2013-06-08 20:28:44 -04:00
|
|
|
req = web.post("https://linx.li/vtluug", {'url': url, 'short': short, 'api_key': phenny.config.linx_api_key})
|
2013-06-09 01:27:24 -04:00
|
|
|
except (web.HTTPError, web.ConnectionError):
|
2012-06-02 01:17:09 -04:00
|
|
|
raise GrumbleError("THE INTERNET IS FUCKING BROKEN. Please try again later.")
|
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'(.*)')
|
|
|
|
|
|
|
|
|
2012-03-27 23:20:18 -04:00
|
|
|
def lines(phenny, input):
|
2012-03-28 19:12:09 -04:00
|
|
|
""".lines <nickname> (<today/yesterday/YYYYMMDD>) - Returns the number of lines a user posted on a specific date."""
|
2012-03-27 23:20:18 -04:00
|
|
|
|
2012-03-28 19:12:09 -04:00
|
|
|
if input.group(2):
|
|
|
|
info = input.group(2).split(" ")
|
|
|
|
|
2012-03-28 22:01:04 -04:00
|
|
|
if len(info) == 1:
|
2012-03-28 19:12:09 -04:00
|
|
|
nickname = info[0]
|
|
|
|
date = "today"
|
|
|
|
elif len(info) == 2:
|
|
|
|
nickname = info[0]
|
|
|
|
date = info[1]
|
|
|
|
else:
|
|
|
|
phenny.reply(".lines <nickname> (<today/yesterday/YYYYMMDD>) - Returns the number of lines a user posted on a specific date.")
|
|
|
|
return
|
2012-03-27 23:20:18 -04:00
|
|
|
|
2012-03-28 21:51:28 -04:00
|
|
|
else:
|
|
|
|
nickname = input.nick
|
|
|
|
date = "today"
|
2012-03-28 19:12:09 -04:00
|
|
|
|
2012-03-27 23:20:18 -04:00
|
|
|
try:
|
2013-06-08 20:28:44 -04:00
|
|
|
req = web.post("https://linx.li/vtluuglines", {'nickname': nickname, 'date': date, 'sender': input.nick, 'channel': input.sender, 'api_key': phenny.config.linx_api_key})
|
2013-06-09 01:27:24 -04:00
|
|
|
except (web.HTTPError, web.ConnectionError):
|
2012-06-02 01:17:09 -04:00
|
|
|
raise GrumbleError("THE INTERNET IS FUCKING BROKEN. Please try again later.")
|
2012-03-27 23:20:18 -04:00
|
|
|
|
|
|
|
phenny.reply(req)
|
|
|
|
|
2012-03-28 19:12:09 -04:00
|
|
|
lines.rule = (['lines'], r'(.*)')
|
2012-03-27 23:20:18 -04:00
|
|
|
|
2012-06-21 19:29:31 -04:00
|
|
|
|
|
|
|
def posted(phenny, input):
|
|
|
|
""".posted <message> - Checks if <message> has already been posted."""
|
|
|
|
|
|
|
|
message = input.group(2)
|
|
|
|
if not message:
|
|
|
|
phenny.say(".posted <message> - Checks if <message> has already been posted.")
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
2013-06-08 20:28:44 -04:00
|
|
|
req = web.post("https://linx.li/vtluugposted", {'message': message, 'sender': input.nick, 'channel': input.sender, 'api_key': phenny.config.linx_api_key})
|
2013-06-09 01:27:24 -04:00
|
|
|
except (web.HTTPError, web.ConnectionError):
|
2012-06-21 19:29:31 -04:00
|
|
|
raise GrumbleError("THE INTERNET IS FUCKING BROKEN. Please try again later.")
|
|
|
|
|
|
|
|
phenny.reply(req)
|
|
|
|
|
|
|
|
posted.rule = (['posted'], r'(.*)')
|
|
|
|
|
2012-06-27 19:33:09 -04:00
|
|
|
|
2012-03-27 23:20:18 -04:00
|
|
|
if __name__ == '__main__':
|
2012-06-27 19:33:09 -04:00
|
|
|
print(__doc__.strip())
|