From baa623a4ac234c991669a38733b0650275117060 Mon Sep 17 00:00:00 2001 From: Ryan Hitchman Date: Tue, 17 Nov 2009 17:27:55 -0700 Subject: [PATCH] fix autorejoin --- bot.py | 20 ++++++++++++-------- core/irc.py | 3 ++- plugins/misc.py | 4 ++-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/bot.py b/bot.py index 4a74297..dfe7f78 100755 --- a/bot.py +++ b/bot.py @@ -25,14 +25,18 @@ print 'Connecting to IRC' bot.conns = {} -for connection in bot.config['connections']: - for name, conf in connection.iteritems(): - if name in bot.conns: - print 'ERROR: more than one connection named "%s"' % name - raise ValueError - bot.conns[name] = irc(conf['server'], conf['nick']) - for channel in conf.get('channels', []): - bot.conns[name].join(channel) +try: + for connection in bot.config['connections']: + for name, conf in connection.iteritems(): + if name in bot.conns: + print 'ERROR: more than one connection named "%s"' % name + raise ValueError + bot.conns[name] = irc(conf['server'], conf['nick'], channels=conf['channels']) + for channel in conf['channels']: + bot.conns[name].join(channel) +except Exception, e: + print 'ERROR: malformed config file', Exception, e + sys.exit() bot.persist_dir = os.path.abspath('persist') diff --git a/core/irc.py b/core/irc.py index aa7a66f..ce9ff7b 100644 --- a/core/irc.py +++ b/core/irc.py @@ -62,9 +62,10 @@ class irc(object): "handles the IRC protocol" #see the docs/ folder for more information on the protocol - def __init__(self, server, nick, port=6667): + def __init__(self, server, nick, port=6667, channels=[]): self.server = server self.conn = crlf_tcp(server, port) + self.channels = channels thread.start_new_thread(self.conn.run, ()) self.out = Queue.Queue() #responses from the server are placed here # format: [rawline, prefix, command, params, diff --git a/plugins/misc.py b/plugins/misc.py index a2f3030..7b39ec9 100644 --- a/plugins/misc.py +++ b/plugins/misc.py @@ -4,8 +4,8 @@ from util import hook @hook.event('KICK INVITE') def rejoin(bot, input): if input.command == 'KICK': - if input.paraml[1] == bot.bot.nick: - if input.paraml[0] == bot.bot.channel: + if input.paraml[1] == input.conn.nick: + if input.paraml[0] in input.conn.channels: bot.join(input.paraml[0]) if input.command == 'INVITE':