bot: Try to reconnect after disconnect.
This commit is contained in:
parent
96df7f89b2
commit
f562d698b2
2 changed files with 12 additions and 1 deletions
|
@ -45,7 +45,6 @@ def main(arglist=None, stdout=sys.stdout, stderr=sys.stderr):
|
|||
if not config.ready():
|
||||
return 3
|
||||
bot = bot_mod.ForwardBot(config)
|
||||
bot.connect()
|
||||
bot.process()
|
||||
return 0
|
||||
|
||||
|
|
|
@ -28,9 +28,21 @@ class ForwardBot(slixmpp.ClientXMPP):
|
|||
self.register_plugin(xep.value)
|
||||
setattr(self, xep.name.lower(), self.plugin[xep.value])
|
||||
|
||||
self.add_event_handler('disconnected', self.handle_disconnected)
|
||||
self.add_event_handler('connection_failed', self.handle_connection_failed)
|
||||
self.add_event_handler('session_start', self.handle_start)
|
||||
self.add_event_handler('forward::queryhost', self.handle_queryhost)
|
||||
self.add_event_handler('message', self.handle_message)
|
||||
self.event('disconnected')
|
||||
|
||||
async def handle_disconnected(self, data=None):
|
||||
self.connect()
|
||||
|
||||
async def handle_connection_failed(self, error):
|
||||
# If the connection isn't going to be retried, or if the retry has
|
||||
# gotten excessive, give up.
|
||||
if not (0 < self.connect_loop_wait < self.max_retry_wait):
|
||||
self.loop.stop()
|
||||
|
||||
async def handle_start(self, event):
|
||||
self.send_presence()
|
||||
|
|
Loading…
Reference in a new issue