From 7651cfca2c04921e5cbf3b6fbcdd040c172582fd Mon Sep 17 00:00:00 2001 From: kaliko Date: Wed, 6 May 2020 12:26:04 +0200 Subject: [PATCH] Some minor code formatting --- sid/sid.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/sid/sid.py b/sid/sid.py index b9c7df7..729f7b6 100644 --- a/sid/sid.py +++ b/sid/sid.py @@ -92,7 +92,8 @@ class MUCBot(slixmpp.ClientXMPP): # Discover bot internal command (ie. help) for name, value in inspect.getmembers(self): - if inspect.ismethod(value) and getattr(value, '_bot_command', False): + if inspect.ismethod(value) and \ + getattr(value, '_bot_command', False): name = getattr(value, '_bot_command_name') self.log.debug('Registered command: %s', name) self.commands[name] = value @@ -138,7 +139,8 @@ class MUCBot(slixmpp.ClientXMPP): reply = ''.join(traceback.format_exc()) self.log.exception('An error occurred processing: %s: %s', body, reply) if self.log.level < 10 and reply: - self.send_message(mto=msg['from'].bare, mbody=reply, mtype='groupchat') + self.send_message(mto=msg['from'].bare, mbody=reply, + mtype='groupchat') def _view(self, pres): """Track known nick""" @@ -160,28 +162,31 @@ class MUCBot(slixmpp.ClientXMPP): self.get_roster() self.send_presence() self.plugin['xep_0045'].join_muc(self.room, - self.nick, - # If a room password is needed, use: - # password=the_room_password, - wait=True) + self.nick, + # If a room password is needed, use: + # password=the_room_password, + wait=True) + + def register_bot_plugin(self, plugin_cls): + """Registers plugin, takes a class, the method instanciates the plugin :param `sid.plugin.Plugin` plugin_cls: A :py:obj:`sid.plugin.Plugin` class """ self.plugins.append(plugin_cls(self)) for name, value in inspect.getmembers(self.plugins[-1]): - if inspect.ismethod(value) and getattr(value, '_bot_command', - False): + if inspect.ismethod(value) and \ + getattr(value, '_bot_command', False): name = getattr(value, '_bot_command_name') self.log.debug('Registered command: %s', name) self.commands[name] = value def foreach_plugin(self, method, *args, **kwds): for plugin in self.plugins: - self.log.debug('shuting down %s', plugin.__str__) + self.log.debug('calling %s for %s', method, plugin) getattr(plugin, method)(*args, **kwds) def shutdown_plugins(self): - # TODO: why can't use event session_end|disconnected? + # TODO: also use event session_end|disconnected? self.log.info('shuting down') for plugin in self.plugins: self.log.debug('shuting down %s', plugin) -- 2.39.2