-
Notifications
You must be signed in to change notification settings - Fork 4
/
pushover.py
89 lines (78 loc) · 3.85 KB
/
pushover.py
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
# Author: Caspar Clemens Mierau <[email protected]>
# Homepage: https://github.com/leitmedium/weechat-pushover
# Derived from: notifo
# Author: ochameau <poirot.alex AT gmail DOT com>
# Homepage: https://github.com/ochameau/weechat-notifo
# And from: notify
# Author: lavaramano <lavaramano AT gmail DOT com>
# Improved by: BaSh - <bash.lnx AT gmail DOT com>
# Ported to Weechat 0.3.0 by: Sharn - <sharntehnub AT gmail DOT com)
# And from: notifo_notify
# Author: SAEKI Yoshiyasu <[email protected]>
# Homepage: http://bitbucket.org/laclefyoshi/weechat/
#
# This plugin sends push notifications to your iPhone or Android smartphone
# by using pushover.net. In order to use it, please follow these steps:
#
# 1. Register an account at http://pushover.net
# 2. Create a new application at https://pushover.net/apps/build
# 3. Note the "token" for your new application (referenced as TOKEN later on)
# 4. From the Dashboard at https://pushover.net note your "User key" (referenced as USERKEY later on)
# 5. Install the pushover app on your iPhone/Android and login
# 6. put "pushover.py" to ~/.weechat/python
# 7. start the plugin with "/python load pushover.py"
# 8. Set user key and token by doing
# 9. /set plugins.var.python.pushover.user USERKEY
# 10. /set plugins.var.python.pushover.token TOKEN
#
# On security: This plugin does not use end-to-end-encryption. Please see
# the security related FAQ at pushover.net for details
#
# Requires Weechat 0.3.0
# Released under GNU GPL v2, see LICENSE file for details
#
# 2012-10-26, au <[email protected]>:
# version 0.1: merge notify.py and notifo_notify.py in order to avoid
# sending notifications when channel or private buffer is
# already opened
# 2013-06-27, au <[email protected]>:
# version 0.2: replace blocking curl call
# 2020-09-02, au <[email protected]>:
# version 0.3: update to python3 (replace urllib2 with new urllib)
# fix minor code glitches with python 3
import weechat, string, os, http.client, urllib
weechat.register("pushover", "Caspar Clemens Mierau <[email protected]>", "0.3", "GPL", "pushover: Send push notifications to you iPhone/Android about your private message and hiligts.", "", "")
settings = {
"user": "",
"token": "",
}
for option, default_value in list(settings.items()):
if weechat.config_get_plugin(option) == "":
weechat.prnt("", weechat.prefix("error") + "pushover: Please set option: %s" % option)
weechat.prnt("", "pushover: /set plugins.var.python.pushover.%s STRING" % option)
# Hook privmsg/hilights
weechat.hook_print('', '','', 1, 'notify_show', '')
# Functions
def notify_show(data, bufferp, uber_empty, tagsn, isdisplayed, ishilight, prefix, message):
#get local nick for buffer
mynick = weechat.buffer_get_string(bufferp,"localvar_nick")
# only notify if the private message was not sent by myself
if (weechat.buffer_get_string(bufferp, "localvar_type") == "private") and (prefix!=mynick):
show_notification(prefix, prefix, message)
elif ishilight:
buffer = (weechat.buffer_get_string(bufferp, "short_name") or
weechat.buffer_get_string(bufferp, "name"))
show_notification(buffer, prefix, message)
return weechat.WEECHAT_RC_OK
def show_notification(chan, nick, message):
PUSHOVER_USER = weechat.config_get_plugin("user")
PUSHOVER_API_SECRET = weechat.config_get_plugin("token")
if PUSHOVER_USER != "" and PUSHOVER_API_SECRET != "":
conn = http.client.HTTPSConnection("api.pushover.net:443")
conn.request("POST", "/1/messages.json",
urllib.parse.urlencode({
"token": PUSHOVER_API_SECRET,
"user": PUSHOVER_USER,
"title":'weechat: '+chan,
"message": '<'+nick+'> '+message,
}), { "Content-type": "application/x-www-form-urlencoded" })