Full completed project
This commit is contained in:
36
server/modules/handler/outgoing.py
Normal file
36
server/modules/handler/outgoing.py
Normal file
@@ -0,0 +1,36 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user