From b42b01729bb26dc1ec9b5b6010843ece1caaa791 Mon Sep 17 00:00:00 2001 From: dgw Date: Wed, 27 Jan 2021 21:51:46 -0600 Subject: [PATCH] reddit: show singular "comment" in post output when appropriate --- sopel/modules/reddit.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sopel/modules/reddit.py b/sopel/modules/reddit.py index 5f892790e3..3c9751814c 100644 --- a/sopel/modules/reddit.py +++ b/sopel/modules/reddit.py @@ -143,9 +143,10 @@ def say_post_info(bot, trigger, id_, show_link=True, show_comments_link=False): try: s = bot.memory['reddit_praw'].submission(id=id_) - message = ('{title} {link}{nsfw} | {points} {points_text} ' - '({percent}) | {comments} comments | Posted by {author} | ' - 'Created at {created}{comments_link}') + message = ( + '{title} {link}{nsfw} | {points} {points_text} ({percent}) | ' + '{comments} {comments_text} | Posted by {author} | ' + 'Created at {created}{comments_link}') subreddit = s.subreddit.display_name if not show_link: @@ -193,6 +194,8 @@ def say_post_info(bot, trigger, id_, show_link=True, show_comments_link=False): percent = color('{:.1%}'.format(s.upvote_ratio), point_color) + comments_text = 'comment' if s.num_comments == 1 else 'comments' + comments_link = '' if show_comments_link: try: @@ -204,8 +207,8 @@ def say_post_info(bot, trigger, id_, show_link=True, show_comments_link=False): title = unescape(s.title) message = message.format( title=title, link=link, nsfw=nsfw, points=s.score, points_text=points_text, - percent=percent, comments=s.num_comments, author=author, created=created, - comments_link=comments_link) + percent=percent, comments=s.num_comments, comments_text=comments_text, + author=author, created=created, comments_link=comments_link) bot.say(message) except prawcore.exceptions.NotFound: