phenny-1/modules/linx.py

96 lines
2.6 KiB
Python
Raw Normal View History

2012-03-27 23:20:18 -04:00
#!/usr/bin/python3
"""
linx.py - linx.li tools
author: mutantmonkey <mutantmonkey@mutantmonkey.in>, andreim <andreim@andreim.net>
"""
from urllib.error import HTTPError
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-03-27 23:20:18 -04:00
def linx(phenny, input):
""".linx <url> - Upload a URL to linx.li."""
url = input.group(2)
if not url:
phenny.reply("No URL provided. CAN I HAS?")
return
try:
req = web.post("http://linx.li/vtluug", {'url': url})
except (HTTPError, IOError):
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'(.*)')
def lines(phenny, input):
""".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
if input.group(2):
info = input.group(2).split(" ")
2012-03-28 22:01:04 -04:00
if len(info) == 1:
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-27 23:20:18 -04:00
try:
2012-03-28 21:51:28 -04:00
req = web.post("http://linx.li/vtluuglines", {'nickname': nickname, 'date': date, 'sender': input.nick})
2012-03-27 23:20:18 -04:00
except (HTTPError, IOError):
raise GrumbleError("THE INTERNET IS FUCKING BROKEN. Please try again later.")
2012-03-27 23:20:18 -04:00
phenny.reply(req)
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:
req = web.post("http://linx.li/vtluugposted", {'message': message, 'sender': input.nick})
except (HTTPError, IOError):
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
def postedlink(url):
""" helper method for gettitle() """
try:
req = web.post("http://linx.li/vtluugpostedurl", {'url': url})
except:
req = ""
return req
postedlink.channels = ['#vtluug']
2012-03-27 23:20:18 -04:00
if __name__ == '__main__':
2012-06-27 19:33:09 -04:00
print(__doc__.strip())