From 2a03d0e065b499b562a6fefff27cf356a21561a2 Mon Sep 17 00:00:00 2001 From: Dafydd Crosby Date: Sat, 4 Jun 2011 09:36:47 -0600 Subject: [PATCH 1/2] Adding the halbot module --- modules/halbot.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 modules/halbot.py diff --git a/modules/halbot.py b/modules/halbot.py new file mode 100755 index 0000000..4605b5a --- /dev/null +++ b/modules/halbot.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python +""" +halbot.py - A module to connect to Halpy AI module +Copyright (c) 2011 Dafydd Crosby - http://www.dafyddcrosby.com + +Licensed under the Eiffel Forum License 2. +""" +from megahal import * +megahal = MegaHAL() + +def learn(phenny,input): + """Listens in on the room, gradually learning new phrases""" + megahal.learn(input.group()) +learn.rule = r'(.*)' +learn.priority = 'low' + +def megahalbot(phenny, input): + """Responds when someone mentions the bot nickname""" + # Clean the input so Halpy does not get confused + inp = input.group().replace(phenny.nick,'') + inp = inp.replace("\'","") + inp = inp.replace("\"","") + + phenny.say(input.nick + ": " + megahal.get_reply(inp)) + megahal.sync() +megahalbot.rule = r'(.*)$nickname(.*)' +megahalbot.priority = 'low' From a76e8bcc0d58182028e92342524e0ee6684700a3 Mon Sep 17 00:00:00 2001 From: Dafydd Crosby Date: Sat, 4 Jun 2011 09:38:11 -0600 Subject: [PATCH 2/2] Adding the slogan module --- modules/slogan.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 modules/slogan.py diff --git a/modules/slogan.py b/modules/slogan.py new file mode 100755 index 0000000..d8e2666 --- /dev/null +++ b/modules/slogan.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +""" +slogan.py - Phenny Slogan Module +Copyright (c) 2011 Dafydd Crosby - http://www.dafyddcrosby.com + +Licensed under the Eiffel Forum License 2. +""" + +import re +import web + +uri = 'http://www.sloganizer.net/en/outbound.php?slogan=%s' + +def sloganize(word): + bytes = web.get(uri % web.urllib.quote(word.encode('utf-8'))) + return bytes + +def slogan(phenny, input): + word = input.group(2) + slogan = sloganize(word) + + # Remove HTML tags + remove_tags = re.compile(r'<.*?>') + slogan = remove_tags.sub('', slogan) + + if not slogan: + phenny.say("Looks like an issue with sloganizer.net") + return + phenny.say(slogan) + +slogan.commands = ['slogan'] +slogan.example = '.slogan Granola' + +if __name__ == '__main__': + print __doc__.strip()