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
|
|
|
|
2009-04-19 11:18:27 +00:00
|
|
|
class Input(object):
|
|
|
|
|
2009-11-18 00:19:26 +00:00
|
|
|
def __init__(self, conn, raw, prefix, command,
|
2009-04-19 11:18:27 +00:00
|
|
|
params, nick, user, host, paraml, msg):
|
2009-11-18 00:19:26 +00:00
|
|
|
self.conn = conn
|
2009-11-19 00:39:27 +00:00
|
|
|
self.server = conn.server
|
2009-04-19 11:18:27 +00:00
|
|
|
self.raw = raw
|
|
|
|
self.prefix = prefix
|
|
|
|
self.command = command
|
|
|
|
self.params = params
|
|
|
|
self.nick = nick
|
|
|
|
self.user = user
|
|
|
|
self.host = host
|
|
|
|
self.paraml = paraml
|
|
|
|
self.msg = msg
|
|
|
|
self.chan = paraml[0]
|
2009-11-18 00:19:26 +00:00
|
|
|
if self.chan == conn.nick:
|
2009-04-19 11:18:27 +00:00
|
|
|
self.chan = nick
|
|
|
|
|
|
|
|
def say(self, msg):
|
2009-11-18 00:19:26 +00:00
|
|
|
self.conn.msg(self.chan, msg)
|
2009-04-19 11:18:27 +00:00
|
|
|
|
|
|
|
def reply(self, msg):
|
2009-11-19 01:42:37 +00:00
|
|
|
self.say(self.nick + ': ' + msg)
|
|
|
|
|
2009-11-19 03:20:59 +00:00
|
|
|
def pm(self, msg):
|
|
|
|
self.conn.msg(self.nick, msg)
|
|
|
|
|
2009-11-19 01:42:37 +00:00
|
|
|
|
|
|
|
def run(func, input):
|
|
|
|
ac = func.func_code.co_argcount
|
|
|
|
if ac == 2:
|
|
|
|
out = func(bot, input)
|
|
|
|
elif ac == 1:
|
|
|
|
out = func(input.inp)
|
|
|
|
if out is not None:
|
|
|
|
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))
|