Begin adding platform support
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import requests
|
||||
import aiohttp
|
||||
|
||||
from core.util import logs
|
||||
|
||||
@@ -8,7 +8,7 @@ log = logs.get_logger(__name__)
|
||||
|
||||
|
||||
# Actual function to send a message to a topic
|
||||
def raw_sendmsg(msg, title=None, priority=None, tags=None, url=None, topic=None):
|
||||
async def raw_sendmsg(msg, title=None, priority=None, tags=None, url=None, topic=None):
|
||||
if url is None:
|
||||
url = NTFY_URL
|
||||
headers = {"Title": "Pluto"}
|
||||
@@ -18,15 +18,17 @@ def raw_sendmsg(msg, title=None, priority=None, tags=None, url=None, topic=None)
|
||||
headers["Priority"] = priority
|
||||
if tags:
|
||||
headers["Tags"] = tags
|
||||
requests.post(
|
||||
f"{url}/{topic}",
|
||||
data=msg,
|
||||
headers=headers,
|
||||
)
|
||||
cast = {
|
||||
"headers": headers,
|
||||
"data": msg,
|
||||
}
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.post(f"{url}/{topic}", **cast) as response:
|
||||
response = await response.content()
|
||||
|
||||
|
||||
# Sendmsg helper to send a message to a user's notification settings
|
||||
def sendmsg(user, *args, **kwargs):
|
||||
async def sendmsg(user, *args, **kwargs):
|
||||
notification_settings = user.get_notification_settings()
|
||||
|
||||
if notification_settings.ntfy_topic is None:
|
||||
@@ -35,4 +37,4 @@ def sendmsg(user, *args, **kwargs):
|
||||
else:
|
||||
topic = notification_settings.ntfy_topic
|
||||
|
||||
raw_sendmsg(*args, **kwargs, url=notification_settings.ntfy_url, topic=topic)
|
||||
await raw_sendmsg(*args, **kwargs, url=notification_settings.ntfy_url, topic=topic)
|
||||
|
||||
Reference in New Issue
Block a user