]> git.99rst.org Git - irssi-scripts.irssi.org.git/commitdiff
added a new python script, gotify.py. sends a push notification to gotify for priv...
authorterminaldweller <redacted>
Wed, 6 Sep 2023 07:37:46 +0000 (11:07 +0330)
committerAilin Nemui <redacted>
Sun, 24 Sep 2023 21:46:04 +0000 (23:46 +0200)
scripts/gotify.py [new file with mode: 0644]

diff --git a/scripts/gotify.py b/scripts/gotify.py
new file mode 100644 (file)
index 0000000..93580ea
--- /dev/null
@@ -0,0 +1,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()
git clone https://git.99rst.org/PROJECT