h/plugins/printerfact.py

21 lines
621 B
Python
Raw Normal View History

2015-11-03 01:18:44 +00:00
from util import hook
import requests, re, random
regex = re.compile(re.escape("cat"), re.IGNORECASE)
kittenrex = re.compile(re.escape("kitten"), re.IGNORECASE)
@hook.regex("PHP sadness$")
def php_fact(inp):
return "http://phpsadness.com/sad/" + str(random.randint(0,53))
@hook.regex("(.*) fact$")
def printerfact(inp, say=None):
2015-11-04 20:12:30 +00:00
if len(inp.group(1).split()) != 1:
2015-11-05 01:27:52 +00:00
return "I cowardly refuse to look that up"
2015-11-04 20:12:30 +00:00
2015-11-03 01:18:44 +00:00
r = requests.get('https://catfacts-api.appspot.com/api/facts?number=1')
fact = r.json()['facts'][0]
inp = inp.group(1)
return kittenrex.sub("baby "+ inp, regex.sub(inp, fact))