Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. import praw
  2. import config
  3. import time
  4. import re
  5.  
  6. def bot_login():
  7. print ("Loggin 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.  
  19.  
  20.  
  21. # Main Function
  22.  
  23. def main(r): # No idea why it needs r
  24. for submission in r.subreddit('rotmg').new(limit=10): # For each of the submissions on r/rotmg/new, up to submission # limit...
  25.  
  26. # Nasty set of if statements for each regex needing to be checked, very inneficient but it works
  27. # A demo with comments is below:
  28.  
  29. # infractions = 0 # number of penalty points accumulated
  30. # goal = 50 # number of penalty points neccesary to get removed, changes every mark (mark = Question Thread, Fame Train, etc)
  31.  
  32. # matcher = re.match("Does",submission.title) # Regex for the if statement, chenges every if statement
  33.  
  34. # if(matcher != None): # If the matcher found something in the body of the post
  35. # print("Success!") # Debugger
  36. # infractions = infractions + 10 # Add penalty points
  37.  
  38. # Start of Question Thread Checker
  39. print(submission.title)
  40. infractions = 0
  41. goal = 50
  42.  
  43. matcher = re.match(".+\?",submission.title) # Question mark at the end of the title
  44. if(matcher != None):
  45. infractions = infractions + 40
  46. print(infractions)
  47.  
  48. matcher = re.match("(?i)(which|what) (character|pet|weapon|character) (?:\w+ ?){0,4} (max|feed|fuse|hatch|equip|buy|)",submission.selftext)
  49. if(matcher != None):
  50. infractions = infractions + 10
  51. print(infractions)
  52.  
  53. 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)
  54. if(matcher != None):
  55. infractions = infractions + 10
  56. print(infractions)
  57.  
  58. 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)
  59. if(matcher != None):
  60. infractions = infractions + 10
  61. print(infractions)
  62.  
  63.  
  64.  
  65.  
  66.  
  67. if(infractions >= goal): # Checks if enough infractions were accumulated to remove the post at the end
  68. #submission.remove(spam=False) (Not on a moderator account atm)
  69. #submission.reply(" *I am a bot, and this action was performed automatically.*\n \n" +
  70. # "**Autodetect: Question.** Please comment your question on the [stickied weekly question thread](https://www.reddit.com/r/RotMG/comments/6soxcy/weekly_help_general_questions_thread_2017_version/) instead of making a post on the subreddit, thank you! \n \n" +
  71. # "~~Your post has been removed, pending approval if this action was performed in error.~~ \n \n" +
  72. # "This bot is in beta (v0.2) and no posts will be removed until the bot can be proven to have a high accuracy.")
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79. # End of Question Thread Checker
  80.  
  81. # Start of Fame Train Checker
  82.  
  83. infractions = 0
  84. goal = 10
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91. print ("Finished! Sleeping for 5 minutes...")
  92. time.sleep(300)
  93.  
  94.  
  95.  
  96.  
  97. r = bot_login()
  98. main(r)
  99.  
  100. # Notes for myself:
  101. #
  102. # submission.selftext = body of a text post, empty line for link posts
  103. # submission.author = author of a post
  104. # submission.remove(spam=False) = removes a post
  105. # re.match(pattern, string)
  106. # submission.title = title of a post
  107. # comment.reply("I am a cat") = how to reply to a comment
  108. #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement