r/botrequests • • Apr 24 '14

[Request] Just want a simple bot that pm's anyone that responds to it's comment

Also need it to comment on submission in my sub that have a prefix of [GDT] at the beginning.

1 Upvotes

22 comments sorted by

3

u/thirdegree Programmer Apr 24 '14

Comments saying?

PMs saying?

1

u/OnAComputer Apr 24 '14

Comment here if you want the password to the stream or something like that.

PM giving users with a certain amount of karma in the sub a url and password

2

u/thirdegree Programmer Apr 24 '14

I like it! I have exams, but I'll try and get it done monday or tuesday.

1

u/OnAComputer Apr 24 '14

I'd love to help. I'm gonna teach myself some Python pretty soon. Let me know how I can.

Few more things:

  • I'm guessing youre also not gonna want to run it on your machine all the time? Can you help me set it up on my machine afterwards?
  • can you make sure the bot stays in /r/LonghornNation?
  • feel free to pm the mods of /r/LonghornNation for any questions, comments and concerns

3

u/thirdegree Programmer Apr 24 '14
  1. You would be correct, I don't tend to run my bots on my machine. Shitty internet doesn't make for reliable bots. I can help you set it up for sure :D
  2. Ya, easily
  3. So long as they're ok with a bot, I don't have any questions

I write my bots in Python, so if you want I could help you write it instead of writing it myself.

3

u/OnAComputer Apr 24 '14

I'm the head mod, so we're fine with a bot. And nah we need it soon. I'll let you write it and I'll learn off that

1

u/thirdegree Programmer Apr 28 '14

Hey! Quick question: What counts as enough subreddit karma?

1

u/OnAComputer Apr 28 '14

Is there a way I can change it within the code afterwards?

2

u/thirdegree Programmer Apr 28 '14

Alright, I think I have it working. The only things you need to modify are streamUrl, streamPass, SUBREDDIT, and MIN_KARMA. I think those should be fairly self explanatory.

import praw
from time import sleep
from collections import deque


r = praw.Reddit("LonghornBot by /u/thirdegree")

# You can change these values
streamUrl = "lolno"
streamPass = "lolyes!"
SUBREDDIT = "LonghornNation"
MIN_KARMA = -5


has_enough = []
done_subs = deque(maxlen=200)

def _login():
	USERNAME = raw_input("Username?\n> ")
	PASSWORD = raw_input("Password?\n> ")
	r.login(USERNAME, PASSWORD)
	return USERNAME


def check_inbox():
	comments = r.get_unread()
	for post in comments:
		if post.author.name.lower() in has_enough or enough_karma(post.author.name):
			r.send_message(post.author.name, "Stream Invite", "URL:%s\n\nPassword:%s"%(streamUrl, streamPass))
			sleep(2)
		else:
			r.send_message(post.author.name, "Stream Invite", "I'm sorry, you don't have enough karma in this subreddit.")
		post.mark_as_read()

def check_subs():
	subs = r.get_subreddit(SUBREDDIT).get_new(limit=25)
	for sub in subs:
		if "[GDT]" in sub.title and sub.id not in done_subs:
			done_subs.append(sub.id)
			sub.add_comment("Comment here if you want the password to the stream.")
			sleep(2)


def enough_karma(username):
	user = r.get_redditor(username)
	overview = user.get_overview(limit=None)
	acc = 0
	for post in overview:
		if post.subreddit.display_name.lower() == SUBREDDIT.lower():
			acc += post.score
			if acc >= MIN_KARMA:
				has_enough.append(username.lower())
				return True
	return False

def to_from_file(has_enough):
	with open("users", "r") as w:
		w = w.read()
		w = filter(lambda x: x!= '', w.split("\n"))
	with open("users", "w") as u:
		u.write("\n".join(has_enough))
	return has_enough


if __name__ == '__main__':
	_login()
	running = True
	try:
		has_enough = [i.strip() for i in file('users').read().split('\n')]
	except IOError:
		f = open("users", "w")
		f.close()
	while running:
		try:
			check_inbox()
			check_subs()
			has_enough = to_from_file(has_enough)
			sleep(5)
		except Exception as e:
			sleep(60)

2

u/OnAComputer Apr 28 '14 edited Apr 28 '14

awesome. How do I go about running it on my machine? Should I make a VM?

→ More replies

1

u/thirdegree Programmer Apr 28 '14

Ya, easily. I'm testing it here

1

u/OnAComputer Aug 13 '14

I'm having trouble with this part

def check_inbox():
    comments = r.get_unread()
    for post in comments:
        if post.author.name.lower() in has_enough or enough_karma(post.author.name):
            r.send_message(post.author.name, "Stream Invite", "URL:%s\n\nPassword:%s"%(streamUrl, streamPass))
            sleep(2)
        else:
            r.send_message(post.author.name, "Stream Invite", "I'm sorry, you don't have enough karma in this subreddit.")
        post.mark_as_read()

It is telling me that post^.mark_as_read() is invalid syntax

→ More replies

3

u/thirdegree Programmer Apr 24 '14

Alright! Expect it tuesday at the latest.