weechat-old/python/autoload/notify.py @ a9f1df02501f

More
author Steve Losh <steve@stevelosh.com>
date Sat, 21 Oct 2023 15:01:32 -0400
parents weechat/python/autoload/notify.py@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