Advertisement
NateNate60

Shut Up Exe Bot source code (Ver 7.3)

Nov 16th, 2018
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 14.86 KB | None | 0 0
  1. #Patch Notes
  2. """
  3. The bot will check its inbox for people who
  4. say "bad bot" or "shut up bot" to it.
  5.  
  6. If someone says something that sounds like a death
  7. announcement then the bot will accuse the user
  8. of being the killer.
  9.  
  10. More trigger phrases.
  11.  
  12. Shut Up Exe Bot is now being hosted on Python Anywhere
  13. for better reliability.
  14.  
  15. Subpatch: Module "os" is no longer imported as I have realised
  16. it is never used. To increase efficiency the amount of
  17. inbox messages that the bot checks will be tied to one
  18. tenth of coNumber, minus two. That means that if the bot
  19. is set to check 50 comments as the coNumber, then the bot
  20. will check 3 messages.
  21. """
  22.  
  23. #Version number, as a string
  24. version = "7.30"
  25. print ("Starting Shut_Up_Exe_Bot version " + version)
  26.  
  27.  
  28. #Import the required modules
  29. print ("Importing modules...", end='')
  30. import praw
  31. import config
  32. import time
  33. print ('done')
  34. print ("Loading features...", end='')
  35.  
  36. #Testing mode. True for testing mode off and False for on
  37. reply = True
  38.  
  39. #Choose whether the bot should print the list of comments replied to after every
  40. # reply. False for don't print, True for print.
  41. printCRT = False
  42.  
  43. #Maximum number of comments to check in one cycle. Must be a multiple of 10!
  44. # For the fastest, set this to 30, which is the minimum. I recommend 50 if
  45. # your hardware allows.
  46. coNumber = 50
  47.  
  48.  
  49.  
  50.  
  51. #Define function LOGIN
  52. def login() :
  53.     print ("Connecting to Reddit")
  54.     print ("Authenticating...", end='')
  55.     r = praw.Reddit(username = config.username,
  56.                 password = config.password,
  57.                 client_id = config.client_id,
  58.                 client_secret = config.client_secret,
  59.                 user_agent = config.user_agent)
  60.     print ('done')
  61.     return r
  62.  
  63. #___________________________________________
  64.  
  65.  
  66.  
  67.  
  68. #Define function RUN_BOT
  69. def run_bot(r, comments_replied_to, execount, jestcount, vigcount, coNumber, printCRT, version) :
  70.     print ("Obtaining comments")
  71.  
  72.     #Obtaining comments
  73.     for comment in r.subreddit('townofsalemgame').comments(limit = coNumber) :
  74.         if comment.author not in config.banned :
  75.             if comment.id not in comments_replied_to and comment.author != r.user.me() :
  76.                 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() :
  77.                     if "execute" not in comment.body.lower():
  78.                         print ("Found valid string for EXE at " + comment.id)
  79.                         if reply == True :
  80.                             execount += 1
  81.                             comment.reply ("Executioners silenced: " + str(execount) + "." + "\n \n" +
  82.                                            "Beep Boop. I am a bot. Please contact NateNate60 for any suggestions, questions, ~~and complaints~~"
  83.                                            + "\n \n ^ShutUpExeBot ^Version " + "^" + version)
  84.                             print ("The current execount is: ", str(execount) + ". Reply successful.")
  85.                             comments_replied_to.append (comment.id)
  86.                             with open ('comments.txt', 'a') as f :
  87.                                 f.write (comment.id + "\n")
  88.                             open('execount.txt', 'w').close()
  89.                             with open ('execount.txt', 'a') as exe :
  90.                                 exe.write (str(execount))
  91.                             if printCRT == True :
  92.                                 print ("Comments that the bot has replied to: " + str(comments_replied_to))
  93.                 elif "silence" in comment.body.lower() and "exe" in comment.body.lower() :
  94.                     print ("Found valid string for EXE at " + comment.id)
  95.                     if reply == True :
  96.                         execount += 1
  97.                         comment.reply ("Executioners silenced: " + str(execount) + "." + "\n \n" +
  98.                                        "Beep Boop. I am a bot. Please contact NateNate60 for any suggestions, questions, ~~and complaints~~"
  99.                                        "\n \n ^ShutUpExeBot ^Version " + "^" + version)
  100.                         print ("The current execount is: ", str(execount) + ". Reply successful.")
  101.                         comments_replied_to.append (comment.id)
  102.                         with open ('comments.txt', 'a') as f :
  103.                             f.write (comment.id + "\n")
  104.                         open('execount.txt', 'w').close()
  105.                         with open ('execount.txt', 'a') as exe :
  106.                             exe.write (str(execount))
  107.                         if printCRT == True :
  108.                             print ("Comments that the bot has replied to: " + str(comments_replied_to))
  109.                 elif "shut up jest" in comment.body.lower() or "u jest" in comment.body.lower() or "re jest" in comment.body.lower() :
  110.                     print ("Found valid string for JEST at " + comment.id)
  111.                     if reply == True :
  112.                         jestcount += 1
  113.                         comment.reply ("Jesters discovered: " + str(jestcount) + "." + "\n \n" +
  114.                                        "Beep Boop. I am a bot. Please contact NateNate60 for any suggestions, questions, ~~and complaints.~~"
  115.                                        + "\n \n ^ShutUpExeBot ^Version " + "^" + version)
  116.                         print ("The current jestcount is: ", str(jestcount) + ". Reply successful.")
  117.                         comments_replied_to.append (comment.id)
  118.                         with open ('comments.txt', 'a') as f :
  119.                             f.write (comment.id + "\n")
  120.                         open('jestcount.txt', 'w').close()
  121.                         with open ('jestcount.txt', 'a') as jest :
  122.                             jest.write (str(jestcount))
  123.                         if printCRT == True :
  124.                             print ("Comments that the bot has replied to: " + str(comments_replied_to))
  125.                 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() :
  126.                     print ("Found valid string for MAYOR at " + comment.id)
  127.                     if reply == True :
  128.                         vigcount += 1
  129.                         comment.reply ("You were shot by a Vigilante! Mayors shot: " + str(vigcount) + ". \n \n" +
  130.                                        "Beep Boop. I am a bot. Please contact NateNate60 for any suggestions, questions, ~~and complaints~~" +
  131.                                        "\n \n ^ShutUpExeBot ^Version " + "^" + version)
  132.                         print ("The current vigcount is: ", str(vigcount) + ". Reply successful.")
  133.                         comments_replied_to.append (comment.id)
  134.                         with open ('comments.txt', 'a') as f :
  135.                             f.write (comment.id + "\n")
  136.                         open ('vigcount.txt', 'w').close()
  137.                         with open ('vigcount.txt', 'a') as vig :
  138.                             vig.write (str(jestcount))
  139.                         if printCRT == True :
  140.                             print ("Comments that the bot has replied to: " + str(comments_replied_to))
  141.                 elif "is maf" in comment.body.lower() :
  142.                     if "m sheriff" in comment.body.lower() :
  143.                         print ("Found valid string for SHERIFF at " + comment.id)
  144.                         if reply == True :
  145.                             comment.reply ("Please kindly close thine talking-cavity, person who kills convicted invididuals on behalf of the Government." + "\n \n" +
  146.                                            "Beep Boop. I am a bot. Please contact NateNate60 for any suggestions, questions, ~~and complaints~~" +
  147.                                            "\n \n ^ShutUpExeBot ^Version " + "^" + version)
  148.                             comments_replied_to.append (comment.id)
  149.                             with open ('comments.txt', 'a') as f :
  150.                                 f.write (comment.id + "\n")
  151.                             if printCRT == True :
  152.                                 print ("Comments that the bot has replied to: " + str(comments_replied_to))
  153.                 elif "tarnation john wil" in comment.body.lower() :
  154.                     print ("Found valid string for WILLARD at " + comment.id)
  155.                     if reply == True :
  156.                         comment.reply ("Yes, tarnation John Willard indeed." + "\n \n" +
  157.                                        "Beep Boop. I am a bot. Please contact NateNate60 for any suggestions, questions, ~~and complaints~~" +
  158.                                        "\n \n ^ShutUpExeBot ^Version " + "^" + version)
  159.                         comments_replied_to.append (comment.id)
  160.                         with open ('comments.txt', 'a') as f :
  161.                             f.write (comment.id + "\n")
  162.                         if printCRT == True :
  163.                             print ("Comments that the bot has replied to: " + str(comments_replied_to))
  164.                 elif "died last night" in comment.body.lower() and "he was" in comment.body.lower() or "dead in their home last night" in comment.body.lower() and "he was" in comment.body.lower() :
  165.                     print ("Found valid string for DEATH at " + comment.id)
  166.                     if reply == True :
  167.                         comment.reply ("I bet you were the one that killed them." + "\n \n" +
  168.                                        "Beep Boop. I am a bot. Please contact NateNate60 for any suggestions, questions, ~~and complaints~~" +
  169.                                        "\n \n ^ShutUpExeBot ^Version " + "^" + version)
  170.                         comments_replied_to.append (comment.id)
  171.                         with open ('comments.txt', 'a') as f :
  172.                             f.write (comment.id + '\n')
  173.                         if printCRT == True :
  174.                             print ("Comments that the bot has replied to: " + str(comments_replied_to))
  175.                 elif "incognito" in comment.body.lower() and "mode" in comment.body.lower() :
  176.                     print ("Found valid string for INCOGNITO at " + comment.id)
  177.                     if reply == True :
  178.                         comment.reply ("Incognito mode? Remember to close your malarky before making screenshots." + "\n \n" +
  179.                                        "Beep Boop. I am a bot. Please contact NateNate60 for any suggestions, questions, ~~and complaints~~" +
  180.                                        "\n \n ^ShutUpExeBot ^Version " + "^" + version)
  181.                         comments_replied_to.append (comment.id)
  182.                         with open ('comments.txt', 'a') as f :
  183.                             f.write (comment.id + '\n')
  184.                         if printCRT == True :
  185.                             print ("Comments that the bot has replied to: " + str(comments_replied_to))
  186.     print ("Fetching inbox")
  187.     for message in r.inbox.unread(limit = coNumber/10) :
  188.         if message.id not in comments_replied_to :
  189.             if "bad" in message.body.lower() and "bot" in  message.body.lower() :
  190.                 if reply == True :
  191.                     message.reply ("Bah, tarnation you anyways. If I got something wrong, please contact NateNate60." + "\n \n" +
  192.                                    "^ShutUpExeBot ^Version " + "^" + version)
  193.                     print ("Found valid string for BADBOT at " + message.id)
  194.                     comments_replied_to.append (message.id)
  195.                     with open ('comments.txt', 'a') as f :
  196.                         f.write (message.id + "\n")
  197.             elif "shut up" in message.body.lower() and "bot" in message.body.lower() or "begone" in message.body.lower() and "bot" in message.body.lower :
  198.                 print ("Found valid string for SHUTUPBOT at " + message.id)
  199.                 if reply == True :
  200.                     message.reply ("Begone, executioner." + "\n \n" +
  201.                                    "^ShutUpExeBot ^Version " + "^" + version)
  202.                     comments_replied_to.append (message.id)
  203.                     with open ('comments.txt', 'a') as f :
  204.                         f.write (message.id + "\n")
  205.             elif "silence" in message.body.lower() and "bot" in message.body.lower() :
  206.                 if reply == True :
  207.                     message.reply ("Begone, executioner." + "\n \n" +
  208.                                    "^ShutUpExeBot ^Version " + "^" + version)
  209.                     comments_replied_to.append (message.id)
  210.                     with open ('comments.txt', 'a') as f :
  211.                         f.write (message.id + "\n")
  212.             elif "good" in message.body.lower() and "bot" in message.body.lower() :
  213.                 if reply == True :
  214.                     message.reply ("Thank you for the praise, human." + "\n \n" +
  215.                                    "^ShutUpExeBot ^Version " + "^" + version)
  216.                     comments_replied_to.append (message.id)
  217.                     with open ('comments.txt', 'a') as f :
  218.                         f.write (message.id + "\n")
  219.             elif "!blacklist" in message.body.lower() :
  220.                 print (str(message.author) + " requested to be blacklisted")
  221.                 if reply == True :
  222.                     message.reply ("You have been blacklisted. To be unblacklisted, please contact u/NateNate60." + "\n \n" +
  223.                                    "^ShutUpExeBot ^Version " + "^" + version)
  224.                     comments_replied_to.append (message.id)
  225.                     with open ('comments.txt', 'a') as f :
  226.                         f.write (message.id + "\n")
  227.                     config.banned.append (message.author)
  228.     print ("The bot is resting for 5 seconds")
  229.     time.sleep (5)
  230.     return execount, comments_replied_to
  231.  
  232.  
  233.  
  234.  
  235.  
  236. #Define function GET_COMMENT_LIST
  237. def get_comment_list() :
  238.     with open ("comments.txt", "r") as f :
  239.         comments_replied_to = f.read()
  240.         comments_replied_to = comments_replied_to.split("\n")
  241.     return comments_replied_to
  242.  
  243. def get_execount() :
  244.     with open ("execount.txt", "r") as exe :
  245.         execount = exe.read ()
  246.         execount = int(execount)
  247.     return execount
  248.  
  249. def get_jestcount() :
  250.     with open ("jestcount.txt", "r") as jest :
  251.         jestcount = jest.read()
  252.         jestcount = int(jestcount)
  253.     return jestcount
  254. def get_vigcount() :
  255.     with open ('vigcount.txt', 'r') as vig :
  256.         vigcount = vig.read()
  257.         vigcount = int(vigcount)
  258.     return vigcount
  259.  
  260. print ('done')
  261.  
  262.  
  263.  
  264. #Log in
  265. r = login()
  266.  
  267. #Set empty list for comments_replied_to
  268. comments_replied_to = get_comment_list()
  269.  
  270. print ("Blacklisted users: ", config.banned)
  271. print ("Loaded.")
  272.  
  273. #Run forever
  274. while True :
  275.     execount = get_execount()
  276.     jestcount = get_jestcount()
  277.     vigcount = get_vigcount()
  278.     run_bot(r, comments_replied_to, execount, jestcount, vigcount, coNumber, printCRT, version)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement