def process_comment(comment):
    if re.search("Jordy", comment.body, re.IGNORECASE) and comment.is_root:

        print("Jordy comment found {}: {}".format(comment.id, comment.body))

        if db.has_replied(comment.id):
            print("Already replied to comment {}: {}".format(
                comment.id, comment.body))
        else:
            print("Replying to comment {}: {}".format(comment.id,
                                                      comment.body))
            db.add_reply(comment.id)
            comment.reply(":(")

    if not comment.is_root and hasattr(comment, 'parent'):
        process_sub_comment(comment)
Пример #2
0
def run():
  no_context = [ '/r/nocontext' ]
  banned_subreddits = [ 'wishlist', 'cringepics', 'askreddit' ]
  r = login.init()
  my_id = login.my_id(r)
  while True:
    try:
      for comment in praw.helpers.comment_stream(r, 'all', verbosity=0):
        subreddit = comment.subreddit.display_name.lower()
        if subreddit in banned_subreddits:
          continue
        text = util.txt(comment).lower().strip()
        if text in no_context \
            and not comment.is_root \
            and not db.has_replied(comment.id):
          db.reply(comment.id)
          login.refresh_praw(r)
          reply(r, comment)
    except praw.errors.OAuthInvalidToken:
      login.refresh_praw(r)
def process_sub_comment(comment):
    parent = comment.parent()
    replied = False
    if hasattr(parent.author, "name"):
        if re.search("JordyDiedForThis", parent.author.name,
                     re.IGNORECASE) and not db.has_replied(comment.id):
            print("Comment is response to bot")
            if re.search("good bot", comment.body, re.IGNORECASE):
                replied = True
                IMG_SRC = random.choice(tuple(THUMBS))
                comment.reply("[:')]({})".format(IMG_SRC))

            else:
                if re.search("bad bot", comment.body,
                             re.IGNORECASE) or re.search(
                                 "sad bot", comment.body, re.IGNORECASE):
                    replied = True
                    IMG_SRC = random.choice(tuple(SADS))
                    comment.reply("[:'(]({})".format(IMG_SRC))

            if replied:
                db.add_reply(comment.id)