fixed reconnection logic, using the internal timer logic.
This commit is contained in:
parent
7cf4552ab8
commit
622ffa4825
1 changed files with 6 additions and 7 deletions
13
IRCBot.py
13
IRCBot.py
|
@ -52,7 +52,8 @@ class Bot(object):
|
||||||
def timer_setting_remove(self, timer):
|
def timer_setting_remove(self, timer):
|
||||||
self.timers.remove(timer)
|
self.timers.remove(timer)
|
||||||
self.del_setting("timer-%s" % timer.id)
|
self.del_setting("timer-%s" % timer.id)
|
||||||
def add_timer(self, event_name, delay, next_due=None, id=None, **kwargs):
|
def add_timer(self, event_name, delay, next_due=None, id=None, persist=True,
|
||||||
|
**kwargs):
|
||||||
timer = Timer.Timer(self, event_name, delay, next_due, **kwargs)
|
timer = Timer.Timer(self, event_name, delay, next_due, **kwargs)
|
||||||
if id:
|
if id:
|
||||||
timer.id = id
|
timer.id = id
|
||||||
|
@ -92,11 +93,8 @@ class Bot(object):
|
||||||
del self.servers[server.fileno()]
|
del self.servers[server.fileno()]
|
||||||
|
|
||||||
def reconnect(self, event):
|
def reconnect(self, event):
|
||||||
server = event["server"]
|
server_details = self.database.get_server(event["server_id"])
|
||||||
IRCServer.Server.__init__(server, server.id, server.target_hostname,
|
server = IRCServer.Server(*server_details, self)
|
||||||
server.port, server.password, server.ipv4, server.tls,
|
|
||||||
server.original_nickname, server.original_username,
|
|
||||||
server.original_realname, self)
|
|
||||||
if self.connect(server):
|
if self.connect(server):
|
||||||
self.servers[server.fileno()] = server
|
self.servers[server.fileno()] = server
|
||||||
else:
|
else:
|
||||||
|
@ -144,7 +142,8 @@ class Bot(object):
|
||||||
self.disconnect(server)
|
self.disconnect(server)
|
||||||
|
|
||||||
reconnect_delay = self.config.get("reconnect-delay", 10)
|
reconnect_delay = self.config.get("reconnect-delay", 10)
|
||||||
self.add_timer("reconnect", reconnect_delay, server=server)
|
self.add_timer("reconnect", reconnect_delay, None, None, False,
|
||||||
|
server_id=server.id)
|
||||||
|
|
||||||
print("disconnected from %s, reconnecting in %d seconds" % (
|
print("disconnected from %s, reconnecting in %d seconds" % (
|
||||||
str(server), reconnect_delay))
|
str(server), reconnect_delay))
|
||||||
|
|
Loading…
Reference in a new issue