Don't add a server to bot.servers until it's connected
This commit is contained in:
parent
cb486d6122
commit
e89b4b6a83
2 changed files with 15 additions and 16 deletions
|
@ -24,7 +24,6 @@ class Bot(object):
|
|||
if not new_server.get_setting("connect", True):
|
||||
return
|
||||
self.events.on("new").on("server").call(server=new_server)
|
||||
self.servers[new_server.fileno()] = new_server
|
||||
if connect and new_server.get_setting("connect", True):
|
||||
self.connect(new_server)
|
||||
return new_server
|
||||
|
@ -35,15 +34,9 @@ class Bot(object):
|
|||
sys.stderr.write("Failed to connect to %s\n" % str(server))
|
||||
traceback.print_exc()
|
||||
return False
|
||||
self.servers[server.fileno()] = server
|
||||
self.poll.register(server.fileno(), select.EPOLLOUT)
|
||||
return True
|
||||
def connect_all(self):
|
||||
for server in self.servers.values():
|
||||
if server.get_setting("connect", True):
|
||||
if not self.connect(server):
|
||||
return False
|
||||
return True
|
||||
|
||||
def setup_timers(self, event):
|
||||
for setting, value in self.find_settings("timer-%"):
|
||||
id = setting.split("timer-", 1)[1]
|
||||
|
|
20
start.py
20
start.py
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import argparse, time
|
||||
import argparse, sys, time
|
||||
import IRCBot, Config, Database
|
||||
|
||||
def bool_input(s):
|
||||
|
@ -25,13 +25,19 @@ bot.config_object = config_object
|
|||
bot.args = args
|
||||
bot.modules.load_modules()
|
||||
|
||||
servers = database.get_servers()
|
||||
for server in servers:
|
||||
bot.add_server(*server)
|
||||
if len(bot.servers):
|
||||
server_details = database.get_servers()
|
||||
servers = []
|
||||
for server_detail in server_details:
|
||||
server = bot.add_server(*server_detail)
|
||||
if not server == None:
|
||||
servers.append(server)
|
||||
if len(servers):
|
||||
bot.events.on("boot").on("done").call()
|
||||
time.sleep(5)
|
||||
if bot.connect_all():
|
||||
for server in servers:
|
||||
if not bot.connect(server):
|
||||
sys.stderr.write("failed to connect to '%s', exiting\r\n" % (
|
||||
str(server)))
|
||||
sys.exit(1)
|
||||
bot.run()
|
||||
else:
|
||||
try:
|
||||
|
|
Loading…
Reference in a new issue