Advertisement
NateNate60

Shut Up Exe Bot source code (Ver. 5)

Oct 22nd, 2018
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.19 KB | None | 0 0
  1. print ("Starting Shut_Up_Exe_Bot version 5")
  2.  
  3. #Patch Notes
  4. """
  5. The function for ignoring users is complete. It should not have any bugs in it,
  6. but feel free to contact me if you encounter any, and I will immediately fix
  7. them.
  8.  
  9. Added more trigger phrases.
  10.  
  11. The bot now states what version it is running in its replies. This has no real
  12. purpose other than to help me organise its comments.
  13.  
  14. Remember that the bot is in Testing Mode by default. Change the variable reply
  15. at line 25 to true to turn off Testing Mode.
  16. """
  17.  
  18. #Import the required modules
  19. import praw
  20. import config
  21. import time
  22. import os
  23.  
  24. #Testing mode
  25. reply = False
  26.  
  27.  
  28.  
  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) :
  49.     print ("Obtaining comments")
  50.    
  51.     #Obtaining comments
  52.     for comment in r.subreddit('townofsalemgame').comments(limit = 50) :
  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() :
  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" + "Beep Boop. I am a bot. Please contact NateNate60 for any suggestions, questions, ~~and complaints~~"
  60.                                        + "^ShutUpExeBot ^Version ^5")
  61.                         print ("The current execount is: ", str(execount) + ". Reply successful.")
  62.                         comments_replied_to.append (comment.id)
  63.                         with open ('comments.txt', 'a') as f :
  64.                             f.write (comment.id + "\n")
  65.                         open('execount.txt', 'w').close()
  66.                         with open ('execount.txt', 'a') as exe :
  67.                             exe.write (str(execount))
  68.                         print ("Comments that the bot has replied to: " + str(comments_replied_to))
  69.                 elif "shut up jest" in comment.body.lower() or "u jest" in comment.body.lower() or "re jest" in comment.body.lower() :
  70.                     print ("Found valid string for JEST at " + comment.id)
  71.                     if reply == True :
  72.                         jestcount += 1
  73.                         comment.reply ("Jesters discovered: " + str(jestcount) + "." + "\n \n" + "Beep Boop. I am a bot. Please contact NateNate60 for any suggestions, questions, ~~and complaints~~"
  74.                                        + "^ShutUpExeBot ^Version ^5")
  75.                         print ("The current jestcount is: ", str(jestcount) + ". Reply successful.")
  76.                         comments_replied_to.append (comment.id)
  77.                         with open ('comments.txt', 'a') as f :
  78.                             f.write (comment.id + "\n")
  79.                         open('jestcount.txt', 'w').close()
  80.                         with open ('jestcount.txt', 'a') as jest :
  81.                             jest.write (str(jestcount))
  82.                         print ("Comments that the bot has replied to: " + str(comments_replied_to))
  83.                 elif "has revealed themselves as the mayor" in comment.body.lower() or "has revealed himself as the mayor" in comment.body.lower() :
  84.                     print ("Found valid string for MAYOR at " + comment.id)
  85.                     if reply == True :
  86.                         comment.reply ("You were shot by a Vigilante!" + "\n \n" + "Beep Boop. I am a bot. Please contact NateNate60 for any suggestions, questions, ~~and complaints~~"
  87.                                        + "^ShutUpExeBot ^Version ^5")
  88.                         comments_replied_to.append (comment.id)
  89.                         with open ('comments.txt', 'a') as f :
  90.                             f.write (comment.id + "\n")
  91.                         print ("Comments that the bot has replied to: " + str(comments_replied_to))
  92.                 elif "is maf" in comment.body.lower() and "m sheriff" in comments.body.lower :
  93.                     print ("Found valid string for SHERIFF at " + comment.id)
  94.                     if reply == True :
  95.                         comment.reply ("Please kindly close thine talking-cavity, executioner." + "\n \n" + "Beep Boop. I am a bot. Please contact NateNate60 for any suggestions, questions, ~~and complaints~~"
  96.                                        + "^ShutUpExeBot ^Version ^5")
  97.                         comments_replied_to,append (comment.id)
  98.                         with open ('comments.txt', 'a') as f :
  99.                             f.write (comment.id + "\n")
  100.                         print ("Comments that the bot has replied to: " + str(comments_replied_to))
  101.     print ("The bot is resting for 5 seconds")
  102.     time.sleep (5)
  103.     return execount, comments_replied_to
  104.  
  105.  
  106.  
  107.  
  108.  
  109. #Define function GET_COMMENT_LIST
  110. def get_comment_list() :
  111.     with open ("comments.txt", "r") as f :
  112.         comments_replied_to = f.read()
  113.         comments_replied_to = comments_replied_to.split("\n")
  114.     return comments_replied_to
  115.  
  116. def get_execount() :
  117.     with open ("execount.txt", "r") as exe :
  118.         execount = exe.read ()
  119.         execount = int(execount)
  120.     return execount
  121.  
  122. def get_jestcount() :
  123.     with open ("jestcount.txt", "r") as jest :
  124.         jestcount = jest.read()
  125.         jestcount = int(jestcount)
  126.     return jestcount
  127.  
  128.  
  129.  
  130. #Log in
  131. r = login()
  132.  
  133. #Set empty list for comments_replied_to
  134. comments_replied_to = get_comment_list()
  135.  
  136. print ("Blacklisted users: ", config.banned)
  137. print ("Loaded.")
  138.  
  139. #Run forever
  140. while True :
  141.     execount = get_execount()
  142.     jestcount = get_jestcount()
  143.     run_bot(r, comments_replied_to, execount, jestcount)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement