Advertisement
NateNate60

Shut Up Exe Bot source code (Ver. 8)

Jan 8th, 2019
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 18.12 KB | None | 0 0
  1. #Patch Notes
  2. """
  3. Work has begun on integrating Shut Up Exe Bot with WillardPoints Bot.
  4.  
  5. The goal is to make it so that SUEB can issue Willard Points to redditors
  6. that trigger execount and jestcount.
  7. """
  8.  
  9. #Version number, as a string
  10. version = "8.0"
  11. print ("Starting Shut_Up_Exe_Bot version " + version)
  12.  
  13.  
  14. #Import the required modules
  15. print ("Importing modules...", end='')
  16. import praw
  17. import config
  18. import time as t
  19. import datetime
  20. print ('done')
  21. print ("Loading features...", end='')
  22.  
  23. #Testing mode. True for testing mode off and False for on
  24. reply = True
  25.  
  26. #Choose whether the bot should print the list of comments replied to after every
  27. # reply. False for don't print, True for print.
  28. printCRT = False
  29.  
  30. #Maximum number of comments to check in one cycle. Must be a multiple of 5!
  31. # For the fastest, set this to 15, which is the minimum. I recommend 50 if
  32. # your hardware allows.
  33. coNumber = 30
  34.  
  35. # Set the tick
  36. tick = 0
  37.  
  38.  
  39. #Define function LOGIN
  40. def login() :
  41.     print ("Connecting to Reddit")
  42.     print ("Authenticating...", end='')
  43.     r = praw.Reddit(username = config.username,
  44.                 password = config.password,
  45.                 client_id = config.client_id,
  46.                 client_secret = config.client_secret,
  47.                 user_agent = config.user_agent)
  48.     print ('done')
  49.     return r
  50.  
  51. #___________________________________________
  52.  
  53.  
  54.  
  55.  
  56. #Define function RUN_BOT
  57. def run_bot(r, comments_replied_to, execount, jestcount, vigcount, coNumber, printCRT, version, tick, time) :
  58.     if tick == 1 :
  59.         coNumber = coNumber * 20
  60.     #Obtaining comments
  61.     for comment in r.subreddit('townofsalemgame+over50kmp+townofcirclejerk').comments(limit = coNumber) :
  62.         if comment.author not in config.banned :
  63.             if comment.id not in comments_replied_to and comment.author != r.user.me() :
  64.                 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() or "!trigger 1" in comment.body.lower() and comment.author == "NateNate60" :
  65.                     if "execute" not in comment.body.lower() and "jail" not in comment.body.lower() and "don" not in comment.body.lower():
  66.                         print (time + ":", "Found valid string for EXE at " + comment.id)
  67.                         if reply == True :
  68.                             execount += 1
  69.                             comment.reply ("Executioners silenced: " + str(execount) + ". You have been awarded 1 Willard Point!" + "\n \n" +
  70.                                            "Beep Boop. I am a bot. Please contact NateNate60 for any suggestions, questions, ~~and complaints~~"
  71.                                            + "\n \n ^ShutUpExeBot ^Version " + "^" + version)
  72.                             print ("The current execount is: ", str(execount) + ". Reply successful.")
  73.                             comments_replied_to.append (comment.id)
  74.                             with open ('comments.txt', 'a') as f :
  75.                                 f.write (comment.id + "\n")
  76.                             open('execount.txt', 'w').close()
  77.                             with open ('execount.txt', 'a') as exe :
  78.                                 exe.write (str(execount))
  79.                             if printCRT == True :
  80.                                 print ("Comments that the bot has replied to: " + str(comments_replied_to))
  81.                             award (1, comment.author)
  82.                 elif "silence" in comment.body.lower() and "exe" in comment.body.lower() :
  83.                     print (time + ":", "Found valid string for EXE at " + comment.id)
  84.                     if reply == True :
  85.                         execount += 1
  86.                         comment.reply ("Executioners silenced: " + str(execount) + ". You have been awarded 1 Willard Point!" + "\n \n" +
  87.                                        "Beep Boop. I am a bot. Please contact NateNate60 for any suggestions, questions, ~~and complaints~~"
  88.                                        "\n \n ^ShutUpExeBot ^Version " + "^" + version)
  89.                         print ("The current execount is: ", str(execount) + ". Reply successful.")
  90.                         comments_replied_to.append (comment.id)
  91.                         with open ('comments.txt', 'a') as f :
  92.                             f.write (comment.id + "\n")
  93.                         open('execount.txt', 'w').close()
  94.                         with open ('execount.txt', 'a') as exe :
  95.                             exe.write (str(execount))
  96.                         if printCRT == True :
  97.                             print ("Comments that the bot has replied to: " + str(comments_replied_to))
  98.                         award (1, comment.author)
  99.                 elif "shut up jest" in comment.body.lower() or "u jest" in comment.body.lower() or "re jest" in comment.body.lower() :
  100.                     print (time + ":", "Found valid string for JEST at " + comment.id)
  101.                     if reply == True :
  102.                         jestcount += 1
  103.                         comment.reply ("Jesters discovered: " + str(jestcount) + ". You have been awarded 1 Willard Point!" + "\n \n" +
  104.                                        "Beep Boop. I am a bot. Please contact NateNate60 for any suggestions, questions, ~~and complaints.~~"
  105.                                        + "\n \n ^ShutUpExeBot ^Version " + "^" + version)
  106.                         print ("The current jestcount is: ", str(jestcount) + ". Reply successful.")
  107.                         comments_replied_to.append (comment.id)
  108.                         with open ('comments.txt', 'a') as f :
  109.                             f.write (comment.id + "\n")
  110.                         open('jestcount.txt', 'w').close()
  111.                         with open ('jestcount.txt', 'a') as jest :
  112.                             jest.write (str(jestcount))
  113.                         if printCRT == True :
  114.                             print ("Comments that the bot has replied to: " + str(comments_replied_to))
  115.                         award (1, comment.author)
  116.                 elif "has revealed themse" in comment.body.lower() and "mayor" in comment.body.lower() or "has revealed himself as the mayor" in comment.body.lower() or "i'm mayor" in comment.body.lower() :
  117.                     print (time + ":", "Found valid string for MAYOR at " + comment.id)
  118.                     if reply == True :
  119.                         vigcount += 1
  120.                         comment.reply ("You were shot by a Vigilante! Mayors shot: " + str(vigcount) + ". \n \n" +
  121.                                        "Beep Boop. I am a bot. Please contact NateNate60 for any suggestions, questions, ~~and complaints~~" +
  122.                                        "\n \n ^ShutUpExeBot ^Version " + "^" + version)
  123.                         print ("The current vigcount is: ", str(vigcount) + ". Reply successful.")
  124.                         comments_replied_to.append (comment.id)
  125.                         with open ('comments.txt', 'a') as f :
  126.                             f.write (comment.id + "\n")
  127.                         open ('vigcount.txt', 'w').close()
  128.                         with open ('vigcount.txt', 'a') as vig :
  129.                             vig.write (str(jestcount))
  130.                         if printCRT == True :
  131.                             print ("Comments that the bot has replied to: " + str(comments_replied_to))
  132.                         award (1, comment.author)
  133.                 elif "is maf" in comment.body.lower() or "yo" in comment.body.lower() and "maf" in comment.body.lower() or "sus" in comment.body.lower() :
  134.                     if "m sheriff" in comment.body.lower() :
  135.                         print (time + ":", "Found valid string for SHERIFF at " + comment.id)
  136.                         if reply == True :
  137.                             comment.reply ("Please kindly close thine talking-cavity, person who kills convicted invididuals on behalf of the Government." + "\n \n" +
  138.                                            "Beep Boop. I am a bot. Please contact NateNate60 for any suggestions, questions, ~~and complaints~~" +
  139.                                            "\n \n ^ShutUpExeBot ^Version " + "^" + version)
  140.                             comments_replied_to.append (comment.id)
  141.                             with open ('comments.txt', 'a') as f :
  142.                                 f.write (comment.id + "\n")
  143.                             if printCRT == True :
  144.                                 print ("Comments that the bot has replied to: " + str(comments_replied_to))
  145.                 elif "tarnation john wil" in comment.body.lower() :
  146.                     print (time + ":", "Found valid string for WILLARD at " + comment.id)
  147.                     if reply == True :
  148.                         comment.reply ("Yes, tarnation John Willard indeed. You have been awarded 1 Willard Point!" + "\n \n" +
  149.                                        "Beep Boop. I am a bot. Please contact NateNate60 for any suggestions, questions, ~~and complaints~~" +
  150.                                        "\n \n ^ShutUpExeBot ^Version " + "^" + version)
  151.                         comments_replied_to.append (comment.id)
  152.                         with open ('comments.txt', 'a') as f :
  153.                             f.write (comment.id + "\n")
  154.                         if printCRT == True :
  155.                             print ("Comments that the bot has replied to: " + str(comments_replied_to))
  156.                         award (1, comment.author)
  157.                 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() :
  158.                     print (time + ":", "Found valid string for DEATH at " + comment.id)
  159.                     if reply == True :
  160.                         comment.reply ("I bet you were the one that killed them." + "\n \n" +
  161.                                        "Beep Boop. I am a bot. Please contact NateNate60 for any suggestions, questions, ~~and complaints~~" +
  162.                                        "\n \n ^ShutUpExeBot ^Version " + "^" + version)
  163.                         comments_replied_to.append (comment.id)
  164.                         with open ('comments.txt', 'a') as f :
  165.                             f.write (comment.id + '\n')
  166.                         if printCRT == True :
  167.                             print ("Comments that the bot has replied to: " + str(comments_replied_to))
  168.                 elif "incognito" in comment.body.lower() and "mode" in comment.body.lower() :
  169.                     print (time + ":", "Found valid string for INCOGNITO at " + comment.id)
  170.                     if reply == True :
  171.                         comment.reply ("Incognito mode? Remember to close your malarky before making screenshots." + "\n \n" +
  172.                                        "Beep Boop. I am a bot. Please contact NateNate60 for any suggestions, questions, ~~and complaints~~" +
  173.                                        "\n \n ^ShutUpExeBot ^Version " + "^" + version)
  174.                         comments_replied_to.append (comment.id)
  175.                         with open ('comments.txt', 'a') as f :
  176.                             f.write (comment.id + '\n')
  177.                         if printCRT == True :
  178.                             print ("Comments that the bot has replied to: " + str(comments_replied_to))
  179.                 elif "more weight" in comment.body.lower() or 'more wieght' in comment.body.lower() :
  180.                     print (time + ":", "Found valid string for WEIGHT at " + comment.id)
  181.                     if reply == True :
  182.                         comment.reply (">more weight" + "\n \n" + "Those are some famous words, spoken by Giles Corey during the IRL witch trials, " +
  183.                                        'after he refused to plead. He was then promptly dispatched with the "Splat!" death animation. Have a Willard Point!' + '\n \n' +
  184.                                        "Beep Boop. I am a bot. Please contact NateNate60 for any suggestions, questions, ~~and complaints~~" +
  185.                                        "\n \n ^ShutUpExeBot ^Version " + "^" + version)
  186.                         comments_replied_to.append (comment.id)
  187.                         with open ('comments.txt', 'a') as f :
  188.                             f.write (comment.id + '\n')
  189.                         if printCRT == True:
  190.                             print ("Comments that the bot has replied to: " + str(comments_replied_to))
  191.                         award (1, comment.author)
  192.  
  193.  
  194.     if tick%5 == 0 :
  195.         for message in r.inbox.unread(limit = coNumber/5) :
  196.             if message.id not in comments_replied_to :
  197.                 if "bad" in message.body.lower() and "bot" in  message.body.lower() :
  198.                     print (time + ":", "Found valid string for BADBOT at " + message.id)
  199.                     if reply == True :
  200.                         message.reply ("Bah, tarnation you anyways. If I got something wrong, please contact NateNate60." + "\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 "shut up" in message.body.lower() and "bot" in message.body.lower() or "begone" in message.body.lower() and "bot" in message.body.lower :
  206.                     print (time + ":", "Found valid string for SHUTUPBOT at " + message.id)
  207.                     if reply == True :
  208.                         message.reply ("Begone, executioner." + "\n \n" +
  209.                                        "^ShutUpExeBot ^Version " + "^" + version)
  210.                         comments_replied_to.append (message.id)
  211.                         with open ('comments.txt', 'a') as f :
  212.                             f.write (message.id + "\n")
  213.                 elif "silence" in message.body.lower() and "bot" in message.body.lower() :
  214.                     print (time + ":", 'Found valid string for SILENCEBOT at ' + message.id)
  215.                     if reply == True :
  216.                         message.reply ("Begone, executioner." + "\n \n" +
  217.                                        "^ShutUpExeBot ^Version " + "^" + version)
  218.                         comments_replied_to.append (message.id)
  219.                         with open ('comments.txt', 'a') as f :
  220.                             f.write (message.id + "\n")
  221.                 elif "good" in message.body.lower() and "bot" in message.body.lower() :
  222.                     print (time + ":", "Found valid string for PRAISE at", message.id)
  223.                     if reply == True :
  224.                         message.reply ("Thank you for the praise, human. If it make you happy, here's a Willard Point!" + "\n \n" +
  225.                                        "^ShutUpExeBot ^Version " + "^" + version)
  226.                         comments_replied_to.append (message.id)
  227.                         with open ('comments.txt', 'a') as f :
  228.                             f.write (message.id + "\n")
  229.                         award (1, message.author)
  230.                 elif "!blacklist" in message.body.lower() :
  231.                     print (time + ":", str(message.author) + " requested to be blacklisted")
  232.                     if reply == True :
  233.                         message.reply ("You have been blacklisted. To be unblacklisted, please contact u/NateNate60." + "\n \n" +
  234.                                        "^ShutUpExeBot ^Version " + "^" + version)
  235.                         comments_replied_to.append (message.id)
  236.                         with open ('comments.txt', 'a') as f :
  237.                             f.write (message.id + "\n")
  238.                         config.banned.append (message.author)
  239.                 elif "!sleep" in message.body.lower() :
  240.                     pass
  241.  
  242.     t.sleep (5)
  243.     return comments_replied_to, execount, jestcount, vigcount
  244.  
  245.  
  246.  
  247.  
  248. #Define function AWARD, which awards Willard Points.
  249. def award (award, user) :
  250.     with open ("transactions.txt", 'a') as trans :
  251.         trans.write (user + "+" + award)
  252.  
  253.  
  254.  
  255. #Define function GET_COMMENT_LIST
  256. def get_comment_list() :
  257.     with open ("comments.txt", "r") as f :
  258.         comments_replied_to = f.read()
  259.         comments_replied_to = comments_replied_to.split("\n")
  260.     return comments_replied_to
  261.  
  262. def get_execount() :
  263.     with open ("execount.txt", "r") as exe :
  264.         execount = exe.read ()
  265.         execount = int(execount)
  266.     return execount
  267.  
  268. def get_jestcount() :
  269.     with open ("jestcount.txt", "r") as jest :
  270.         jestcount = jest.read()
  271.         jestcount = int(jestcount)
  272.     return jestcount
  273. def get_vigcount() :
  274.     with open ('vigcount.txt', 'r') as vig :
  275.         vigcount = vig.read()
  276.         vigcount = int(vigcount)
  277.     return vigcount
  278.  
  279. print ('done')
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286. #Get time
  287. print ("Getting time...", end='')
  288. st = t.time()
  289. st = datetime.datetime.fromtimestamp(st).strftime('%Y-%m-%d %H:%M:%S')
  290. time = st
  291. print ('done.')
  292. print ("Right now, it's UTC" , time)
  293.  
  294.  
  295. #Log in
  296. r = login()
  297.  
  298. #Set empty list for comments_replied_to
  299. comments_replied_to = get_comment_list()
  300.  
  301. print ("Blacklisted users: ", config.banned)
  302. print ("Loaded.")
  303.  
  304. #Run forever
  305. while True :
  306.     st = t.time()
  307.     st = datetime.datetime.fromtimestamp(st).strftime('%Y-%m-%d %H:%M:%S')
  308.     time = st
  309.     execount = get_execount()
  310.     jestcount = get_jestcount()
  311.     vigcount = get_vigcount()
  312.     run_bot(r, comments_replied_to, execount, jestcount, vigcount, coNumber, printCRT, version, tick, time)
  313.     tick += 1
  314.     if tick == 1 :
  315.         print (time + ":", "The bot has successfully completed one cycle.")
  316.     elif tick == 5 :
  317.         print (time + ":", 'The bot has successfully completed 5 cycles.')
  318.     elif tick%10 == 0 and tick < 100 :
  319.         print (time + ":", 'The bot has successfully completed', tick, "cycles.")
  320.     elif tick%100 == 0 and tick < 500 :
  321.         print (time + ":", 'The bot has successfully completed', tick, "cycles.")
  322.     elif tick%500 == 0 and tick < 3000:
  323.         print (time + ":", 'The bot has successfully completed', tick, "cycles.")
  324.     elif tick%1000 == 0 :
  325.         print (time + ":", 'The bot has successfully completed', tick, "cycles.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement