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
|
import irssi
import typing
import urllib
from urllib import request, parse
IRSSI = {
"author": "terminaldweller",
"contact": "https://terminaldweller.com",
"name": "gotify",
"description": "sends push notifications via gotify",
"license": "GPL3 or newer",
"url": "https://github.com/irssi/scripts.irssi.org",
}
def do_push(
content: bytes, target: bytes, nick: bytes, server: irssi.IrcServer
) -> None:
gotify_token = irssi.settings_get_str(b"gotify_token").decode("utf-8")
gotify_url = irssi.settings_get_str(b"gotify_server_url").decode("utf-8")
push_priosity = irssi.settings_get_int(b"gotify_push_priority")
form_fields = {
"title": "irssi",
"message": f"received message on {server.tag.decode('utf-8')} from {nick.decode('utf-8')} : {content.decode('utf-8')}",
"priority": push_priosity,
}
data = parse.urlencode(form_fields)
data = data.encode("utf-8")
url = gotify_url + f"/message?token={gotify_token}"
req = request.Request(url, data=data, method="POST")
request.urlopen(req)
def gotify_sig_handler(*args, **kwargs) -> None:
server = args[0]
msg = args[1]
nick = args[2]
address = args[3]
target = args[4]
do_push(msg, target, nick, server)
def run_on_script_load() -> None:
irssi.settings_add_bool(
b"misc",
b"transformer_debug",
False,
)
irssi.settings_add_str(
b"misc",
b"gotify_server_url",
b"https://gotify.terminaldweller.com",
)
irssi.settings_add_int(
b"misc",
b"gotify_push_priority",
10,
)
irssi.settings_add_str(
b"misc",
b"gotify_token",
b"",
)
irssi.signal_add(b"message private", gotify_sig_handler)
run_on_script_load()
|