/usr/share/weechat/python/nma.py is in weechat-scripts 20120603-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | # Author: sitaktif <romainchossart AT gmail DOT com>
# This plugin calls the pynma bindings via python when somebody says your nickname, sends you a query, etc.
# Requires Weechat 0.3.0
# To make it work, you need to get pynma.py from NotifyMyAndroid website or on github - https://github.com/uskr/pynma . Just put it in the same folder as the script)
# Released under GNU GPL v2
# Heavily based on lavaramano's script "notify.py" v. 0.0.5
#
# Todo: Do not send my own messages on query channels
# 2012-01-05 Ac-town
# version 1.0.2: Fixes a few typos I ran into and adds only_away. Only_away only sends notifications if you are marked away.
# 2011-09-19, sitaktif
# version 1.0.1: Corrected a bug with debug functions
# 2011-07-22, sitaktif
# version 1.0.0: Initial release
import weechat
weechat.register("nma", "sitaktif", "1.0.2", "GPL2", "nma: Receive notifications on NotifyMyAndroid app.", "", "")
# script options
settings = {
"apikey" : "",
"nick_separator_left" : "<",
"nick_separator_right" : "> ",
"emergency_hilights" : "-1",
"emergency_priv_msg" : "0",
"activated" : "on",
"show_hilights" : "on",
"show_priv_msg" : "on",
"smart_notification" : "off",
"only_away" : "off",
"debug" : "off",
}
#severity_t = {
#"emergency" : 2,
#"high" : 1,
#"normal" : 0,
#"moderate" : -1,
#"low": -2
#}
"""
Init
"""
for option, default_value in settings.items():
if weechat.config_get_plugin(option) == "":
weechat.config_set_plugin(option, default_value)
if weechat.config_get_plugin("apikey") == "":
weechat.prnt("", "You haven't set your API key. Use /set plugins.var.python.nma.apikey \"you_nma_api_token\" to fix that.")
"""
Hooks
"""
# Hook command
weechat.hook_command("nma", "Activate NotifyMyAndroid notifications", "on | off",
"on : Activate notifications\n"
"off : Desactivate notifications\n",
"on || off",
"nma_cmd_cb", "");
# Hook privmsg/hilights
weechat.hook_print("", "irc_privmsg", "", 1, "notify_show", "")
from pynma import PyNMA
p = PyNMA()
p.addkey(weechat.config_get_plugin("apikey"))
"""
Helpers
"""
def _debug(text):
if weechat.config_get_plugin("debug") == "on":
weechat.prnt("", text)
"""
Functions
"""
def nma_cmd_cb(data, buffer, args):
if args in ["on", "off"]:
weechat.prnt("", "Notify My Android notifications %sactivated"
% ("de" if args == "off" else ""))
weechat.config_set_plugin('activated', args)
else:
weechat.prnt("", "Error: Invalid argument")
weechat.command("", "/help nma")
return weechat.WEECHAT_RC_OK
def notify_show(data, bufferp, uber_empty, tagsn, isdisplayed,
ishilight, prefix, message):
"""Sends highlighted message to be printed on notification"""
if weechat.config_get_plugin('activated') == "off":
return weechat.WEECHAT_RC_OK
if (weechat.config_get_plugin('smart_notification') == "on" and
bufferp == weechat.current_buffer()):
return weechat.WEECHAT_RC_OK
if (weechat.config_get_plugin('only_away') == "on" and not
weechat.buffer_get_string(bufferp, 'localvar_away')):
return weechat.WEECHAT_RC_OK
ret = None
notif_body = "%s%s%s%s" % (weechat.config_get_plugin('nick_separator_left'),
prefix, weechat.config_get_plugin('nick_separator_right'), message)
# PM (query)
if (weechat.buffer_get_string(bufferp, "localvar_type") == "private" and
weechat.config_get_plugin('show_priv_msg') == "on"):
ret = show_notification("IRC private message",
notif_body, int(weechat.config_get_plugin("emergency_priv_msg")))
_debug("Message sent: %s. Return: %s." % (notif_body, ret))
# Highlight (your nick is quoted)
elif (ishilight == "1" and
weechat.config_get_plugin('show_hilights') == "on"):
bufname = (weechat.buffer_get_string(bufferp, "short_name") or
weechat.buffer_get_string(bufferp, "name"))
ret = show_notification(bufname, notif_body,
int(weechat.config_get_plugin("emergency_hilights")))
_debug("Message sent: %s. Return: %s." % (notif_body, ret))
if ret is not None:
_debug(str(ret))
return weechat.WEECHAT_RC_OK
def show_notification(chan, message, priority):
global p
return p.push("[IRC]", chan, message, '', priority, batch_mode=False)
# vim: autoindent expandtab smarttab shiftwidth=4
|