Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw #you probably know what this is
- import base64 #encoded passwords
- from urllib.request import quote #to turn the parent comment into a link
- r = praw.Reddit(user_agent='GloriousGeorge (by /u/USERNAME)',
- client_id='', client_secret="",
- username='', password=base64.b64decode(b"").decode("utf-8", "ignore"))
- r.read_only = False #no idea if this is required. Kept it to be safe.
- subreddit = r.subreddit("pcmasterrace") #get the subreddit. "all" for all comments
- f = open("C:\\repliedto.txt", "r+") #REPLACE THE PATH
- comments = subreddit.stream.comments() # get the comment stream
- x = 1 #for the counter
- for comment in comments: #for each comment in the comments stream. the current comment being processed is called "comment"
- print("found new comment! processing... (" + str(x) + ")") #the str(x) thing is printing the number of the comment being proccesed
- x += 1 #add 1 to the number
- try:
- text = str(comment.body) # Fetch body
- except:
- print("Failed to fetch or str body")
- try:
- author = str(comment.author) # Fetch author
- except AttributeError: #check if the author has been deleted
- print("Author has been deleted")
- #author was deleted
- continue
- if author.lower() == "".lower(): #Don't reply to yourself
- #myself
- print("Comment is by myself")
- continue
- if "/u/gloriousgeorge" in text: #check to see the comment is "!lmgtfy". use if text.lower() == "!lmgtfy".lower() to be non-case sensitive, use if "!lmgtfy" in text if you want the comment to be anywhere
- if comment.id in f.read(): #if the comment is already in the file, bot has replied to it
- print("ALREADY IN FILE")
- if comment.id not in f.read(): #^
- # Generate a message
- print("Attempting Answer")
- #quote() url-ifies the text, self explanatory i hope
- try:
- comment.reply("It looks like you are trying to summon /u/GloriousGe0rge. \n\n_____\n\n^by ^/u/Shrellex") #reply to comment
- except praw.exceptions.APIException:
- print('RATELIMIT ERROR')
- print("Replied to comment by " + author)
- f.write(comment.id + "\n")#write comment id to file so it doesn't reply to it again
- if comment.id in f.read():
- print("Written Successfully!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement