Skip to content

Commit

Permalink
gobble comment errors
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPowerScripts committed Jan 11, 2021
1 parent abf07ff commit db5ccf3
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/bots/reddit/actions/comments/comment_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from config import reddit_config
from ..utils import get_subreddit, AVOID_WORDS
import random
from praw.exceptions import APIException

Source = namedtuple('Source', ['name', 'api'])

Expand Down Expand Up @@ -49,17 +50,20 @@ def comment(self, roll=1):
if len(post.comments.list()) > 0:
post_with_comments = True

# choose if we're replying to the post or to a comment
if chance(self.config.get('reddit_reply_to_comment')):
# reply to the post with a response based on the post title
log.info('replying directly to post')
post.reply(self.comments.get_reply(post.title))
else:
# get a random comment from the post
comment = random.choice(post.comments.list())
# reply to the comment
log.info('replying to comment')
comment.reply(self.comments.get_reply(comment.body))
try:
# choose if we're replying to the post or to a comment
if chance(self.config.get('reddit_reply_to_comment')):
# reply to the post with a response based on the post title
log.info('replying directly to post')
post.reply(self.comments.get_reply(post.title))
else:
# get a random comment from the post
comment = random.choice(post.comments.list())
# reply to the comment
log.info('replying to comment')
comment.reply(self.comments.get_reply(comment.body))
except APIException as e:
log.info(f"error commenting: {e}")



Expand Down

0 comments on commit db5ccf3

Please sign in to comment.