Skip to content

Commit

Permalink
refactor: remove unnecessary checks for notifications (#781)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidemarcoli authored Oct 14, 2024
1 parent 1f24e4f commit 254a7d3
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/utils/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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)
notification(title, body)

0 comments on commit 254a7d3

Please sign in to comment.