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-03-01 02:32:41 +00:00
|
|
|
|
2010-03-06 19:41:54 +00:00
|
|
|
print thread.stack_size(1024 * 512) # reduce vm size
|
|
|
|
|
|
|
|
|
2010-02-02 04:42:34 +00:00
|
|
|
class Input(dict):
|
|
|
|
def __init__(self, conn, raw, prefix, command, params,
|
|
|
|
nick, user, host, paraml, msg):
|
2010-03-01 02:32:41 +00:00
|
|
|
|
2010-02-02 04:42:34 +00:00
|
|
|
chan = paraml[0].lower()
|
2010-03-01 02:32:41 +00:00
|
|
|
if chan == conn.nick: # is a PM
|
2010-02-02 04:42:34 +00:00
|
|
|
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,
|
2010-03-01 02:32:41 +00:00
|
|
|
paraml=paraml, msg=msg, server=conn.server, chan=chan,
|
2010-02-02 04:42:34 +00:00
|
|
|
say=say, reply=reply, pm=pm, bot=bot)
|
2010-03-05 05:04:57 +00:00
|
|
|
|
|
|
|
def __getattr__(self, key):
|
|
|
|
return self[key]
|
|
|
|
|
2010-03-05 05:15:29 +00:00
|
|
|
def __setattr__(self, key, value):
|
2010-03-05 05:04:57 +00:00
|
|
|
self[key] = value
|
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))
|