Advertisement
Guest User

kemonomimi bot v0.3

a guest
Sep 5th, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.13 KB | None | 0 0
  1. import praw
  2. import config
  3. import random
  4. import os
  5. import time
  6.  
  7. def bot_login():
  8.     print "Logging in..."
  9.     r = praw.Reddit(username = config.username,
  10.             password = config.password,
  11.             client_id = config.client_id,
  12.             client_secret = config.client_secret,
  13.             user_agent = "kemonomimi bot v0.3.2")
  14.     print "Logged in!"
  15.  
  16.     return r
  17.  
  18. def run_bot(r, comments_replied_to, catgirls):
  19.     #print catgirls
  20.     print "Searching last 25 comments..."
  21.  
  22.     for comment in r.subreddit('KemonomimiCheerUpBot+anime_irl+animemes').comments(limit=25):
  23.         if (("!im sad" in comment.body.lower())  and \
  24.             comment.id not in comments_replied_to and \
  25.             comment.author != r.user.me()):
  26.  
  27.             # print "!im sad found in comment" + comment.id
  28.  
  29.             comment.reply("[Here](" + random.choice(catgirls) + ") is a "
  30.                           "picture of a catgirl! Hopefully this will cheer you up!"
  31.                           "\n\n"
  32.                           "---"
  33.                           "\n\n"
  34.                           "I am a bot. For more info on me and how to use me, see r/KemonomimiCheerUpBot")
  35.  
  36.             print "replied to comment " + comment.id
  37.  
  38.             comments_replied_to.append(comment.id)
  39.  
  40.             with open("comments_replied_to.txt", "a") as f:
  41.                 f.write(comment.id + "\n")
  42.  
  43.     print "searching inbox..."
  44.  
  45.     for reply in r.inbox.comment_replies(limit=3):
  46.         if ("good bot" in reply.body.lower() and reply.id not in comments_replied_to):
  47.  
  48.             #print "Good bot found in reply " + reply.id
  49.  
  50.             reply.reply("[Thank You! :)](https://i.imgur.com/P3GRavv.gifv)")
  51.  
  52.             print "Thanked reply " + reply.id
  53.  
  54.             comments_replied_to.append(reply.id)
  55.  
  56.             with open("comments_replied_to.txt", "a") as f:
  57.                 f.write(reply.id+ "\n")
  58.  
  59.        
  60.  
  61.  
  62.  
  63.    
  64.     print "Time for a cat-nap!..."
  65.  
  66.     time.sleep(60)
  67.  
  68. # Load catgirls from a file (defaults to catgirls.txt)
  69. def get_catgirls(fname='catgirls.txt'):
  70.  
  71.     print "collecting catgirls..."
  72.  
  73.     if not os.path.isfile(fname):
  74.         raise FileNotFoundError("Can't get catgirls from " + fname)
  75.  
  76.     catgirls = []
  77.  
  78.     with open(fname) as catgirls_file:
  79.         catgirls_contents = catgirls_file.read()
  80.  
  81.     catgirls = catgirls_contents.split("\n")
  82.     catgirls = filter(None, catgirls)
  83.  
  84.     catgirls = [catgirl.strip() for catgirl in catgirls]
  85.  
  86.     return catgirls
  87.  
  88. def get_saved_comments():
  89.  
  90.     print "reading comments_replied_to..."
  91.  
  92.     if not os.path.isfile("comments_replied_to.txt"):
  93.         comments_replied_to = []
  94.     else:
  95.         with open("comments_replied_to.txt", "r") as f:
  96.             comments_replied_to = f.read()
  97.             comments_replied_to = comments_replied_to.split("\n")
  98.             comments_replied_to = filter(None, comments_replied_to)
  99.  
  100.     return comments_replied_to
  101.  
  102.  
  103. if __name__ == '__main__':
  104.  
  105.     r = bot_login()
  106.     catgirls = get_catgirls()
  107.     comments_replied_to = get_saved_comments()
  108.  
  109.     while True:
  110.         run_bot(r, comments_replied_to, catgirls)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement