Only automatically reconnect to a server when we don't already have a server

with the same ID (to make reconnection work)
This commit is contained in:
jesopo 2018-11-05 20:33:45 +00:00
parent 3cb9baeec3
commit ce3b319bee

View file

@ -134,10 +134,6 @@ class Bot(object):
event["timer"].redo() event["timer"].redo()
def reconnect(self, server_id: int, connection_params: typing.Optional[ def reconnect(self, server_id: int, connection_params: typing.Optional[
utils.irc.IRCConnectionParameters]=None) -> bool: utils.irc.IRCConnectionParameters]=None) -> bool:
old_server = self.get_server(server_id)
if old_server:
self.disconnect(old_server)
server = self.add_server(server_id, False, connection_params) server = self.add_server(server_id, False, connection_params)
if self.connect(server): if self.connect(server):
self.servers[server.fileno()] = server self.servers[server.fileno()] = server
@ -208,13 +204,14 @@ class Bot(object):
self._events.on("server.disconnect").call(server=server) self._events.on("server.disconnect").call(server=server)
self.disconnect(server) self.disconnect(server)
reconnect_delay = self.config.get("reconnect-delay", 10) if not self.get_server(server.id):
self._timers.add("reconnect", reconnect_delay, reconnect_delay = self.config.get("reconnect-delay", 10)
server_id=server.id, self._timers.add("reconnect", reconnect_delay,
connection_params=server.connection_params) server_id=server.id,
connection_params=server.connection_params)
print("disconnected from %s, reconnecting in %d seconds" % ( self.log.info(
str(server), reconnect_delay)) "Disconnected from %s, reconnecting in %d seconds",
[str(server), reconnect_delay])
elif server.waiting_send() and server.throttle_done(): elif server.waiting_send() and server.throttle_done():
self.register_both(server) self.register_both(server)