Advertisement
Guest User

Untitled

a guest
Jan 11th, 2018
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. import praw
  2. import time
  3.  
  4. def authenticate():
  5. print("Authenticating...")
  6. r = praw.Reddit(username = 'TalkieToasterBot',
  7. password = 'NotRealPasswordJustHelpPls', // I have all of these in my actual program just not sharing them
  8. client_id = 'NotRealID',
  9. client_secret = 'NotRealSecret'
  10. )
  11. print("Authenticated as {}".format(r.user.me()))
  12. return r
  13.  
  14. def main():
  15. r = authenticate()
  16. while True:
  17. run_bot(r)
  18. time.sleep(10)
  19.  
  20. words_to_look_for = [ {
  21. 'id': 'toast',
  22. 'target_text': ['toast', 'muffin', 'teacakes', 'teacake', 'buns', 'bun', 'baguettes', 'baguette', 'bagels', 'bagel', 'crumpets', 'crumpet', 'pancakes', 'pancake', 'hot cross buns', 'flapjacks', 'flapjack', 'waffle', 'waffles', 'toaster'],
  23. 'reply': 'Does anyone want toast?'
  24. },
  25. {
  26. 'id': 'talkie',
  27. 'target_text': ['Talkie', 'talkie'],
  28. 'reply': "Talkie's the name toastings the game."
  29. },
  30. {
  31. 'id': 'flapjack',
  32. 'target_text': ['No Flapjacks', 'no flapjacks'],
  33. 'reply': "So you're a waffle man eh?"
  34. },
  35. {
  36. 'id': 'bread',
  37. 'target_text': ['No Bread', 'no bread'],
  38. 'reply': "But I'm a toaster! It is my raison d'etre.. I toast, therefore I am. If you didn't want toast why did you repair me?"
  39. },
  40. {
  41. 'id': 'accident',
  42. 'target_text': ['accident'],
  43. 'reply': "That wasn't an accident! It was first degree toastercide."
  44. }]
  45.  
  46. cache = []
  47.  
  48. def run_bot(r):
  49. print("Grabbing Subreddit...")
  50. for comment in r.subreddit('test').comments(limit=25):
  51. comment_text = comment.body.lower()
  52. for item in comment.body:
  53. isMatch = any(string in comment_text for string in item['target_text'])
  54. if comment.id not in cache and not already_replied(comment) and isMatch:
  55. comment.reply(item['reply'])
  56. print("Match Found! Comment ID: " + comment.id)
  57. print("Reply Successful!")
  58. cache.append(comment.id)
  59.  
  60. def already_replied(comment):
  61. for c in comment.replies():
  62. if str(c.author) == 'TalkieToasterBot':
  63. return True
  64. return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement