weechat/python/autoload/notify.py @ 579af8ed8dcb

More
author Steve Losh <steve@stevelosh.com>
date Sat, 15 Dec 2018 16:57:13 -0500
parents a1d399ef7d54
children (none)
import weechat, subprocess

SCRIPT_NAME = 'notify'
SCRIPT_AUTHOR = 'Steve Losh <steve@stevelosh.com>'
SCRIPT_VERSION = '0.0.1'
SCRIPT_LICENSE = 'MIT'
SCRIPT_DESC = 'notify-send for weechat'

weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, '', '')

weechat.hook_print('', 'irc_privmsg', '', 1, 'notify', '')

def _notify(text):
    subprocess.call(['notify-send', text])

def notify(data, buffer, date, tags, displayed, highlight, prefix, message):
    # ignore if it's yourself
    own_nick = weechat.buffer_get_string(buffer, 'localvar_nick')

    if prefix == own_nick or prefix == ('@%s' % own_nick):
        return weechat.WEECHAT_RC_OK

    if int(highlight):
        channel = weechat.buffer_get_string(buffer, 'localvar_channel')
        _notify('%s %s\n%s' % (prefix, channel, message))
    elif 'notify_private' in tags:
        _notify('%s [PM]\n%s' % (prefix, message))

    return weechat.WEECHAT_RC_OK