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):
|
if not new_server.get_setting("connect", True):
|
||||||
return
|
return
|
||||||
self.events.on("new").on("server").call(server=new_server)
|
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):
|
if connect and new_server.get_setting("connect", True):
|
||||||
self.connect(new_server)
|
self.connect(new_server)
|
||||||
return new_server
|
return new_server
|
||||||
|
@ -35,15 +34,9 @@ class Bot(object):
|
||||||
sys.stderr.write("Failed to connect to %s\n" % str(server))
|
sys.stderr.write("Failed to connect to %s\n" % str(server))
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return False
|
return False
|
||||||
|
self.servers[server.fileno()] = server
|
||||||
self.poll.register(server.fileno(), select.EPOLLOUT)
|
self.poll.register(server.fileno(), select.EPOLLOUT)
|
||||||
return True
|
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):
|
def setup_timers(self, event):
|
||||||
for setting, value in self.find_settings("timer-%"):
|
for setting, value in self.find_settings("timer-%"):
|
||||||
id = setting.split("timer-", 1)[1]
|
id = setting.split("timer-", 1)[1]
|
||||||
|
|
22
start.py
22
start.py
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import argparse, time
|
import argparse, sys, time
|
||||||
import IRCBot, Config, Database
|
import IRCBot, Config, Database
|
||||||
|
|
||||||
def bool_input(s):
|
def bool_input(s):
|
||||||
|
@ -25,14 +25,20 @@ bot.config_object = config_object
|
||||||
bot.args = args
|
bot.args = args
|
||||||
bot.modules.load_modules()
|
bot.modules.load_modules()
|
||||||
|
|
||||||
servers = database.get_servers()
|
server_details = database.get_servers()
|
||||||
for server in servers:
|
servers = []
|
||||||
bot.add_server(*server)
|
for server_detail in server_details:
|
||||||
if len(bot.servers):
|
server = bot.add_server(*server_detail)
|
||||||
|
if not server == None:
|
||||||
|
servers.append(server)
|
||||||
|
if len(servers):
|
||||||
bot.events.on("boot").on("done").call()
|
bot.events.on("boot").on("done").call()
|
||||||
time.sleep(5)
|
for server in servers:
|
||||||
if bot.connect_all():
|
if not bot.connect(server):
|
||||||
bot.run()
|
sys.stderr.write("failed to connect to '%s', exiting\r\n" % (
|
||||||
|
str(server)))
|
||||||
|
sys.exit(1)
|
||||||
|
bot.run()
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
if bool_input("no servers found, add one?"):
|
if bool_input("no servers found, add one?"):
|
||||||
|
|
Loading…
Reference in a new issue