Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import time
- r = praw.Reddit(user_agent='INSERT YOURS',
- client_id = 'INSERT YOURS',
- client_secret = 'INSERT YOURS',
- username = 'INSERT YOURS',
- password = 'INSERT YOURS')
- print('Logged in!')
- haters = []
- file = open("haters.txt","r")
- line = "\n"
- while "\n" in line:
- line = file.readline()
- haters.append(line.replace("\n",""))
- print(line.replace("\n",""))
- file.close()
- print(haters)
- def reply(comment, message):
- print(str(comment.author.name in haters) + " "+ comment.author.name)
- if comment.author.name in haters:
- print("Good")
- return
- try:
- print("Attempting to reply...")
- comment.reply(message+' \n ^^*beep* ^^*bop* ^^if ^^you ^^hate ^^me, ^^reply ^^with ^^\"stop\". ^^If ^^you ^^just ^^got ^^smart, ^^reply ^^with ^^"start".')
- print("Success! Searching for another..")
- except Exception as err:
- print("EXCEPTION HANDLED: ",err)
- error=str(err)
- if error[0:9]=="RATELIMIT":
- index = error.index(" in ")
- num = error[index+4]
- isMinutes = error[index+4+2] == "m" or error[index+4+3] == "m"
- if isMinutes:
- num=int(num)*60+30
- print("waiting %s seconds..." % (num))
- time.sleep(num) #bonus 30 gives the API some leeway
- else:
- num = (int(num)+1)*10+30
- print("waiting %s seconds..." % (num))
- time.sleep(int(num))
- reply(comment,message)
- else:
- print("Crazy error! Abandon ship!\n"+error+"\nSearching for another...")
- def removeHater(author):
- name = author.name
- haters.remove(name)
- file = open("haters.txt","r")
- line = "\n"
- contents = ""
- while "\n" in line:
- line = file.readline()
- nl = line.replace("\n","")
- if(nl!=name):
- contents+=line
- file.close()
- hate = open("haters.txt","w")
- hate.write(contents)
- hate.close()
- print("Added "+name)
- r.redditor(name).message("You love me. :)",
- "You are off of the hater list. If this is a mistake, PM /u/Allons-why \n^^If ^^you ^^like ^^to ^^have ^^fun ^^a ^^lot, ^^go ^^to ^^/r/checks_out_bot",)
- def addHater(author):
- name = author.name
- if name not in haters:
- haters.append(name)
- hate = open("haters.txt","r")
- contents = hate.read()
- hate.close()
- hate = open("haters.txt","w")
- hate.write(contents+"\n"+name)
- hate.close()
- print(name)
- r.redditor(name).message("You hate me. :(",
- "I have put you on my hater list at your request. I will no longer bother you. If this is a mistake, PM /u/Allons-why",)
- negatives = ["don't","no","never"]
- def run_bot():
- print("Grabbing sub...")
- subreddit = r.subreddit("all")
- print("Grabbing comments...")
- comments = subreddit.stream.comments()
- print("Searching...")
- for comment in comments:
- comment_text = " "+comment.body.lower().replace("\"","")
- if "stop" in comment_text and not any(string in comment_text for string in negatives):
- try:
- parent = comment.parent()
- if parent.author.name == "checks_out_bot":
- addHater(comment.author)
- except:
- continue
- elif ("start" in comment_text) and (comment.author.name in haters):
- try:
- parent = comment.parent()
- if parent.author.name == "checks_out_bot":
- removeHater(comment.author)
- except Exception as err:
- print("start: "+str(err))
- continue
- elif "it's funny because checks_out_bot's username is very applicable to their comment." in comment_text:
- reply(comment,"\\*beep\\* \\*boop\\* \\*beeeep\\* That is *my* thing!")
- elif "username checks out" in comment_text or " name checks out" in comment_text:
- parent = comment.parent()
- if parent.author.name == "checks_out_bot":
- reply(comment, "Yes it does.")
- else:
- reply(comment,"It's funny because %s's username is very applicable to their comment."%(parent.author.name.replace("_","\\_")))
- while True:
- try:
- run_bot()
- except Exception as err:
- print(err)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement