Commit 60a98b20 authored by Sindre Sorhus's avatar Sindre Sorhus Committed by Sébastien Helleu

notification_center.py 1.5.0: add options "channels" and "tags"

parent a167c539
......@@ -9,7 +9,7 @@ from pync import Notifier
SCRIPT_NAME = 'notification_center'
SCRIPT_AUTHOR = 'Sindre Sorhus <[email protected]>'
SCRIPT_VERSION = '1.4.0'
SCRIPT_VERSION = '1.5.0'
SCRIPT_LICENSE = 'MIT'
SCRIPT_DESC = 'Pass highlights and private messages to the macOS Notification Center'
WEECHAT_ICON = os.path.expanduser('~/.weechat/weechat.png')
......@@ -25,13 +25,15 @@ DEFAULT_OPTIONS = {
'activate_bundle_id': 'com.apple.Terminal',
'ignore_old_messages': 'off',
'ignore_current_buffer_messages': 'off',
'channels': '',
'tags': '',
}
for key, val in DEFAULT_OPTIONS.items():
if not weechat.config_is_set_plugin(key):
weechat.config_set_plugin(key, val)
weechat.hook_print('', 'irc_privmsg', '', 1, 'notify', '')
weechat.hook_print('', 'irc_privmsg,' + weechat.config_get_plugin('tags'), '', 1, 'notify', '')
def notify(data, buffer, date, tags, displayed, highlight, prefix, message):
# ignore if it's yourself
......@@ -55,13 +57,20 @@ def notify(data, buffer, date, tags, displayed, highlight, prefix, message):
# passing `None` or `''` still plays the default sound so we pass a lambda instead
sound = weechat.config_get_plugin('sound_name') if weechat.config_get_plugin('sound') == 'on' else lambda:_
activate_bundle_id = weechat.config_get_plugin('activate_bundle_id')
if weechat.config_get_plugin('show_highlights') == 'on' and int(highlight):
channel = weechat.buffer_get_string(buffer, 'localvar_channel')
channel_whitelist = weechat.config_get_plugin('channels').split(',')
channel = weechat.buffer_get_string(buffer, 'localvar_channel')
if channel in channel_whitelist:
if weechat.config_get_plugin('show_message_text') == 'on':
Notifier.notify(message, title='%s %s' % (prefix, channel), sound=sound, appIcon=WEECHAT_ICON, activate=activate_bundle_id)
else:
Notifier.notify('In %s by %s' % (channel, prefix), title='Channel Activity', sound=sound, appIcon=WEECHAT_ICON, activate=activate_bundle_id)
elif weechat.config_get_plugin('show_highlights') == 'on' and int(highlight):
if weechat.config_get_plugin('show_message_text') == 'on':
Notifier.notify(message, title='%s %s' % (prefix, channel), sound=sound, appIcon=WEECHAT_ICON, activate=activate_bundle_id)
else:
Notifier.notify('In %s by %s' % (channel, prefix), title='Highlighted Message', sound=sound, appIcon=WEECHAT_ICON, activate=activate_bundle_id)
elif weechat.config_get_plugin('show_private_message') == 'on' and 'notify_private' in tags:
elif weechat.config_get_plugin('show_private_message') == 'on' and 'irc_privmsg' in tags and 'notify_private' in tags:
if weechat.config_get_plugin('show_message_text') == 'on':
Notifier.notify(message, title='%s [private]' % prefix, sound=sound, appIcon=WEECHAT_ICON, activate=activate_bundle_id)
else:
......
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