def botcmd(*args, **kwargs):
"""Decorator for bot command functions
def botcmd(*args, **kwargs):
"""Decorator for bot command functions
self.add_event_handler('message', self.message)
self.add_event_handler('got_online', self._view)
self.add_event_handler('message', self.message)
self.add_event_handler('got_online', self._view)
# 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
self.log.setLevel(log_level)
self.log.debug('set logger, log level : %s', log_level)
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()
+
- 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
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})
:param dict event: An empty dictionary. The session_start
event does not provide any additional data.
"""
:param dict event: An empty dictionary. The session_start
event does not provide any additional data.
"""
- 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]):
: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:
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) +