diff --git a/bot.py b/bot.py index 9208061..63e4173 100755 --- a/bot.py +++ b/bot.py @@ -13,11 +13,12 @@ import thread import Queue import collections +sys.path += ['plugins'] # so 'import hook' works without duplication + import irc import yaml os.chdir(sys.path[0]) # do stuff relative to the installation directory -sys.path += ['plugins'] # so 'import hook' works without duplication class Bot(object): def __init__(self, nick, channel, network): @@ -68,7 +69,7 @@ print print 'Connecting to IRC' bot.irc = irc.irc(network, nick) bot.irc.join(channel) -bot.commandprefix = '^(?:\.|'+nick+'[:,]*\s*)' +bot.commandprefix = r'^(?:[.!]|'+nick+r'[:,]*\s*)' bot.persist_dir = os.path.abspath('persist') print 'Running main loop' diff --git a/plugins/iambuttbot.py b/plugins/iambuttbot.py index d836575..9114e94 100644 --- a/plugins/iambuttbot.py +++ b/plugins/iambuttbot.py @@ -11,6 +11,9 @@ def iambuttbot(bot, input): if input.nick.lower() != 'buttbot': return + if '@' in input or '#' in input: + return #prevent abuse + password = open('iambuttbot_password').readlines()[0].strip() status = input.inp if len(input.inp) <= 140 else input.inp[:137] + "..." data = urllib.urlencode({"status": status.encode('utf8')}) diff --git a/plugins/twitter.py b/plugins/twitter.py index b17c026..715bc35 100644 --- a/plugins/twitter.py +++ b/plugins/twitter.py @@ -19,7 +19,7 @@ def twitter(bot, input): try: tweet = etree.parse(url) except IOError: - return 'RoR: XTREME scalability (twitter is unresponsive)' + return 'RoR: XTREME scalability (twitter gave an error)' if tweet.find('error') is not None: return "can't find that username" diff --git a/plugins/urbandictionary.py b/plugins/urbandictionary.py new file mode 100644 index 0000000..b9bb0e1 --- /dev/null +++ b/plugins/urbandictionary.py @@ -0,0 +1,28 @@ +from lxml import html + +import urllib +import hook + +@hook.command('u') +@hook.command +def urban(inp): + '''.u/.urban -- looks up on urbandictionary.com''' + if not inp.strip(): + return urban.__doc__ + + url = 'http://www.urbandictionary.com/define.php?term=' + \ + urllib.quote(inp.strip(), safe='') + page = html.parse(url) + defs = page.xpath("//div[@class='definition']") + + print repr(defs[0].text_content()) + + if not defs: + return 'no definitions found' + + out = ' '.join(defs[0].text_content().split()) + + if len(out) > 400: + out = out[:out.rfind(' ', 0, 400)] + '...' + + return out