Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.69 KB | None | 0 0
  1. import praw
  2. import config
  3. import time
  4. import re
  5.  
  6. def bot_login():
  7. print ("\nLoggin in...")
  8. r = praw.Reddit(username = config.username,
  9. password = config.password,
  10. client_id = config.client_id, # Messy stuff at the beginning
  11. client_secret = config.client_secret,
  12. user_agent = "tybug's testing bot ")
  13. print ("I've logged on!")
  14.  
  15. return r
  16.  
  17.  
  18. limit = 5
  19. version = "0.4"
  20. Question_thread_goal = 50
  21. Fame_train_goal = 10
  22. Guild_recruitment_goal = 10
  23.  
  24. weekly_question_thread_link = "https://www.reddit.com/r/RotMG/comments/6soxcy/" # Posted August 10th
  25.  
  26. # Main Function
  27.  
  28. def main(r): # No idea why it needs r
  29. print("Start of` a fresh run:")
  30. for submission in r.subreddit('rotmg').new(limit=limit): # For each of the submissions on r/rotmg/new, up to submission # limit...
  31.  
  32.  
  33. # Nasty set of if statements for each regex needing to be checked, very inneficient but it works
  34. # A demo with comments is below:
  35.  
  36. # infractions = 0 # number of penalty points accumulated
  37.  
  38. # matcher = re.match("Does",submission.title) # Regex for the if statement, chenges every if statement
  39.  
  40. # if(matcher != None): # If the matcher found something in the body of the post
  41. # print("Success!") # Debugger
  42. # infractions = infractions + 10 # Add penalty points
  43.  
  44.  
  45.  
  46.  
  47. # Start of Question Thread Checker
  48. print("\n" + submission.title)
  49.  
  50. infractions = 0
  51.  
  52. matcher = re.match(".+\?",submission.title) # Question mark at the end of the title
  53. if(matcher != None):
  54. infractions = infractions + 40
  55. print("Infractions: " + str(infractions))
  56. print("Number: 1")
  57.  
  58. matcher = re.match("(?i)(which|what) (character|pet|weapon|character) (?:\w+ ?){0,4} (max|feed|fuse|hatch|equip|buy|)",submission.selftext)
  59. if(matcher != None):
  60. infractions = infractions + 10
  61. print("Infractions: " + str(infractions))
  62. print("Number: 2 \n")
  63.  
  64. matcher = re.match("(?i)(how|what) (good|bad|terrible|awesome|amazing|okay) (?:\w+ ?){0,5} (skull|robe|spell|helm|wand|bow|armor|UT|shield|trap|ring)",submission.title)
  65. if(matcher != None):
  66. infractions = infractions + 10
  67. print("Infractions: " + str(infractions))
  68. print("Number: 3 \n")
  69.  
  70. matcher = re.match("(?i)(how|what) (good|bad|terrible|awesome|amazing|okay) (?:\w+ ?){0,5} (skull|robe|spell|helm|wand|bow|armor|UT|shield|trap|ring)",submission.selftext)
  71. if(matcher != None):
  72. infractions = infractions + 10
  73. print("Infractions: " + str(infractions))
  74. print("Number: 4 \n")
  75.  
  76.  
  77. if(infractions >= Question_thread_goal): # Checks if enough infractions were accumulated to remove the post at the end
  78. #submission.remove(spam=False) (Not on a moderator account atm)
  79. submission.reply("**Autodetect: Question.** Please comment your question on the [stickied weekly question thread]" +
  80. (weekly_question_thread_link) + "instead of making a post on the subreddit, thank you! \n \n" +
  81. "--- \n \n ^(I am a bot, and this action was performed automatically) ^| ^(Version: " + version + " (Beta)^) ^| ^(Reply to leave feedback)")
  82. print("I've left a weekly question thread comment! \n")
  83.  
  84.  
  85. # End of Question Thread Checker
  86.  
  87.  
  88. infractions = 0
  89.  
  90.  
  91. # Start of Fame Train Checker
  92.  
  93. matcher = re.match("(?i)Looking for (?:\w+ ?){0,4} \w*train discord",submission.title)
  94. if(matcher != None):
  95. infractions = infractions + 10
  96. print("Infractions: " + str(infractions))
  97. print("Number: 5 \n")
  98.  
  99.  
  100. matcher = re.match("(?i)Looking for \w*train discord",submission.title)
  101. if(matcher != None):
  102. infractions = infractions + 10
  103. print("Infractions: " + str(infractions))
  104. print("Number: 6 \n")
  105.  
  106.  
  107. matcher = re.match("(?i)(where|what) is (?:\w+ ?){0,4} (\w*train|\w*train discord)",submission.title)
  108. if(matcher != None):
  109. infractions = infractions + 10
  110. print("Infractions: " + str(infractions))
  111. print("Number: 7 \n")
  112.  
  113. if(infractions >= Fame_train_goal):
  114. #submission.remove(spam=False) (Not on a moderator account atm)
  115. submission.reply("**Autodetect: Fame Train.** location. The Fame Train, previously located on the server EUN2, now moves around to whichever" +
  116. "realm provides the best fpm (fame per minute). Their current location can be found in the #click-here-for-train channel of their discord:" +
  117. "https://discord.gg/pVGQe7g. \n \n" +
  118. "--- \n \n ^(I am a bot, and this action was performed automatically) ^| ^(Version: " + version + " (Beta)^) ^| ^(Reply to leave feedback)")
  119. print("I've left a fame train comment! \n")
  120.  
  121. # End of Fame Train Checker
  122.  
  123.  
  124. infractions = 0
  125.  
  126.  
  127. # Start of Guild Recruitment Checker
  128.  
  129. matcher = re.match("(?i)Recruiting for",submission.title)
  130. if(matcher != None):
  131. infractions = infractions + 10
  132. print("Infractions: " + str(infractions))
  133. print("Number: 8 \n")
  134.  
  135. matcher = re.match("(?i)Looking for (?:\w+ ?){0,3} guild",submission.title)
  136. if(matcher != None):
  137. infractions = infractions + 10
  138. print("Infractions: " + str(infractions))
  139. print("Number: 9 \n")
  140.  
  141. matcher = re.match("(?i)Looking for (?:\w+ ?){0,3} guild",submission.selftext)
  142. if(matcher != None):
  143. infractions = infractions + 10
  144. print("Infractions: " + str(infractions))
  145. print("Number: 10 \n")
  146.  
  147. matcher = re.match("(?i)Requirement (?:\w+ ?){0,4} (./8|fame)",submission.selftext)
  148. if(matcher != None):
  149. infractions = infractions + 10
  150. print("Infractions: " + str(infractions))
  151. print("Number: 11 \n")
  152.  
  153. matcher = re.match("(?i)Requirement (?:\w+ ?){0,4} (./8|fame)",submission.title)
  154. if(matcher != None):
  155. infractions = infractions + 10
  156. print("Infractions: " + str(infractions))
  157. print("Number: 12 \n")
  158.  
  159.  
  160. if(infractions >= Guild_recruitment_goal):
  161. #submission.remove(spam=False) (Not on a moderator account atm)
  162. submission.reply("**Autodetect: Guild Recruitment/Looking to join a guild.** Please post over at the" +
  163. "[Realmeye Forums'] (https://www.realmeye.com/forum/c/guilds) guild recruitment section instead of reddit, thanks! \n \n" +
  164. "--- \n \n ^(I am a bot, and this action was performed automatically) ^| ^(Version: " + version + " (Beta)^) ^| ^(Reply to leave feedback)")
  165. print("I've left a guild recruitment comment! \n")
  166.  
  167. # End of Guild Recruitment Checker\
  168.  
  169.  
  170.  
  171. print ("\nFinished! Sleeping for 5 minutes... \n")
  172. time.sleep(300)
  173.  
  174.  
  175. r = bot_login() # Not sure what this does either honestly, but it works
  176.  
  177. while True:
  178. main(r)
  179.  
  180.  
  181.  
  182. # Notes for myself:
  183. #
  184. # submission.selftext = body of a text post, empty line for link posts
  185. # submission.author = author of a post
  186. # submission.remove(spam=False) = removes a post
  187. # re.match(pattern, string)
  188. # submission.title = title of a post
  189. # comment.reply("I am a cat") = how to reply to a comment
  190. #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement