misc cleaning, fix urban
This commit is contained in:
parent
e284ed75ba
commit
322205eb92
8
bot.py
8
bot.py
|
@ -6,18 +6,12 @@ channel = "#cobol"
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import glob
|
|
||||||
import re
|
|
||||||
import thread
|
|
||||||
import Queue
|
import Queue
|
||||||
import collections
|
|
||||||
|
|
||||||
sys.path += ['plugins'] # so 'import hook' works without duplication
|
sys.path += ['plugins'] # so 'import hook' works without duplication
|
||||||
|
os.chdir(sys.path[0]) # do stuff relative to the installation directory
|
||||||
|
|
||||||
import irc
|
import irc
|
||||||
import yaml
|
|
||||||
|
|
||||||
os.chdir(sys.path[0]) # do stuff relative to the installation directory
|
|
||||||
|
|
||||||
|
|
||||||
class Bot(object):
|
class Bot(object):
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import thread
|
||||||
|
|
||||||
class Input(object):
|
class Input(object):
|
||||||
|
|
||||||
def __init__(self, raw, prefix, command,
|
def __init__(self, raw, prefix, command,
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
import glob
|
||||||
|
import collections
|
||||||
|
|
||||||
if 'plugin_mtimes' not in globals():
|
if 'plugin_mtimes' not in globals():
|
||||||
mtimes = {}
|
mtimes = {}
|
||||||
|
|
||||||
|
|
16
irc.py
16
irc.py
|
@ -52,10 +52,10 @@ class crlf_tcp(asynchat.async_chat):
|
||||||
self.iqueue.put(decode(line))
|
self.iqueue.put(decode(line))
|
||||||
self.buffer = ''
|
self.buffer = ''
|
||||||
|
|
||||||
irc_prefix_re = re.compile(r'(.*?) (.*?) (.*)')
|
irc_prefix_rem = re.compile(r'(.*?) (.*?) (.*)').match
|
||||||
irc_noprefix_re = re.compile(r'()(.*?) (.*)')
|
irc_noprefix_rem = re.compile(r'()(.*?) (.*)').match
|
||||||
irc_param_re = re.compile(r'(?:^|(?<= ))(:.*|[^ ]+)')
|
irc_netmask_rem = re.compile(r':?([^!@]*)!?([^@]*)@?(.*)').match
|
||||||
irc_netmask_re = re.compile(r':?([^!@]*)!?([^@]*)@?(.*)')
|
irc_param_ref = re.compile(r'(?:^|(?<= ))(:.*|[^ ]+)').findall
|
||||||
|
|
||||||
|
|
||||||
class irc(object):
|
class irc(object):
|
||||||
|
@ -76,11 +76,11 @@ class irc(object):
|
||||||
while True:
|
while True:
|
||||||
msg = self.conn.iqueue.get()
|
msg = self.conn.iqueue.get()
|
||||||
if msg.startswith(":"): #has a prefix
|
if msg.startswith(":"): #has a prefix
|
||||||
prefix, command, params = irc_prefix_re.match(msg).groups()
|
prefix, command, params = irc_prefix_rem(msg).groups()
|
||||||
else:
|
else:
|
||||||
prefix, command, params = irc_noprefix_re.match(msg).groups()
|
prefix, command, params = irc_noprefix_rem(msg).groups()
|
||||||
nick, user, host = irc_netmask_re.match(prefix).groups()
|
nick, user, host = irc_netmask_rem(prefix).groups()
|
||||||
paramlist = irc_param_re.findall(params)
|
paramlist = irc_param_ref(params)
|
||||||
lastparam = ""
|
lastparam = ""
|
||||||
if paramlist and paramlist[-1].startswith(':'):
|
if paramlist and paramlist[-1].startswith(':'):
|
||||||
lastparam = paramlist[-1][1:]
|
lastparam = paramlist[-1][1:]
|
||||||
|
|
|
@ -46,7 +46,10 @@ def command(func=None, hook=None, **kwargs):
|
||||||
if func is not None:
|
if func is not None:
|
||||||
args['name'] = func
|
args['name'] = func
|
||||||
if hook is not None:
|
if hook is not None:
|
||||||
args['hook'] = hook
|
if isinstance(hook, list):
|
||||||
|
args['hook'] = '(?:' + '|'.join(hook) + ')'
|
||||||
|
else:
|
||||||
|
args['hook'] = hook
|
||||||
args.update(kwargs)
|
args.update(kwargs)
|
||||||
return command_wrapper
|
return command_wrapper
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
import lxml
|
from lxml import html
|
||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
import hook
|
import hook
|
||||||
|
|
||||||
|
|
||||||
@hook.command('u')
|
@hook.command(['u', 'urban'])
|
||||||
@hook.command
|
|
||||||
def urban(inp):
|
def urban(inp):
|
||||||
'''.u/.urban <phrase> -- looks up <phrase> on urbandictionary.com'''
|
'''.u/.urban <phrase> -- looks up <phrase> on urbandictionary.com'''
|
||||||
if not inp.strip():
|
if not inp.strip():
|
||||||
|
@ -13,7 +12,7 @@ def urban(inp):
|
||||||
|
|
||||||
url = 'http://www.urbandictionary.com/define.php?term=' + \
|
url = 'http://www.urbandictionary.com/define.php?term=' + \
|
||||||
urllib.quote(inp.strip(), safe='')
|
urllib.quote(inp.strip(), safe='')
|
||||||
page = lxml.html.parse(url)
|
page = html.parse(url)
|
||||||
defs = page.xpath("//div[@class='definition']")
|
defs = page.xpath("//div[@class='definition']")
|
||||||
|
|
||||||
if not defs:
|
if not defs:
|
||||||
|
|
Loading…
Reference in New Issue