Commit 4bc21580 authored by louiz’'s avatar louiz’

Improve the simple_notify plugin and the daemon to execute a command to clean...

Improve the simple_notify plugin and the daemon to execute a command to clean the notification and to execute the remote commands through sh -c, letting us use pipes and redirections. Also adds the highlight event for plugin, and make the simple_notify plugin use it as well.
parent 737c6aae
......@@ -17,14 +17,31 @@ default), and fill it like this:
command = notify-send -i /path/to/poezio/data/poezio_80.png "New message from %(from)s" "%(body)s"
You can put any command, instead of this one. You can also use the
command = echo %{from}s\> %{body}s >> some.fifo
delay = 3
after_command echo = >> some.fifo
You can put any command, instead of these ones. You can also use the
special keywords _%(from)s_ and _%(body)s_ that will be replaced
directly in the command line by the author of the message, and the body.
The example shown above will display something like this:
The first example shown above will display something like this:
image:../../images/simple_notify_example.png["Simple notify example",
title="Simple notify example"]
The second example will first write the author and the message in a
fifo, that fifo can locally be read by some other program (was tested
with the xmobar PipeReader command, which displays what is read from a
fifo into a status bar. Be careful, you have two different fifos in
that case, don’t get confused). The delay and command_after options
are used to erase/delete/kill the notification after a certain
delay. In our example it is used to display an empty message in our
xmobar, erasing the notification after 3 seconds.
NOTE: If you set the _exec_remote_ option to _true_ into the
link:../configure.html[main configuration file], the command will be executed
remotely (as explained in the link:link.html[/link help]).
from plugin import BasePlugin
from xhtml import clean_text, get_body_from_message_stanza
from timed_events import DelayedEvent
class Plugin(BasePlugin):
def init(self):
self.add_event_handler('private_msg', self.on_private_msg)
self.add_event_handler('conversation_msg', self.on_conversation_msg)
self.add_event_handler('highlight', self.on_highlight)
def on_private_msg(self, message, tab):
fro = message['from']
self.do_notify(message, fro)
def on_highlight(self, message, tab):
fro = message['from'].resource
self.do_notify(message, fro)
def on_conversation_msg(self, message, tab):
fro = message['from'].bare
self.do_notify(message, fro)
......@@ -23,3 +29,8 @@ class Plugin(BasePlugin):
self.core.information('No notification command was provided in the configuration file', 'Warning')
self.core.exec_command(command % {'body':body, 'from':fro})
after_command = self.config.get('after_command', '').strip()
if not after_command:
delayed_event = DelayedEvent(self.config.get('delay', 1), self.core.exec_command, after_command % {'body':body, 'from':fro})
......@@ -1445,7 +1445,8 @@ class Core(object):
body = xhtml.get_body_from_message_stanza(message)
if body:
date = date if delayed == True else None
tab.add_message(body, date, nick_from, history=True if date else False)
if tab.add_message(body, date, nick_from, history=True if date else False):'highlight', message, tab)
if tab is self.current_tab():
tab.info_header.refresh(tab, tab.text_win)
......@@ -40,7 +40,7 @@ class Executor(threading.Thread):
def run(self):'executing %s' % (self.command.strip(),))
command = shlex.split(self.command)
command = shlex.split('sh -c "%s"' % self.command)
def main():
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment