fix autorejoin
This commit is contained in:
parent
55f4b5aa95
commit
baa623a4ac
8
bot.py
8
bot.py
|
@ -25,14 +25,18 @@ print 'Connecting to IRC'
|
||||||
|
|
||||||
bot.conns = {}
|
bot.conns = {}
|
||||||
|
|
||||||
|
try:
|
||||||
for connection in bot.config['connections']:
|
for connection in bot.config['connections']:
|
||||||
for name, conf in connection.iteritems():
|
for name, conf in connection.iteritems():
|
||||||
if name in bot.conns:
|
if name in bot.conns:
|
||||||
print 'ERROR: more than one connection named "%s"' % name
|
print 'ERROR: more than one connection named "%s"' % name
|
||||||
raise ValueError
|
raise ValueError
|
||||||
bot.conns[name] = irc(conf['server'], conf['nick'])
|
bot.conns[name] = irc(conf['server'], conf['nick'], channels=conf['channels'])
|
||||||
for channel in conf.get('channels', []):
|
for channel in conf['channels']:
|
||||||
bot.conns[name].join(channel)
|
bot.conns[name].join(channel)
|
||||||
|
except Exception, e:
|
||||||
|
print 'ERROR: malformed config file', Exception, e
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
bot.persist_dir = os.path.abspath('persist')
|
bot.persist_dir = os.path.abspath('persist')
|
||||||
|
|
||||||
|
|
|
@ -62,9 +62,10 @@ class irc(object):
|
||||||
"handles the IRC protocol"
|
"handles the IRC protocol"
|
||||||
#see the docs/ folder for more information on the 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.server = server
|
||||||
self.conn = crlf_tcp(server, port)
|
self.conn = crlf_tcp(server, port)
|
||||||
|
self.channels = channels
|
||||||
thread.start_new_thread(self.conn.run, ())
|
thread.start_new_thread(self.conn.run, ())
|
||||||
self.out = Queue.Queue() #responses from the server are placed here
|
self.out = Queue.Queue() #responses from the server are placed here
|
||||||
# format: [rawline, prefix, command, params,
|
# format: [rawline, prefix, command, params,
|
||||||
|
|
|
@ -4,8 +4,8 @@ from util import hook
|
||||||
@hook.event('KICK INVITE')
|
@hook.event('KICK INVITE')
|
||||||
def rejoin(bot, input):
|
def rejoin(bot, input):
|
||||||
if input.command == 'KICK':
|
if input.command == 'KICK':
|
||||||
if input.paraml[1] == bot.bot.nick:
|
if input.paraml[1] == input.conn.nick:
|
||||||
if input.paraml[0] == bot.bot.channel:
|
if input.paraml[0] in input.conn.channels:
|
||||||
bot.join(input.paraml[0])
|
bot.join(input.paraml[0])
|
||||||
|
|
||||||
if input.command == 'INVITE':
|
if input.command == 'INVITE':
|
||||||
|
|
Loading…
Reference in New Issue