Skip to content

Commit

Permalink
Show erroring feeds in !rss subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Apr 10, 2021
1 parent c185b31 commit 79cd475
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions rss/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,20 @@ async def command_notice(self, evt: MessageEvent, feed_id: int, setting: bool) -
send_type = "m.notice" if setting else "m.text"
await evt.reply(f"Updates for feed ID {feed.id} will now be sent as `{send_type}`")

@staticmethod
def _format_subscription(feed: Feed, subscriber: str) -> str:
msg = (f"* {feed.id} - [{feed.title}]({feed.url}) "
f"(subscribed by [{subscriber}](https://matrix.to/#/{subscriber}))")
if feed.error_count > 1:
msg += f" \n ⚠️ The last {feed.error_count} attempts to fetch the feed have failed!"
return msg

@rss.subcommand("subscriptions", aliases=("ls", "list", "subs"),
help="List the subscriptions in the current room.")
async def command_subscriptions(self, evt: MessageEvent) -> None:
subscriptions = self.db.get_feeds_by_room(evt.room_id)
await evt.reply("**Subscriptions in this room:**\n\n"
+ "\n".join(f"* {feed.id} - [{feed.title}]({feed.url}) (subscribed by "
f"[{subscriber}](https://matrix.to/#/{subscriber}))"
+ "\n".join(self._format_subscription(feed, subscriber)
for feed, subscriber in subscriptions))

@event.on(EventType.ROOM_TOMBSTONE)
Expand Down

0 comments on commit 79cd475

Please sign in to comment.