- """Decorator for bot command functions"""
+ """Decorator for bot command functions
+
+ :param bool hidden: is the command hidden in global help
+ :param str name: command name, default to decorated function name
+ """
def decorate(func, hidden=False, name=None):
setattr(func, '_bot_command', True)
def decorate(func, hidden=False, name=None):
setattr(func, '_bot_command', True)
+ """
+ :param str jid: jid to log with
+ :param str password: jid password
+ :param str room: conference room to join
+ :param str nick: Nickname to use in the room
+ """
+
+ #: Class attribute to define bot's command prefix
+ #:
+ #: Defaults to "!"
prefix = '!'
def __init__(self, jid, password, room, nick, log_file=None,
log_level=logging.INFO):
super(MUCBot, self).__init__(jid, password)
prefix = '!'
def __init__(self, jid, password, room, nick, log_file=None,
log_level=logging.INFO):
super(MUCBot, self).__init__(jid, password)
- 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
+ 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
# the bot establishes its connection with the server
# The session_start event will be triggered when
# the bot establishes its connection with the server
# Discover bot internal command (ie. help)
for name, value in inspect.getmembers(self):
# 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
name = getattr(value, '_bot_command_name')
self.log.debug('Registered command: %s', name)
self.commands[name] = value
if msg['type'] not in ('groupchat', 'chat'):
self.log.warning('Unhandled message')
return
if msg['type'] not in ('groupchat', 'chat'):
self.log.warning('Unhandled message')
return
reply = ''.join(traceback.format_exc())
self.log.exception('An error occurred processing: %s: %s', body, reply)
if self.log.level < 10 and reply:
reply = ''.join(traceback.format_exc())
self.log.exception('An error occurred processing: %s: %s', body, reply)
if self.log.level < 10 and reply:
status = (pres['type'], pres['status'])
self.__seen.update({nick: status})
status = (pres['type'], pres['status'])
self.__seen.update({nick: status})
- 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
- def register_bot_plugin(self, plugin_class):
- self.plugins.append(plugin_class(self))
+ :param `sid.plugin.Plugin` plugin_cls: A :py:obj:`sid.plugin.Plugin` class
+ """
+ self.plugins.append(plugin_cls(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
def foreach_plugin(self, method, *args, **kwds):
for plugin in self.plugins:
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:
getattr(plugin, method)(*args, **kwds)
def shutdown_plugins(self):
getattr(plugin, method)(*args, **kwds)
def shutdown_plugins(self):
self.log.info('shuting down')
for plugin in self.plugins:
self.log.debug('shuting down %s', plugin)
self.log.info('shuting down')
for plugin in self.plugins:
self.log.debug('shuting down %s', plugin)
Automatically assigned to the "help" command."""
help_cmd = ('Type {}help <command name>'.format(self.prefix) +
Automatically assigned to the "help" command."""
help_cmd = ('Type {}help <command name>'.format(self.prefix) +