]> kaliko git repositories - sid.git/blobdiff - sid/sid.py
Improved help strings, add doc url
[sid.git] / sid / sid.py
index 729f7b65784e5c9828c8782dc0ec8a9ac3bc741b..2d64932838b3813da553e4fa6d5280f55d527335 100644 (file)
@@ -23,7 +23,7 @@ import traceback
 
 import slixmpp
 
-from sid import __url__
+from sid import __url__, __doc__
 
 
 def botcmd(*args, **kwargs):
@@ -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
 
@@ -123,9 +132,11 @@ class MUCBot(slixmpp.ClientXMPP):
         body = msg['body'].strip()
         if not body.startswith(MUCBot.prefix):
             return
-        if msg['from'] not in self.__seen:
-            self.log.warning('Will not handle message from unseen jid: %s', msg['from'])
-            #return
+        self.log.debug(msg['from'])
+        if msg['from'] not in self.__seen and msg['type'] == 'chat':
+            self.log.warning('Will not handle direct message'
+                             'from unseen jid: %s', msg['from'])
+            return
         args = body[1:].split()
         cmd = args.pop(0)
         if cmd not in self.commands:
@@ -148,7 +159,7 @@ class MUCBot(slixmpp.ClientXMPP):
         status = (pres['type'], pres['status'])
         self.__seen.update({nick: status})
 
-    def start(self, event):
+    async def start(self, event):
         """
         Process the session_start event.
 
@@ -159,7 +170,7 @@ class MUCBot(slixmpp.ClientXMPP):
         :param dict event: An empty dictionary. The session_start
                      event does not provide any additional data.
         """
-        self.get_roster()
+        await self.get_roster()
         self.send_presence()
         self.plugin['xep_0045'].join_muc(self.room,
                                          self.nick,
@@ -199,6 +210,7 @@ class MUCBot(slixmpp.ClientXMPP):
         Automatically assigned to the "help" command."""
         help_cmd = ('Type {}help <command name>'.format(self.prefix) +
                     ' to get more info about that specific command.\n\n' +
+                    f'DOC: {__doc__}\n' +
                     f'SRC: {__url__}')
         if not args:
             if self.__doc__: