This repository has been archived on 2025-02-10. You can view files and clone it, but cannot push or open issues or pull requests.
Files
beopen/server/modules/handler/outgoing.py
2025-02-10 12:37:33 +00:00

37 lines
1.0 KiB
Python

from modules.data.config import read as config_read
import requests
def post_slot(sio, sid=None):
if sid:
sio.emit("post_slot", room=sid)
else:
sio.emit("post_slot")
def send_ntfy(sio, info, sid, username):
url = config_read("notifications", "ntfyUrl")
if url == "https://ntfy.example.com":
return
user_id = sio.get_session(sid)['id']
nfty_topic = f"{username}-{user_id[:8]}"
if url[-1] != "/":
url = url + "/"
print(url + ntfy_topic)
message = info['message'].encode(encoding='utf-8')
title = info['title']
print(f"ntfy: {nfty_topic}")
try:
requests.post(f"{url}{ntfy_topic}", data=message, headers={"Title": title})
except:
log("WARN", "Notification server cannot be reached, ensure ntfy is up and that the provided url is correct")
def send_notification(sio, info, sid=None, username=None):
if sid:
send_ntfy(sio, info, sid, username)
sio.emit("notification", info, room=sid)
else:
sio.emit("notification", info)