]> kaliko git repositories - sid.git/blobdiff - sid/sid.py
Fixed docstrings indentation
[sid.git] / sid / sid.py
index 373209d2e6797c6040c27510b8e492d11745635e..5b85fd15211315113fc83a3907938ba74d623e70 100644 (file)
@@ -2,7 +2,7 @@
 
 # Copyright (C) 2007-2012 Thomas Perl <thp.io/about>
 # Copyright (C) 2010, 2011 AnaĆ«l Verrier <elghinn@free.fr>
-# Copyright (C) 2014-2015 kaliko <kaliko@azylum.org>
+# Copyright (C) 2014, 2015, 2020 kaliko <kaliko@azylum.org>
 
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -21,7 +21,7 @@ import inspect
 import logging
 import traceback
 
-import sleekxmpp
+import slixmpp
 
 
 def botcmd(*args, **kwargs):
@@ -41,12 +41,12 @@ def botcmd(*args, **kwargs):
         return lambda func: decorate(func, **kwargs)
 
 
-class MUCBot(sleekxmpp.ClientXMPP):
+class MUCBot(slixmpp.ClientXMPP):
 
     prefix = '!'
 
     def __init__(self, jid, password, room, nick, log_file=None,
-            log_level=logging.INFO):
+                 log_level=logging.INFO):
         super(MUCBot, self).__init__(jid, password)
 
         self.log = logging.getLogger(__package__)
@@ -58,6 +58,7 @@ class MUCBot(sleekxmpp.ClientXMPP):
         self.__seen = dict()
         self.register_plugin('xep_0030') # Service Discovery
         self.register_plugin('xep_0045') # Multi-User Chat
+        self.register_plugin('xep_0071') # xhtml-im
         self.register_plugin('xep_0199') # self Ping
 
         # The session_start event will be triggered when
@@ -83,13 +84,15 @@ class MUCBot(sleekxmpp.ClientXMPP):
         log_fd = open(log_file, 'w') if log_file else None
         chandler = logging.StreamHandler(log_fd)
         formatter = logging.Formatter(
-            '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
+            '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
+            )
         chandler.setFormatter(formatter)
         self.log.addHandler(chandler)
         self.log.setLevel(log_level)
         self.log.debug('set logger, log level : %s', log_level)
 
     def message(self, msg):
+        """Messages handler"""
         if msg['type'] not in ('groupchat', 'chat'):
             self.log.warning('Unhandled message')
             return
@@ -117,6 +120,7 @@ class MUCBot(sleekxmpp.ClientXMPP):
                 self.send_message(mto=msg['from'].bare, mbody=reply, mtype='groupchat')
 
     def _view(self, pres):
+        """Track known nick"""
         nick = pres['from']
         status = (pres['type'], pres['status'])
         self.__seen.update({nick: status})
@@ -136,7 +140,7 @@ class MUCBot(sleekxmpp.ClientXMPP):
         """
         self.get_roster()
         self.send_presence()
-        self.plugin['xep_0045'].joinMUC(self.room,
+        self.plugin['xep_0045'].join_muc(self.room,
                                         self.nick,
                                         # If a room password is needed, use:
                                         # password=the_room_password,
@@ -169,7 +173,8 @@ class MUCBot(sleekxmpp.ClientXMPP):
 
         Automatically assigned to the "help" command."""
         help_cmd = ('Type {}help <command name>'.format(self.prefix) +
-                    ' to get more info about that specific command.')
+                    ' to get more info about that specific command.\n\n'+
+                    'SRC: http://git.kaliko.me/sid.git')
         if not args:
             if self.__doc__:
                 description = self.__doc__.strip()
@@ -188,7 +193,8 @@ class MUCBot(sleekxmpp.ClientXMPP):
             text = '{}\n\n{}'.format(description, usage)
         else:
             if args[0] in self.commands.keys():
-                text = self.commands[args[0]].__doc__.strip() or 'undocumented'
+                text = self.commands[args[0]].__doc__ or 'undocumented'
+                text = inspect.cleandoc(text)
             else:
                 text = 'That command is not defined.'
         if message['type'] == 'groupchat':