Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import config
- import time
- import os
- import random
- import re
- def bot_login():
- print "Loggin in..."
- r = praw.Reddit(username = config.username,
- password = config.password,
- client_id = config.client_id,
- client_secret = config.client_secret,
- user_agent = "busterronitest's dog comment responder v0.1")
- print "Logged in!"
- return r
- def run_bot(r, comments_replied_to):
- print "Obtaining 25 comments..."
- for comment in r.subreddit('clearbot').comments(limit=10):
- if "!coinflip" in comment.body and comment.id not in comments_replied_to and comment.author != r.user.me():
- print "String with \"!coinflip\" found in comment " + comment.id
- thecomment = comment.body
- betSize, betChoice = re.match(r'!coinflip \[(\w+)] \((\d+)\)', thecomment).groups()
- betSize = int(betSize)
- whatside = random.randint(1,2)
- if whatside == 1:
- side = "Heads"
- else:
- side = "Tails"
- if side[0] == betChoice:
- win = "win"
- elif side[0] != betChoice:
- win = "lose"
- else:
- win = "ERROR!"
- comment.reply("Flipping a Coin... It landed on {}, Which means you {} {} coins!".format(side ,win, betSize))
- print "Replied to comment " + comment.id
- comments_replied_to.append(comment.id)
- with open ("comments_replied_to.txt", "a") as a:
- a.write(comment.id + "\n")
- print "Sleeping for 10 seconds..."
- time.sleep(10)
- def get_saved_comments():
- if not os.path.isfile("comments_replied_to.txt"):
- comments_replied_to = []
- else:
- with open("comments_replied_to.txt", "r") as f:
- comments_replied_to = f.read()
- comments_replied_to = comments_replied_to.split("\n")
- comments_replied_to = filter(None, comments_replied_to)
- return comments_replied_to
- r = bot_login()
- comments_replied_to = get_saved_comments()
- print comments_replied_to
- while True:
- run_bot(r, comments_replied_to)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement