2009-04-19 11:42:48 +00:00
|
|
|
import thread
|
2009-04-23 02:49:06 +00:00
|
|
|
import traceback
|
2009-04-19 11:42:48 +00:00
|
|
|
|
2010-02-02 04:42:34 +00:00
|
|
|
class Input(dict):
|
|
|
|
def __init__(self, conn, raw, prefix, command, params,
|
|
|
|
nick, user, host, paraml, msg):
|
|
|
|
|
|
|
|
chan = paraml[0].lower()
|
|
|
|
if chan == conn.nick: # is a PM
|
|
|
|
chan = nick
|
|
|
|
|
|
|
|
def say(msg):
|
|
|
|
conn.msg(chan, msg)
|
|
|
|
|
|
|
|
def reply(msg):
|
|
|
|
conn.msg(chan, nick + ': ' + msg)
|
|
|
|
|
|
|
|
def pm(msg):
|
|
|
|
conn.msg(nick, msg)
|
|
|
|
|
|
|
|
dict.__init__(self, conn=conn, raw=raw, prefix=prefix, command=command,
|
|
|
|
params=params, nick=nick, user=user, host=host,
|
|
|
|
paraml=paraml, msg=msg, server=conn.server, chan=chan,
|
|
|
|
say=say, reply=reply, pm=pm, bot=bot)
|
|
|
|
self.__dict__ = self # permits attribute access to values
|
2009-11-19 03:20:59 +00:00
|
|
|
|
2009-11-19 01:42:37 +00:00
|
|
|
|
|
|
|
def run(func, input):
|
2010-02-02 04:42:34 +00:00
|
|
|
args = func._skybot_args
|
|
|
|
if args:
|
|
|
|
if 'db' in args:
|
|
|
|
input['db'] = get_db_connection(input['server'])
|
|
|
|
if 0 in args:
|
|
|
|
out = func(input['inp'], **input)
|
|
|
|
else:
|
|
|
|
kw = dict((key, input[key]) for key in args if key in input)
|
|
|
|
out = func(input['inp'], **kw)
|
|
|
|
else:
|
|
|
|
out = func(input['inp'])
|
2009-11-19 01:42:37 +00:00
|
|
|
if out is not None:
|
2010-02-02 04:42:34 +00:00
|
|
|
input['reply'](unicode(out))
|
2009-04-19 11:18:27 +00:00
|
|
|
|
|
|
|
|
2009-11-18 00:19:26 +00:00
|
|
|
def main(conn, out):
|
2009-11-19 00:39:27 +00:00
|
|
|
for csig, func, args in bot.plugs['tee']:
|
|
|
|
input = Input(conn, *out)
|
|
|
|
func._iqueue.put((bot, input))
|
2009-04-19 11:18:27 +00:00
|
|
|
for csig, func, args in (bot.plugs['command'] + bot.plugs['event']):
|
2009-11-18 00:19:26 +00:00
|
|
|
input = Input(conn, *out)
|
2009-04-19 11:18:27 +00:00
|
|
|
for fsig, sieve in bot.plugs['sieve']:
|
|
|
|
try:
|
|
|
|
input = sieve(bot, input, func, args)
|
|
|
|
except Exception, e:
|
2009-04-23 02:49:06 +00:00
|
|
|
print 'sieve error',
|
|
|
|
traceback.print_exc(Exception)
|
2009-04-19 11:18:27 +00:00
|
|
|
input = None
|
|
|
|
if input == None:
|
|
|
|
break
|
|
|
|
if input == None:
|
|
|
|
continue
|
2009-11-19 01:42:37 +00:00
|
|
|
thread.start_new_thread(run, (func, input))
|