From b6d4c243526ee920a9cab1bb15bd45624dab5190 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Thu, 4 Jul 2024 16:39:37 +0200 Subject: [PATCH 1/2] add custom exception --- ntfy/exceptions.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 ntfy/exceptions.py diff --git a/ntfy/exceptions.py b/ntfy/exceptions.py new file mode 100644 index 0000000..8d749bb --- /dev/null +++ b/ntfy/exceptions.py @@ -0,0 +1,8 @@ +class SubscriptionError(Exception): + """Raised when an error occurs while subscribing to a ntfy topic.""" + + def __init__(self, http_response: dict) -> None: + self._http_message = http_response + self.message = self._http_message.get("error") + self.code = self._http_message.get("code") + super().__init__(self.message) From 37982b43c76b7f75d0ecd918425563c8b9a48cd2 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Fri, 5 Jul 2024 15:30:48 +0200 Subject: [PATCH 2/2] implement markdown rendering --- ntfy/bot.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ntfy/bot.py b/ntfy/bot.py index 918b9ab..1457e0a 100644 --- a/ntfy/bot.py +++ b/ntfy/bot.py @@ -2,6 +2,7 @@ import asyncio from html import escape import json from typing import Any, Dict, Tuple, List, Awaitable, Callable +import markdown from aiohttp import ClientTimeout from maubot import MessageEvent, Plugin @@ -639,9 +640,11 @@ class NtfyBot(Plugin): if click and not title: html_content += "%s%s" % ( emoji, escape(click), - escape(body).replace("\n", "
")) + markdown.markdown(escape(body)) + .replace("\n", "
")) else: - html_content += emoji + escape(body).replace("\n", "
") + html_content += (emoji + markdown.markdown(escape(body)) + .replace("\n", "
")) # add non-emoji tags if tags: