From 6458efd28bf5c35c3d52b42f2624d3e5608c101c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Hells=C3=A9n?= Date: Mon, 13 Dec 2021 17:30:18 +0100 Subject: [PATCH] Add option for sending message to Discord when a new feed is added --- discord_rss_bot/main.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/discord_rss_bot/main.py b/discord_rss_bot/main.py index 133fce7..b026a07 100644 --- a/discord_rss_bot/main.py +++ b/discord_rss_bot/main.py @@ -1,3 +1,5 @@ +from typing import Optional + import typer from dhooks import Webhook from reader import FeedExistsError, make_reader @@ -10,7 +12,10 @@ reader = make_reader(Settings.db_file) # For RSS (https://github.com/lemon24/re @app.command() -def add(feed_url: str) -> None: +def add( + feed_url: str = typer.Argument(..., help="RSS or Atom feed URL."), + notify_discord: bool = typer.Option(False, help="Send message to Discord."), +) -> None: """Add a feed to the database Args: @@ -32,6 +37,13 @@ def add(feed_url: str) -> None: for entry in entries: reader.mark_entry_as_read(entry) + if notify_discord: + # Send a message to Discord + hook.send( + f"discord-rss-bot: {feed_url} added to the database.\nYou now have " + f"{reader.get_feed_counts()} feeds." + ) + typer.echo(f"{feed_url} added")