From f9e4f109d5c786107b758bcabfc1b6604e86e344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Hells=C3=A9n?= Date: Sat, 7 Jun 2025 04:54:35 +0200 Subject: [PATCH] Add checks for paused or deleted feeds before sending entries to Discord --- .vscode/launch.json | 2 +- discord_rss_bot/feeds.py | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index bb222ab..266d7f2 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,7 +12,7 @@ "--host", "0.0.0.0", "--port", - "5000", + "3000", ], "jinja": true, "justMyCode": true diff --git a/discord_rss_bot/feeds.py b/discord_rss_bot/feeds.py index a8388a9..f81ed50 100644 --- a/discord_rss_bot/feeds.py +++ b/discord_rss_bot/feeds.py @@ -11,7 +11,18 @@ from urllib.parse import ParseResult, urlparse import tldextract from discord_webhook import DiscordEmbed, DiscordWebhook from fastapi import HTTPException -from reader import Entry, EntryNotFoundError, Feed, FeedExistsError, Reader, ReaderError, StorageError, TagNotFoundError +from markdownify import markdownify +from reader import ( + Entry, + EntryNotFoundError, + Feed, + FeedExistsError, + FeedNotFoundError, + Reader, + ReaderError, + StorageError, + TagNotFoundError, +) from discord_rss_bot.custom_message import ( CustomEmbed, @@ -389,6 +400,20 @@ def execute_webhook(webhook: DiscordWebhook, entry: Entry) -> None: entry (Entry): The entry to send to Discord. """ + reader: Reader = get_reader() + + # If the feed has been paused or deleted, we will not send the entry to Discord. + entry_feed: Feed = entry.feed + if entry_feed.updates_enabled is False: + logger.warning("Feed is paused, not sending entry to Discord: %s", entry_feed.url) + return + + try: + reader.get_feed(entry_feed.url) + except FeedNotFoundError: + logger.warning("Feed not found in reader, not sending entry to Discord: %s", entry_feed.url) + return + response: Response = webhook.execute() if response.status_code not in {200, 204}: msg: str = f"Error sending entry to Discord: {response.text}\n{pprint.pformat(webhook.json)}"