2022-12-18 16:55:09 +00:00
|
|
|
import requests
|
|
|
|
|
|
|
|
from core.util import logs
|
|
|
|
|
|
|
|
NTFY_URL = "https://ntfy.sh"
|
|
|
|
|
|
|
|
log = logs.get_logger(__name__)
|
|
|
|
|
|
|
|
|
2022-12-18 17:21:52 +00:00
|
|
|
# Actual function to send a message to a topic
|
|
|
|
def _sendmsg(msg, title=None, priority=None, tags=None, url=None, topic=None):
|
2022-12-18 16:55:09 +00:00
|
|
|
headers = {"Title": "Fisk"}
|
|
|
|
if title:
|
|
|
|
headers["Title"] = title
|
|
|
|
if priority:
|
|
|
|
headers["Priority"] = priority
|
|
|
|
if tags:
|
|
|
|
headers["Tags"] = tags
|
|
|
|
requests.post(
|
2022-12-18 17:21:52 +00:00
|
|
|
f"{url}/{topic}",
|
2022-12-18 16:55:09 +00:00
|
|
|
data=msg,
|
|
|
|
headers=headers,
|
|
|
|
)
|
2022-12-18 17:21:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Sendmsg helper to send a message to a user's notification settings
|
|
|
|
def sendmsg(user, *args, **kwargs):
|
|
|
|
notification_settings = user.get_notification_settings()
|
|
|
|
if notification_settings.ntfy_url is None:
|
|
|
|
url = NTFY_URL
|
|
|
|
else:
|
|
|
|
url = notification_settings.ntfy_url
|
|
|
|
|
|
|
|
if notification_settings.ntfy_topic is None:
|
|
|
|
# No topic set, so don't send
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
topic = notification_settings.ntfy_topic
|
|
|
|
|
|
|
|
_sendmsg(*args, **kwargs, url=url, topic=topic)
|