Skip to content

Commit

Permalink
Merge pull request #2025 from sopel-irc/reddit-comments-plural
Browse files Browse the repository at this point in the history
reddit: show singular "comment" in post output when appropriate
  • Loading branch information
dgw authored Feb 25, 2021
2 parents c5dffb5 + b42b017 commit 13a59f8
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions sopel/modules/reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 13a59f8

Please sign in to comment.