Guest User

a broken reddit bot(line18)

a guest
Aug 12th, 2016
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. import praw
  2. import time
  3.  
  4. r = praw.Reddit(user_agent = "Depression help bot By /u/Depression_help_bot and /u/playgrop")
  5. r.login("Depression_help_bot","*censored*")
  6. print("Logging in...")
  7.  
  8. words_to_match = ["depression", "depressed", "suicidal", "suicide", "take my own life", "kill myself"]
  9. cache = []
  10.  
  11. def run_bot():
  12.     print("Grabbing Subreddit")
  13.     subreddit = r.get_subreddit("pcmasterrace")
  14.     print("Grabbing Comments")
  15.     comments = subreddit.get_comments(limit=50)
  16.     for comment in comments:
  17.         comment_text = comment.body.lower()
  18.         isMatch = any(string in comment_text for string in words_to_match) and if not Depression_help_bot in comment_author_name
  19.             if comment.id not in cache and isMatch:
  20.             print("Match Found! Comment ID: " + comment.id)
  21.             comment.reply("If you are suicidal or know anybody struggeling with depression you should seek help. An example would be here [here](http://www.suicide.org/international-suicide-hotlines.html). ____ Bleep Boop! I am a bot. If you found any problems message me [here](https://www.reddit.com/message/compose/?to=Depression_help_bot)")
  22.         print("Reply sucessfull")
  23.             cache.append(comment.id)
  24.     print("Comment loop finished")
  25.  
  26. while True:
  27.     run_bot()
  28.     time.sleep(30)
Add Comment
Please, Sign In to add comment