]> kaliko git repositories - sid.git/commitdiff
Handles disconnections
authorkaliko <kaliko@azylum.org>
Thu, 1 Oct 2020 11:45:32 +0000 (13:45 +0200)
committerkaliko <kaliko@azylum.org>
Thu, 1 Oct 2020 11:45:32 +0000 (13:45 +0200)
sid/sid.py

index a62c7e46fd14fd7c0d61875cad45f8b650da802b..a3ca555e891602c839ababae1097635676a08e75 100644 (file)
@@ -90,6 +90,9 @@ class MUCBot(slixmpp.ClientXMPP):
         self.add_event_handler('message', self.message)
         self.add_event_handler('got_online', self._view)
 
+        # Handles disconnection
+        self.add_event_handler('disconnected', self.disconn)
+
         # Discover bot internal command (ie. help)
         for name, value in inspect.getmembers(self):
             if inspect.ismethod(value) and \
@@ -110,6 +113,12 @@ class MUCBot(slixmpp.ClientXMPP):
         self.log.setLevel(log_level)
         self.log.debug('set logger, log level : %s', log_level)
 
+    def disconn(self, event):
+        """disconnected handler"""
+        msg = ": %s" % event if event else "‽"
+        self.log.info('Disconnected from server%s', msg)
+        self.connect()
+
     def message(self, msg):
         """Messages handler