Advertisement
Guest User

v

a guest
Feb 14th, 2022
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. import praw
  2. import config
  3. import time
  4. import os
  5. import random
  6. import keep_alive
  7.  
  8. keep_alive.keep_alive()
  9.  
  10. with open("mud.txt", "r") as file:
  11. allText = file.read()
  12. words = list(map(str, allText.split()))
  13.  
  14. def bot_login():
  15. print ("Logging in...")
  16. r = praw.Reddit(username = config.username,
  17. password = config.password,
  18. client_id = config.client_id,
  19. client_secret = config.client_secret,
  20. user_agent = "The Reddit Commenter v1.0")
  21. print ("Logged in!")
  22.  
  23. return r
  24.  
  25. def run_bot(r, comments_replied_to):
  26. print ("Searching last 1,000 comments")
  27.  
  28. for comment in r.subreddit('pokemon').comments(limit=1000):
  29. if "Mudkip" in comment.body and comment.id not in comments_replied_to and comment.author != r.user.me or "mudkip" in comment.body and comment.id not in comments_replied_to and comment.author != r.user.me or ():
  30. print ("String with \"Mudkip\" found in comment ")
  31. comment.reply(random.choice(words))
  32. print ("Replied to comment " + comment.id)
  33.  
  34. comments_replied_to.append(comment.id)
  35.  
  36. with open ("comments_replied_to.txt", "a") as f:
  37. f.write(comment.id + "\n")
  38.  
  39.  
  40. print ("Search Completed.")
  41.  
  42. print (comments_replied_to)
  43.  
  44. print ("Sleeping for 10 seconds...")
  45. #Sleep for 10 seconds...
  46. time.sleep(10)
  47.  
  48. def get_saved_comments():
  49. if not os.path.isfile("comments_replied_to.txt"):
  50. comments_replied_to = []
  51. else:
  52. with open("comments_replied_to.txt", "r") as f:
  53. comments_replied_to = f.read()
  54. comments_replied_to = comments_replied_to.split("\n")
  55. comments_replied_to = filter(None, comments_replied_to)
  56.  
  57. return comments_replied_to
  58.  
  59. r = bot_login()
  60. comments_replied_to = get_saved_comments()
  61. print (comments_replied_to)
  62.  
  63. while True:
  64. run_bot(r, comments_replied_to)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement