fix autorejoin

This commit is contained in:
Ryan Hitchman 2009-11-17 17:27:55 -07:00
parent 55f4b5aa95
commit baa623a4ac
3 changed files with 16 additions and 11 deletions

20
bot.py
View File

@ -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')

View File

@ -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,

View File

@ -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':