Advertisement
dmesticg

Untitled

Jun 29th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. import praw
  2. import config
  3. import time
  4. import os
  5. import random
  6. import re
  7.  
  8. def bot_login():
  9. print ("Loggin in...")
  10. global r
  11. r = praw.Reddit(username = config.username,
  12. password = config.password,
  13. client_id = config.client_id,
  14. client_secret = config.client_secret,
  15. user_agent = config.user_agent)
  16. print ("Logged in!")
  17.  
  18. def run_bot():
  19. global r
  20. global comments_dealt_with
  21. for subreddit in config.subreddits:
  22. print ("Obtaining 25 comments in " + subreddit)
  23. for comment in r.subreddit(subreddit).comments(limit=25):
  24. thecomment = comment.body
  25. flair = next(r.subreddit(config.flair_subreddit).flair(comment.author))
  26. if flair["flair_text"] is None:
  27. r.subreddit(config.flair_subreddit).flair.set(comment.author, "1000")
  28. flair["flair_text"] = "1000"
  29. print ("New user, setting balance to 1000")
  30. try:
  31. currentMoney = int(flair["flair_text"])
  32. except ValueError:
  33. print ("Flair is not an integer, ignoring, flair = " + flair["flair_text"])
  34. comments_dealt_with.append(comment.id)
  35. with open ("comments_dealt_with.txt", "a") as a:
  36. a.write(comment.id + "\n")
  37. continue
  38.  
  39.  
  40. if ("!status" in comment.body and comment.id not in comments_dealt_with and comment.author != r.user.me()):
  41. print ("'!STATUS' FOUND IN COMMENT " + comment.id)
  42. comment.reply(config.status_text + config.footer_text)
  43.  
  44. if ("!resetbalance" in comment.body and comment.id not in comments_dealt_with and comment.author != r.user.me()):
  45. print ("resetbalance called, resetting balance")
  46. r.subreddit(config.flair_subreddit).flair.set(comment.author, "1000")
  47. comment.reply(config.reset_text + config.footer_text)
  48.  
  49. if ("!checkbalance" in comment.body and comment.id not in comments_dealt_with and comment.author != r.user.me()):
  50. print ("checkbalance called, checking balance")
  51. comment.reply(config.checkbal_text(currentMoney) + config.footer_text)
  52.  
  53. ## if currentMoney < betSize:
  54. ## comment.reply(config.low_money_text(currentMoney) + config.footer_text)
  55. ## print ("Not enough coins, replied")
  56. ## comments_dealt_with.append(comment.id)
  57. ## with open ("comments_dealt_with.txt", "a") as a:
  58. ## a.write(comment.id + "\n")
  59. ## continue
  60.  
  61. print ("Replied to comment " + comment.id)
  62. comments_dealt_with.append(comment.id)
  63. with open ("comments_dealt_with.txt", "a") as a:
  64. a.write(comment.id + "\n")
  65.  
  66. print ("Sleeping for 10 seconds...")
  67. time.sleep(10)
  68.  
  69. def get_saved_comments():
  70. global comments_dealt_with
  71. if not os.path.isfile("comments_dealt_with.txt"):
  72. comments_dealt_with = []
  73. else:
  74. with open("comments_dealt_with.txt", "r") as f:
  75. comments_dealt_with = f.read()
  76. comments_dealt_with = comments_dealt_with.split("\n")
  77. #comments_dealt_with = filter(None, comments_dealt_with)
  78.  
  79.  
  80. bot_login()
  81. get_saved_comments()
  82. print (comments_dealt_with)
  83.  
  84. while True:
  85. run_bot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement