Ejemplo n.º 1
0
 def do_notify(self, message, fro):
     body = get_body_from_message_stanza(message, use_xhtml=False)
     if not body:
         return
     command_str = self.config.get('command', '').strip()
     if not command_str:
         self.api.information(
             'No notification command was provided in the configuration file',
             'Warning')
         return
     command = [
         arg % {
             'body': body.replace('\n', ' '),
             'from': fro
         } for arg in shlex.split(command_str)
     ]
     self.core.exec_command(command)
     after_command_str = self.config.get('after_command', '').strip()
     if not after_command_str:
         return
     after_command = [
         arg % {
             'body': body.replace('\n', ' '),
             'from': fro
         } for arg in shlex.split(after_command_str)
     ]
     delayed_event = DelayedEvent(self.config.get('delay', 1),
                                  self.core.exec_command, after_command)
     self.api.add_timed_event(delayed_event)
Ejemplo n.º 2
0
    def create_delayed_event(self, _, *args, **kwargs):
        """
        Create a delayed event, but do not schedule it;
        :py:func:`~PluginAPI.add_timed_event` must be used for that.

        A delayed event is a timed event with a delay from the time
        this function is called (instead of a datetime).

        :param int delay: The number of seconds to schedule the execution
        :param function callback: The handler that will be executed
        :param args: Optional arguments passed to the handler.
        :return: The created event.
        :rtype: :py:class:`timed_events.DelayedEvent`
        """
        return DelayedEvent(*args, **kwargs)