Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import time
- def authenticate():
- print("Authenticating...")
- r = praw.Reddit(username = 'TalkieToasterBot',
- password = 'NotRealPasswordJustHelpPls', // I have all of these in my actual program just not sharing them
- client_id = 'NotRealID',
- client_secret = 'NotRealSecret'
- )
- print("Authenticated as {}".format(r.user.me()))
- return r
- def main():
- r = authenticate()
- while True:
- run_bot(r)
- time.sleep(10)
- words_to_look_for = [ {
- 'id': 'toast',
- 'target_text': ['toast', 'muffin', 'teacakes', 'teacake', 'buns', 'bun', 'baguettes', 'baguette', 'bagels', 'bagel', 'crumpets', 'crumpet', 'pancakes', 'pancake', 'hot cross buns', 'flapjacks', 'flapjack', 'waffle', 'waffles', 'toaster'],
- 'reply': 'Does anyone want toast?'
- },
- {
- 'id': 'talkie',
- 'target_text': ['Talkie', 'talkie'],
- 'reply': "Talkie's the name toastings the game."
- },
- {
- 'id': 'flapjack',
- 'target_text': ['No Flapjacks', 'no flapjacks'],
- 'reply': "So you're a waffle man eh?"
- },
- {
- 'id': 'bread',
- 'target_text': ['No Bread', 'no bread'],
- 'reply': "But I'm a toaster! It is my raison d'etre.. I toast, therefore I am. If you didn't want toast why did you repair me?"
- },
- {
- 'id': 'accident',
- 'target_text': ['accident'],
- 'reply': "That wasn't an accident! It was first degree toastercide."
- }]
- cache = []
- def run_bot(r):
- print("Grabbing Subreddit...")
- for comment in r.subreddit('test').comments(limit=25):
- comment_text = comment.body.lower()
- for item in comment.body:
- isMatch = any(string in comment_text for string in item['target_text'])
- if comment.id not in cache and not already_replied(comment) and isMatch:
- comment.reply(item['reply'])
- print("Match Found! Comment ID: " + comment.id)
- print("Reply Successful!")
- cache.append(comment.id)
- def already_replied(comment):
- for c in comment.replies():
- if str(c.author) == 'TalkieToasterBot':
- return True
- return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement