diff --git a/bot.py b/bot.py index a79fc7b..b9de4cc 100755 --- a/bot.py +++ b/bot.py @@ -6,18 +6,12 @@ channel = "#cobol" import sys import os -import glob -import re -import thread import Queue -import collections sys.path += ['plugins'] # so 'import hook' works without duplication +os.chdir(sys.path[0]) # do stuff relative to the installation directory import irc -import yaml - -os.chdir(sys.path[0]) # do stuff relative to the installation directory class Bot(object): diff --git a/core/main.py b/core/main.py index 147c7e2..c15e525 100644 --- a/core/main.py +++ b/core/main.py @@ -1,3 +1,5 @@ +import thread + class Input(object): def __init__(self, raw, prefix, command, diff --git a/core/reload.py b/core/reload.py index 40066bd..a468546 100644 --- a/core/reload.py +++ b/core/reload.py @@ -1,3 +1,6 @@ +import glob +import collections + if 'plugin_mtimes' not in globals(): mtimes = {} diff --git a/irc.py b/irc.py index 0a3144e..e8a09dd 100644 --- a/irc.py +++ b/irc.py @@ -52,10 +52,10 @@ class crlf_tcp(asynchat.async_chat): self.iqueue.put(decode(line)) self.buffer = '' -irc_prefix_re = re.compile(r'(.*?) (.*?) (.*)') -irc_noprefix_re = re.compile(r'()(.*?) (.*)') -irc_param_re = re.compile(r'(?:^|(?<= ))(:.*|[^ ]+)') -irc_netmask_re = re.compile(r':?([^!@]*)!?([^@]*)@?(.*)') +irc_prefix_rem = re.compile(r'(.*?) (.*?) (.*)').match +irc_noprefix_rem = re.compile(r'()(.*?) (.*)').match +irc_netmask_rem = re.compile(r':?([^!@]*)!?([^@]*)@?(.*)').match +irc_param_ref = re.compile(r'(?:^|(?<= ))(:.*|[^ ]+)').findall class irc(object): @@ -76,11 +76,11 @@ class irc(object): while True: msg = self.conn.iqueue.get() if msg.startswith(":"): #has a prefix - prefix, command, params = irc_prefix_re.match(msg).groups() + prefix, command, params = irc_prefix_rem(msg).groups() else: - prefix, command, params = irc_noprefix_re.match(msg).groups() - nick, user, host = irc_netmask_re.match(prefix).groups() - paramlist = irc_param_re.findall(params) + prefix, command, params = irc_noprefix_rem(msg).groups() + nick, user, host = irc_netmask_rem(prefix).groups() + paramlist = irc_param_ref(params) lastparam = "" if paramlist and paramlist[-1].startswith(':'): lastparam = paramlist[-1][1:] diff --git a/plugins/hook.py b/plugins/hook.py index e27bc23..9b3d4ae 100644 --- a/plugins/hook.py +++ b/plugins/hook.py @@ -46,7 +46,10 @@ def command(func=None, hook=None, **kwargs): if func is not None: args['name'] = func if hook is not None: - args['hook'] = hook + if isinstance(hook, list): + args['hook'] = '(?:' + '|'.join(hook) + ')' + else: + args['hook'] = hook args.update(kwargs) return command_wrapper else: diff --git a/plugins/urbandictionary.py b/plugins/urbandictionary.py index 755b132..5d12bd7 100644 --- a/plugins/urbandictionary.py +++ b/plugins/urbandictionary.py @@ -1,11 +1,10 @@ -import lxml +from lxml import html import urllib import hook -@hook.command('u') -@hook.command +@hook.command(['u', 'urban']) def urban(inp): '''.u/.urban -- looks up on urbandictionary.com''' if not inp.strip(): @@ -13,7 +12,7 @@ def urban(inp): url = 'http://www.urbandictionary.com/define.php?term=' + \ urllib.quote(inp.strip(), safe='') - page = lxml.html.parse(url) + page = html.parse(url) defs = page.xpath("//div[@class='definition']") if not defs: