Advertisement
NateNate60

Shut Up Exe Bot source code (Ver. 9)

Apr 7th, 2019
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.45 KB | None | 0 0
  1. import prawcore.exceptions as e
  2. while True :
  3. try :
  4. #Patch Notes
  5. """
  6. SUEB can now process some WPB commands.
  7. """
  8.  
  9. #Version number, as a string
  10. version = "9.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. import os.path
  21. print ('done')
  22. print ("Loading features...", end='')
  23.  
  24. #Testing mode. True for testing mode off and False for on
  25. reply = True
  26.  
  27. #Choose whether the bot should print the list of comments replied to after every
  28. # reply. False for don't print, True for print.
  29. printCRT = False
  30.  
  31. #Maximum number of comments to check in one cycle. Must be a multiple of 5!
  32. # For the fastest, set this to 15, which is the minimum. I recommend 50 if
  33. # your hardware allows.
  34. coNumber = 30
  35.  
  36. # Set the tick
  37. tick = 0
  38.  
  39. #Signature
  40. signature = "^NateNate60's ^ShutUpExeBot ^Version ^" + version + " ^Reply ^!info ^for ^information"
  41.  
  42.  
  43. #Define function LOGIN
  44. def login() :
  45. print ("Connecting to Reddit")
  46. print ("Authenticating...", end='')
  47. r = praw.Reddit(username = config.username,
  48. password = config.password,
  49. client_id = config.client_id,
  50. client_secret = config.client_secret,
  51. user_agent = config.user_agent)
  52. print ('done')
  53. return r
  54.  
  55. #___________________________________________
  56.  
  57.  
  58.  
  59.  
  60. #Define function RUN_BOT
  61. def run_bot(r, comments_replied_to, execount, jestcount, vigcount, coNumber, printCRT, version, tick, time, signature) :
  62. if tick == 1 :
  63. coNumber = 1000
  64. #Obtaining comments
  65. for comment in r.subreddit('townofsalemgame+over50kmp+townofcirclejerk').comments(limit = coNumber) :
  66. if comment.author not in config.banned :
  67. if comment.id not in comments_replied_to and comment.author != r.user.me() :
  68. if "shut up" in comment.body.lower() and "exe" in comment.body.lower() or "u exe" in comment.body.lower() or "silence exe" in comment.body.lower() or "!trigger 1" in comment.body.lower() and comment.author == "NateNate60" :
  69. if "execute" not in comment.body.lower() and "jail" not in comment.body.lower() and "don" not in comment.body.lower() and "bot" not in comment.body.lower() :
  70. print (time + ":", "Found valid string for EXE at " + comment.id)
  71. if reply == True :
  72. execount += 1
  73. comment.reply ("Executioners silenced: " + str(execount) + ". \n \n You have been awarded 1 Willard Point!" + "\n \n"
  74. + signature)
  75. print ("The current execount is: ", str(execount) + ". 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('execount.txt', 'w').close()
  80. with open ('execount.txt', 'a') as exe :
  81. exe.write (str(execount))
  82. if printCRT == True :
  83. print ("Comments that the bot has replied to: " + str(comments_replied_to))
  84. award (1, comment.author)
  85. elif "silence" in comment.body.lower() and "exe" in comment.body.lower() :
  86. print (time + ":", "Found valid string for EXE at " + comment.id)
  87. if reply == True :
  88. execount += 1
  89. comment.reply ("Executioners silenced: " + str(execount) + ". \n \n You have been awarded 1 Willard Point!" + "\n \n"
  90. + signature)
  91. print ("The current execount is: ", str(execount) + ". Reply successful.")
  92. comments_replied_to.append (comment.id)
  93. with open ('comments.txt', 'a') as f :
  94. f.write (comment.id + "\n")
  95. open('execount.txt', 'w').close()
  96. with open ('execount.txt', 'a') as exe :
  97. exe.write (str(execount))
  98. if printCRT == True :
  99. print ("Comments that the bot has replied to: " + str(comments_replied_to))
  100. award (1, comment.author)
  101. elif "shut up jest" in comment.body.lower() or "u jest" in comment.body.lower() or "re jest" in comment.body.lower() :
  102. print (time + ":", "Found valid string for JEST at " + comment.id)
  103. if reply == True :
  104. jestcount += 1
  105. comment.reply ("Jesters discovered: " + str(jestcount) + ".\n \n You have been awarded 1 Willard Point!" + "\n \n"
  106. + signature)
  107. print ("The current jestcount is: ", str(jestcount) + ". Reply successful.")
  108. comments_replied_to.append (comment.id)
  109. with open ('comments.txt', 'a') as f :
  110. f.write (comment.id + "\n")
  111. open('jestcount.txt', 'w').close()
  112. with open ('jestcount.txt', 'a') as jest :
  113. jest.write (str(jestcount))
  114. if printCRT == True :
  115. print ("Comments that the bot has replied to: " + str(comments_replied_to))
  116. award (1, comment.author)
  117. 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() :
  118. print (time + ":", "Found valid string for MAYOR at " + comment.id)
  119. if reply == True :
  120. vigcount += 1
  121. comment.reply ("You were shot by a Vigilante! Mayors shot: " + str(vigcount) + ". \n \n" +
  122. signature)
  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. signature)
  139. comments_replied_to.append (comment.id)
  140. with open ('comments.txt', 'a') as f :
  141. f.write (comment.id + "\n")
  142. if printCRT == True :
  143. print ("Comments that the bot has replied to: " + str(comments_replied_to))
  144. elif "tarnation john wil" in comment.body.lower() :
  145. print (time + ":", "Found valid string for WILLARD at " + comment.id)
  146. if reply == True :
  147. comment.reply ("Yes, tarnation John Willard indeed. \n \n You have been awarded 1 Willard Point!" + "\n \n" +
  148. signature)
  149. comments_replied_to.append (comment.id)
  150. with open ('comments.txt', 'a') as f :
  151. f.write (comment.id + "\n")
  152. if printCRT == True :
  153. print ("Comments that the bot has replied to: " + str(comments_replied_to))
  154. award (1, comment.author)
  155. 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() :
  156. print (time + ":", "Found valid string for DEATH at " + comment.id)
  157. if reply == True :
  158. comment.reply ("I bet you were the one that killed them." + "\n \n" +
  159. signature)
  160. comments_replied_to.append (comment.id)
  161. with open ('comments.txt', 'a') as f :
  162. f.write (comment.id + '\n')
  163. if printCRT == True :
  164. print ("Comments that the bot has replied to: " + str(comments_replied_to))
  165. elif "incognito" in comment.body.lower() and "mode" in comment.body.lower() :
  166. print (time + ":", "Found valid string for INCOGNITO at " + comment.id)
  167. if reply == True :
  168. comment.reply ("Incognito mode? Remember to close your malarky before making screenshots." + "\n \n" +
  169. signature)
  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 "more weight" in comment.body.lower() or 'more wieght' in comment.body.lower() :
  176. print (time + ":", "Found valid string for WEIGHT at " + comment.id)
  177. if reply == True :
  178. comment.reply (">more weight" + "\n \n" + "Those are some famous words, spoken by Giles Corey during the IRL witch trials, " +
  179. 'after he refused to plead. He was then promptly dispatched with the "Splat!" death animation. Have a Willard Point!' + '\n \n' +
  180. signature)
  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. award (1, comment.author)
  187.  
  188.  
  189. if tick%5 == 0 :
  190. for message in r.inbox.unread(limit = coNumber/5) :
  191. if message.id not in comments_replied_to :
  192. if "bad" in message.body.lower() and "bot" in message.body.lower() :
  193. print (time + ":", "Found valid string for BADBOT at " + message.id)
  194. if reply == True :
  195. message.reply ("no u! If I got something wrong, please contact NateNate60." + "\n \n" +
  196. signature)
  197. comments_replied_to.append (message.id)
  198. with open ('comments.txt', 'a') as f :
  199. f.write (message.id + "\n")
  200. 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() :
  201. print (time + ":", "Found valid string for SHUTUPBOT at " + message.id)
  202. if reply == True :
  203. message.reply ("Begone, executioner." + "\n \n" +
  204. signature)
  205. comments_replied_to.append (message.id)
  206. with open ('comments.txt', 'a') as f :
  207. f.write (message.id + "\n")
  208. elif "silence" in message.body.lower() and "bot" in message.body.lower() :
  209. print (time + ":", 'Found valid string for SILENCEBOT at ' + message.id)
  210. if reply == True :
  211. message.reply ("Begone, executioner." + "\n \n" +
  212. signature)
  213. comments_replied_to.append (message.id)
  214. with open ('comments.txt', 'a') as f :
  215. f.write (message.id + "\n")
  216. elif "good" in message.body.lower() and "bot" in message.body.lower() :
  217. print (time + ":", "Found valid string for PRAISE at", message.id)
  218. if reply == True :
  219. message.reply ("Thank you for the praise, human. If it makes you happy, here's a Willard Point!" + "\n \n" +
  220. signature)
  221. comments_replied_to.append (message.id)
  222. with open ('comments.txt', 'a') as f :
  223. f.write (message.id + "\n")
  224. award (1, message.author)
  225. elif "!blacklist" in message.body.lower() :
  226. print (time + ":", str(message.author) + " requested to be blacklisted")
  227. if reply == True :
  228. message.reply ("You have been blacklisted. To be unblacklisted, please contact u/NateNate60." + "\n \n" +
  229. signature)
  230. comments_replied_to.append (message.id)
  231. with open ('comments.txt', 'a') as f :
  232. f.write (message.id + "\n")
  233. config.banned.append (message.author)
  234. elif "!info" in message.body.lower() :
  235. print (time + ":", 'Found valid string for INFO at ' + message.id)
  236. if reply == True :
  237. message.reply ("HELLO and welcome to the info page of the NUMBER ONE DANKEST BOT IN ALL OF SALEM!!" + "\n \n" +
  238. 'What I do is I count the number of executioners that people have SILENCED MERCILESSLY with "shut up exe"! I also count the number of jesters in Salem!' +
  239. "DARE TO FIND ALL MY TRIGGER PHRASES! Or cheat and look on NateNate60's Pastebin." +
  240. " \n \n You may have also noticed that I occasionally award Willard Points to good humans. These don't stick around" +
  241. " unless you have a Willard Points account. To create an account to save up WP, message Willard_Points_Bot with `!newaccount`." +
  242. signature + " ^Tarnation ^a ^John ^Willard ^for ^a ^free ^Willard ^Point")
  243. comments_replied_to.append (message.id)
  244. with open ('comments.txt', 'a') as f :
  245. f.write (message.id + "\n")
  246. elif "!isup" in message.body.lower() or '!stat' in message.body.lower() :
  247. message.reply ("Online." + signature)
  248. comments_replied_to.append (message.id)
  249. with open ('comments.txt', 'a') as f :
  250. f.write (message.id + "\n")
  251. elif "!newacc" in message.body.lower() or "!createac" in message.body.lower() :
  252. if reply == True :
  253. if not os.path.isfile(str(message.author) + ".txt") :
  254. message.reply ("An account has been created. However, the 10 WP signing bonus has been forfeited because people do this so much on the wrong bot that the code has had to have been updated" +
  255. " resulting in dozens of lines of new code being written by NateNate60, and code-writing takes time, so the signing bonus has been consumed as a fee. Sorry. Maybe if you ask him nicely " +
  256. "you'll get it back." + signature)
  257. print (time, str(message.author), "created a WPB account at " + message.id)
  258. with open ('log.txt', 'a') as log :
  259. log.write ("\n" + time + ": " + str(message.author) + " opened an account through SUEB.")
  260. with open (str(message.author) + ".txt", 'w') as n :
  261. n.write ("0")
  262. else :
  263. with open (str(message.author) + ".txt", "r") as n :
  264. bal = n.read()
  265. message.reply ("You already have an account. You have " + bal + " Willard Points." + signature)
  266. comments_replied_to.append (message.id)
  267. with open ('comments.txt', 'a') as f :
  268. f.write (message.id + '\n')
  269. elif "!bal" in message.body :
  270. payload = message.body.split(" ")
  271. if len(payload) != 2 :
  272. message.reply ('Invalid syntax for balance checking. Try `!balance [username]`.' + signature)
  273. else :
  274. if os.path.isfile(payload[1] + ".txt") :
  275. with open (payload[1] + ".txt") as acc :
  276. bal = acc.read()
  277. message.reply("That account currently has " + bal + " Willard Points." + signature)
  278. print (time, str(message.author), "checked their WPB balance at " + message.id)
  279. else :
  280. message.reply ("That account does not exist. Use !newaccount" + signature)
  281. comments_replied_to.append (message.id)
  282. with open ('comments.txt', 'a') as f :
  283. f.write (message.id + "\n")
  284. t.sleep (5)
  285. return comments_replied_to, execount, jestcount, vigcount
  286.  
  287.  
  288.  
  289.  
  290. #Define function AWARD, which awards Willard Points.
  291. def award (award, user) :
  292. with open ("transactions.txt", 'a') as trans :
  293. trans.write ("\n" + str(user) + "+" + str(award))
  294.  
  295.  
  296.  
  297. #Define function GET_COMMENT_LIST
  298. def get_comment_list() :
  299. with open ("comments.txt", "r") as f :
  300. comments_replied_to = f.read()
  301. comments_replied_to = comments_replied_to.split("\n")
  302. return comments_replied_to
  303.  
  304. def get_execount() :
  305. with open ("execount.txt", "r") as exe :
  306. execount = exe.read ()
  307. execount = int(execount)
  308. return execount
  309.  
  310. def get_jestcount() :
  311. with open ("jestcount.txt", "r") as jest :
  312. jestcount = jest.read()
  313. jestcount = int(jestcount)
  314. return jestcount
  315. def get_vigcount() :
  316. with open ('vigcount.txt', 'r') as vig :
  317. vigcount = vig.read()
  318. vigcount = int(vigcount)
  319. return vigcount
  320.  
  321. print ('done')
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328. #Get time
  329. print ("Getting time...", end='')
  330. st = t.time()
  331. st = datetime.datetime.fromtimestamp(st).strftime('%Y-%m-%d %H:%M:%S')
  332. time = st
  333. print ('done.')
  334. print ("Right now, it's PST" , time)
  335.  
  336.  
  337. #Log in
  338. r = login()
  339.  
  340. #Set empty list for comments_replied_to
  341. comments_replied_to = get_comment_list()
  342.  
  343. print ("Blacklisted users: ", config.banned)
  344. print ("Loaded.")
  345.  
  346. #Run forever
  347. while True :
  348. st = t.time()
  349. st = datetime.datetime.fromtimestamp(st).strftime('%Y-%m-%d %H:%M:%S')
  350. time = st
  351. execount = get_execount()
  352. jestcount = get_jestcount()
  353. vigcount = get_vigcount()
  354. run_bot(r, comments_replied_to, execount, jestcount, vigcount, coNumber, printCRT, version, tick, time, signature)
  355. tick += 1
  356. if tick == 1 :
  357. print (time + ":", "The bot has successfully completed one cycle.")
  358. elif tick == 5 :
  359. print (time + ":", 'The bot has successfully completed 5 cycles.')
  360. elif tick%10 == 0 and tick < 100 :
  361. print (time + ":", 'The bot has successfully completed', tick, "cycles.")
  362. elif tick%100 == 0 and tick < 500 :
  363. print (time + ":", 'The bot has successfully completed', tick, "cycles.")
  364. elif tick%500 == 0 and tick < 3000:
  365. print (time + ":", 'The bot has successfully completed', tick, "cycles.")
  366. elif tick%1000 == 0 :
  367. print (time + ":", 'The bot has successfully completed', tick, "cycles.")
  368. except e.RequestException :
  369. print ("The bot crashed with RequestExcpetion. Restarting...")
  370. continue
  371. except PermissionError :
  372. print ("The bot crashed with PermissionError. Restarting...")
  373. continue
  374. except e.ServerError :
  375. print ('The bot crashed because it recieved a 503 HTTP error. Restarting...')
  376. continue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement