X-Git-Url: https://git.kaliko.me/?p=sid.git;a=blobdiff_plain;f=sid%2Fsid.py;h=d412ac4ad65d362b0427cdafb35a2f6485e8e7bd;hp=f475bd4f9224cdbe9e9739c00c5519cf1491389b;hb=16a1747dce0c01b1659cb5e287254bcd434000ed;hpb=fc4c29184d12f086ea64721c2de6aa003383442b diff --git a/sid/sid.py b/sid/sid.py index f475bd4..d412ac4 100644 --- a/sid/sid.py +++ b/sid/sid.py @@ -23,6 +23,8 @@ import traceback import slixmpp +from sid import __url__ + def botcmd(*args, **kwargs): """Decorator for bot command functions @@ -90,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 @@ -136,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""" @@ -144,7 +148,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. @@ -155,31 +159,34 @@ 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, - # 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) @@ -191,8 +198,8 @@ class MUCBot(slixmpp.ClientXMPP): Automatically assigned to the "help" command.""" help_cmd = ('Type {}help '.format(self.prefix) + - ' to get more info about that specific command.\n\n'+ - 'SRC: http://git.kaliko.me/sid.git') + ' to get more info about that specific command.\n\n' + + f'SRC: {__url__}') if not args: if self.__doc__: description = self.__doc__.strip()