Advertisement
NateNate60

Shut Up Exe Bot source code (Ver. 7)

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