From 254a7d341a3b2c7618610a2dbf12c5c3bf747c0c Mon Sep 17 00:00:00 2001 From: Davide Marcoli <69892203+davidemarcoli@users.noreply.github.com> Date: Mon, 14 Oct 2024 14:25:22 +0200 Subject: [PATCH] refactor: remove unnecessary checks for notifications (#781) --- src/utils/notifications.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/utils/notifications.py b/src/utils/notifications.py index 5563a7fe..105ed415 100644 --- a/src/utils/notifications.py +++ b/src/utils/notifications.py @@ -23,20 +23,19 @@ logger.debug(f"Failed to add service URL {service_url}: {e}") -def notification(item: MediaItem, title: str, body: str) -> None: +def notification(title: str, body: str) -> None: """Send notifications to all services in settings.""" - if settings.enabled and item.type in settings.on_item_type: - for url in settings.service_urls: - if "discord" in url: - url = f"{url}?format=markdown" - try: - ntfy.notify( - title=title, - body=body, - ) - except Exception as e: - logger.debug(f"Failed to send notification to {url}: {e}") - continue + for url in settings.service_urls: + if "discord" in url: + url = f"{url}?format=markdown" + try: + ntfy.notify( + title=title, + body=body, + ) + except Exception as e: + logger.debug(f"Failed to send notification to {url}: {e}") + continue def _build_discord_notification(item: MediaItem) -> str: """Build a discord notification for the given item using markdown that lists the files completed.""" @@ -67,7 +66,9 @@ def _build_discord_notification(item: MediaItem) -> str: def notify_on_complete(item: MediaItem) -> None: """Send notifications to all services in settings.""" + if item.type not in on_item_type: + return + title = "Riven completed something!" if not settings.title else settings.title body = _build_discord_notification(item) - if item.type in on_item_type: - notification(item, title=title, body=body) \ No newline at end of file + notification(title, body) \ No newline at end of file