Added ability to notify new messages in MUCs
This commit is contained in:
parent
bfbd61c423
commit
558ef877cb
1 changed files with 27 additions and 0 deletions
|
@ -43,6 +43,17 @@ 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
|
delay. In our example it is used to display an empty message in our
|
||||||
xmobar, erasing the notification after 3 seconds.
|
xmobar, erasing the notification after 3 seconds.
|
||||||
|
|
||||||
|
Third example:
|
||||||
|
|
||||||
|
.. code-block:: ini
|
||||||
|
|
||||||
|
[simple_notify]
|
||||||
|
command = notify-send -i /path/to/poezio/data/poezio_80.png "New message from %(from)s" "%(body)s"
|
||||||
|
muc_too = true
|
||||||
|
|
||||||
|
If present and set to ``True``, the ``muc_too`` option will also trigger a
|
||||||
|
notification when a new message arrives on a Multi User Chat you've joined.
|
||||||
|
|
||||||
.. note:: If you set the :term:`exec_remote` option to ``true`` into the
|
.. note:: If you set the :term:`exec_remote` option to ``true`` into the
|
||||||
main configuration file, the command will be executed remotely
|
main configuration file, the command will be executed remotely
|
||||||
(as explained in the :ref:`link-plugin` plugin help).
|
(as explained in the :ref:`link-plugin` plugin help).
|
||||||
|
@ -62,17 +73,25 @@ Options defined
|
||||||
after_command
|
after_command
|
||||||
Command to run after :term:`delay`. You probably want to clean up things.
|
Command to run after :term:`delay`. You probably want to clean up things.
|
||||||
|
|
||||||
|
muc_too
|
||||||
|
Boolean indicating whether new messages in Multi User Chat rooms should
|
||||||
|
trigger a notification or not.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from plugin import BasePlugin
|
from plugin import BasePlugin
|
||||||
from xhtml import get_body_from_message_stanza
|
from xhtml import get_body_from_message_stanza
|
||||||
from timed_events import DelayedEvent
|
from timed_events import DelayedEvent
|
||||||
import shlex
|
import shlex
|
||||||
|
import common
|
||||||
|
|
||||||
|
|
||||||
class Plugin(BasePlugin):
|
class Plugin(BasePlugin):
|
||||||
def init(self):
|
def init(self):
|
||||||
self.api.add_event_handler('private_msg', self.on_private_msg)
|
self.api.add_event_handler('private_msg', self.on_private_msg)
|
||||||
self.api.add_event_handler('conversation_msg', self.on_conversation_msg)
|
self.api.add_event_handler('conversation_msg', self.on_conversation_msg)
|
||||||
|
if self.config.get('muc_too', False):
|
||||||
|
self.api.add_event_handler('muc_msg', self.on_muc_msg)
|
||||||
self.api.add_event_handler('highlight', self.on_highlight)
|
self.api.add_event_handler('highlight', self.on_highlight)
|
||||||
|
|
||||||
def on_private_msg(self, message, tab):
|
def on_private_msg(self, message, tab):
|
||||||
|
@ -87,6 +106,14 @@ class Plugin(BasePlugin):
|
||||||
fro = message['from'].bare
|
fro = message['from'].bare
|
||||||
self.do_notify(message, fro)
|
self.do_notify(message, fro)
|
||||||
|
|
||||||
|
def on_muc_msg(self, message, tab):
|
||||||
|
fro = message['from'].bare
|
||||||
|
# Prevent old messages to be notified
|
||||||
|
# find_delayed_tag(message) returns (True, the datetime) or
|
||||||
|
# (False, None)
|
||||||
|
if not common.find_delayed_tag(message)[0]:
|
||||||
|
self.do_notify(message, fro)
|
||||||
|
|
||||||
def do_notify(self, message, fro):
|
def do_notify(self, message, fro):
|
||||||
body = get_body_from_message_stanza(message, use_xhtml=False)
|
body = get_body_from_message_stanza(message, use_xhtml=False)
|
||||||
if not body:
|
if not body:
|
||||||
|
|
Loading…
Reference in a new issue