Advertisement
NateNate60

Shut Up Exe Bot source code (Ver. 6)

Oct 29th, 2018
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.75 KB | None | 0 0
  1. print ("Starting Shut_Up_Exe_Bot version 6")
  2.  
  3. #Patch Notes
  4. """
  5. The bot now responds to "silence, executioner".
  6. The bot will agree with the user if the users says "tarnation
  7. John Willard".
  8.  
  9. Made they code neater wherever possible.
  10. """
  11.  
  12. #Import the required modules
  13. import praw
  14. import config
  15. import time
  16. import os
  17.  
  18. #Testing mode. True for testing mode off and False for on
  19. reply = True
  20.  
  21. #Choose whether the bot should print the list of comments replied to after every
  22. # reply. False for don't print, True for print.
  23. printCRT = False
  24.  
  25. #Maximum number of comments to check in one cycle
  26. coNumber = 50
  27.  
  28. #Define function LOGIN
  29. def login() :
  30.     print ("Authenticating.")
  31.     r = praw.Reddit(username = config.username,
  32.                 password = config.password,
  33.                 client_id = config.client_id,
  34.                 client_secret = config.client_secret,
  35.                 user_agent = config.user_agent)
  36.     print ("Authentication successful")
  37.     return r
  38.  
  39. #___________________________________________
  40.  
  41.  
  42.  
  43.  
  44.  
  45. #Define function RUN_BOT
  46. def run_bot(r, comments_replied_to, execount, jestcount, coNumber, printCRT) :
  47.     print ("Obtaining comments")
  48.    
  49.     #Obtaining comments
  50.     for comment in r.subreddit('townofsalemgame').comments(limit = coNumber) :
  51.         if comment.author not in config.banned :
  52.             if comment.id not in comments_replied_to and comment.author != r.user.me() :
  53.                 if  "shut up exe" in comment.body.lower() or "u exe" in comment.body.lower() or "re exe" in comment.body.lower() or "silence exe" in comment.body.lower() :
  54.                     print ("Found valid string for EXE at " + comment.id)
  55.                     if reply == True :
  56.                         execount += 1
  57.                         comment.reply ("Executioners silenced: " + str(execount) + "." + "\n \n" +
  58.                                        "Beep Boop. I am a bot. Please contact NateNate60 for any suggestions, questions,~~and complaints~~"
  59.                                        + "\n \n ^ShutUpExeBot ^Version ^6")
  60.                         print ("The current execount is: ", str(execount) + ". Reply successful.")
  61.                         comments_replied_to.append (comment.id)
  62.                         with open ('comments.txt', 'a') as f :
  63.                             f.write (comment.id + "\n")
  64.                         open('execount.txt', 'w').close()
  65.                         with open ('execount.txt', 'a') as exe :
  66.                             exe.write (str(execount))
  67.                         if printCRT == True :
  68.                             print ("Comments that the bot has replied to: " + str(comments_replied_to))
  69.                 elif "silence" in comment.body.lower() and "execut" in comment.body.lower() :
  70.                     print ("Found valid string for EXE at " + comment.id)
  71.                     if reply == True :
  72.                         execount += 1
  73.                         comment.reply ("Executioners silenced: " + str(execount) + "." + "\n \n" +
  74.                                        "Beep Boop. I am a bot. Please contact NateNate60 for any suggestions, questions,~~and complaints~~"
  75.                                        "\n \n ^ShutUpExeBot ^Version ^6")
  76.                         print ("The current execount is: ", str(execount) + ". Reply successful.")
  77.                         comments_replied_to.append (comment.id)
  78.                         with open ('comments.txt', 'a') as f :
  79.                             f.write (comment.id + "\n")
  80.                         open('execount.txt', 'w').close()
  81.                         with open ('execount.txt', 'a') as exe :
  82.                             exe.write (str(execount))
  83.                         if printCRT == True :
  84.                             print ("Comments that the bot has replied to: " + str(comments_replied_to))
  85.                 elif "shut up jest" in comment.body.lower() or "u jest" in comment.body.lower() or "re jest" in comment.body.lower() :
  86.                     print ("Found valid string for JEST at " + comment.id)
  87.                     if reply == True :
  88.                         jestcount += 1
  89.                         comment.reply ("Jesters discovered: " + str(jestcount) + "." + "\n \n" +
  90.                                        "Beep Boop. I am a bot. Please contact NateNate60 for any suggestions, questions, ~~and complaints.~~"
  91.                                        + "\n \n ^ShutUpExeBot ^Version ^6")
  92.                         print ("The current jestcount is: ", str(jestcount) + ". Reply successful.")
  93.                         comments_replied_to.append (comment.id)
  94.                         with open ('comments.txt', 'a') as f :
  95.                             f.write (comment.id + "\n")
  96.                         open('jestcount.txt', 'w').close()
  97.                         with open ('jestcount.txt', 'a') as jest :
  98.                             jest.write (str(jestcount))
  99.                         if printCRT == True :
  100.                             print ("Comments that the bot has replied to: " + str(comments_replied_to))
  101.                 elif "has revealed themselves as the mayor" in comment.body.lower() or "has revealed himself as the mayor" in comment.body.lower() or "i'm mayor" in comment.body.lower() :
  102.                     print ("Found valid string for MAYOR at " + comment.id)
  103.                     if reply == True :
  104.                         comment.reply ("You were shot by a Vigilante!" + "\n \n" +
  105.                                        "Beep Boop. I am a bot. Please contact NateNate60 for any suggestions, questions, ~~and complaints~~" +
  106.                                        "\n \n ^ShutUpExeBot ^Version ^6")
  107.                         comments_replied_to.append (comment.id)
  108.                         with open ('comments.txt', 'a') as f :
  109.                             f.write (comment.id + "\n")
  110.                         if printCRT == True :
  111.                             print ("Comments that the bot has replied to: " + str(comments_replied_to))
  112.                 elif "is maf" in comment.body.lower() :
  113.                     if "m sheriff" in comment.body.lower() :
  114.                         print ("Found valid string for SHERIFF at " + comment.id)
  115.                         if reply == True :
  116.                             comment.reply ("Please kindly close thine talking-cavity, person who kills convicted invididuals on behalf of the Government." + "\n \n" +
  117.                                            "Beep Boop. I am a bot. Please contact NateNate60 for any suggestions, questions, ~~and complaints~~" +
  118.                                            "\n \n ^ShutUpExeBot ^Version ^6")
  119.                             comments_replied_to.append (comment.id)
  120.                             with open ('comments.txt', 'a') as f :
  121.                                 f.write (comment.id + "\n")
  122.                             if printCRT == True :
  123.                                 print ("Comments that the bot has replied to: " + str(comments_replied_to))
  124.                 elif "tarnation john wil" in comments.body.lower() :
  125.                     print ("Found valid string for WILLARD at " + comment.id)
  126.                     if reply == True :
  127.                         comment.reply ("Yes, tarnation John Willard indeed." + "\n \n"
  128.                                        "Beep Boop. I am a bot. Please contact NateNate60 for any suggestions, questions, ~~and complaints~~" +
  129.                                        "\n \n ^ShutUpExeBot ^Version ^6")
  130.                         comments_replied_to.append (comment.id)
  131.                         with open ('comments.txt', 'a') as f :
  132.                             f.write (comment.id + "\n")
  133.                         if printCRT == True :
  134.                             print ("Comments that the bot has replied to: " + str(comments_replied_to))
  135.                 print ("The bot is resting for 5 seconds")
  136.     time.sleep (5)
  137.     return execount, comments_replied_to
  138.  
  139.  
  140.  
  141.  
  142.  
  143. #Define function GET_COMMENT_LIST
  144. def get_comment_list() :
  145.     with open ("comments.txt", "r") as f :
  146.         comments_replied_to = f.read()
  147.         comments_replied_to = comments_replied_to.split("\n")
  148.     return comments_replied_to
  149.  
  150. def get_execount() :
  151.     with open ("execount.txt", "r") as exe :
  152.         execount = exe.read ()
  153.         execount = int(execount)
  154.     return execount
  155.  
  156. def get_jestcount() :
  157.     with open ("jestcount.txt", "r") as jest :
  158.         jestcount = jest.read()
  159.         jestcount = int(jestcount)
  160.     return jestcount
  161.  
  162.  
  163.  
  164. #Log in
  165. r = login()
  166.  
  167. #Set empty list for comments_replied_to
  168. comments_replied_to = get_comment_list()
  169.  
  170. print ("Blacklisted users: ", config.banned)
  171. print ("Loaded.")
  172.  
  173. #Run forever
  174. while True :
  175.     execount = get_execount()
  176.     jestcount = get_jestcount()
  177.     run_bot(r, comments_replied_to, execount, jestcount, coNumber, printCRT)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement