diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 6183ee9..747d4a3 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -12,6 +12,9 @@ frdmn puffrfish nasonfish +We are using code from the following projects: +./plugins/mlia.py - https://github.com/infinitylabs/UguuBot + Special Thanks: Rmmh (created skybot!) lahwran (for his advice and stuff I stole from his skybot fork!) diff --git a/plugins/mlia.py b/plugins/mlia.py new file mode 100644 index 0000000..4d36393 --- /dev/null +++ b/plugins/mlia.py @@ -0,0 +1,32 @@ +# Plugin by Infinity - + +from util import hook, http +import random + +mlia_cache = [] + + +def refresh_cache(): + "gets a page of random MLIAs and puts them into a dictionary " + url = 'http://mylifeisaverage.com/%s' % random.randint(1, 11000) + soup = http.get_soup(url) + + for story in soup.find_all('div', {'class': 'story '}): + mlia_id = story.find('span', {'class': 'left'}).a.text + mlia_text = story.find('div', {'class': 'sc'}).text.strip() + mlia_cache.append((mlia_id, mlia_text)) + +# do an initial refresh of the cache +refresh_cache() + + +@hook.command(autohelp=False) +def mlia(inp, reply=None): + "mlia -- Gets a random quote from MyLifeIsAverage.com." + # grab the last item in the mlia cache and remove it + id, text = mlia_cache.pop() + # reply with the mlia we grabbed + reply('(%s) %s' % (id, text)) + # refresh mlia cache if its getting empty + if len(mlia_cache) < 3: + refresh_cache()