From db492640d78cc7b568d282665b900ec1c241147e Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 11 Apr 2021 00:50:32 +0300 Subject: [PATCH] Respond with error when trying to subscribe to already subscribed feed --- rss/bot.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/rss/bot.py b/rss/bot.py index c328099..fd5e585 100644 --- a/rss/bot.py +++ b/rss/bot.py @@ -294,8 +294,15 @@ async def subscribe(self, evt: MessageEvent, url: str) -> None: self.db.add_entries(entries, override_feed_id=feed.id) elif feed.error_count > 0: self.db.set_backoff(feed, error_count=feed.error_count, next_retry=0) - self.db.subscribe(feed.id, evt.room_id, evt.sender) - await evt.reply(f"Subscribed to feed ID {feed.id}: [{feed.title}]({feed.url})") + feed_info = f"feed ID {feed.id}: [{feed.title}]({feed.url})" + sub, _ = self.db.get_subscription(feed.id, evt.room_id) + if sub is not None: + subscriber = ("You" if sub.user_id == evt.sender + else f"[{sub.user_id}](https://matrix.to/#/{sub.user_id})") + await evt.reply(f"{subscriber} had already subscribed this room to {feed_info}") + else: + self.db.subscribe(feed.id, evt.room_id, evt.sender) + await evt.reply(f"Subscribed to {feed_info}") @rss.subcommand("unsubscribe", aliases=("u", "unsub"), help="Unsubscribe this room from a feed.")