Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import config
- import time
- import re
- def bot_login():
- print ("Loggin in...")
- r = praw.Reddit(username = config.username,
- password = config.password,
- client_id = config.client_id, # Messy stuff at the beginning
- client_secret = config.client_secret,
- user_agent = "tybug's testing bot ")
- print ("I've logged on!")
- return r
- # Main Function
- def main(r): # No idea why it needs r
- for submission in r.subreddit('rotmg').new(limit=10): # For each of the submissions on r/rotmg/new, up to submission # limit...
- # Nasty set of if statements for each regex needing to be checked, very inneficient but it works
- # A demo with comments is below:
- # infractions = 0 # number of penalty points accumulated
- # goal = 50 # number of penalty points neccesary to get removed, changes every mark (mark = Question Thread, Fame Train, etc)
- # matcher = re.match("Does",submission.title) # Regex for the if statement, chenges every if statement
- # if(matcher != None): # If the matcher found something in the body of the post
- # print("Success!") # Debugger
- # infractions = infractions + 10 # Add penalty points
- # Start of Question Thread Checker
- print(submission.title)
- infractions = 0
- goal = 50
- matcher = re.match(".+\?",submission.title) # Question mark at the end of the title
- if(matcher != None):
- infractions = infractions + 40
- print(infractions)
- matcher = re.match("(?i)(which|what) (character|pet|weapon|character) (?:\w+ ?){0,4} (max|feed|fuse|hatch|equip|buy|)",submission.selftext)
- if(matcher != None):
- infractions = infractions + 10
- print(infractions)
- 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)
- if(matcher != None):
- infractions = infractions + 10
- print(infractions)
- 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)
- if(matcher != None):
- infractions = infractions + 10
- print(infractions)
- if(infractions >= goal): # Checks if enough infractions were accumulated to remove the post at the end
- #submission.remove(spam=False) (Not on a moderator account atm)
- #submission.reply(" *I am a bot, and this action was performed automatically.*\n \n" +
- # "**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" +
- # "~~Your post has been removed, pending approval if this action was performed in error.~~ \n \n" +
- # "This bot is in beta (v0.2) and no posts will be removed until the bot can be proven to have a high accuracy.")
- # End of Question Thread Checker
- # Start of Fame Train Checker
- infractions = 0
- goal = 10
- print ("Finished! Sleeping for 5 minutes...")
- time.sleep(300)
- r = bot_login()
- main(r)
- # Notes for myself:
- #
- # submission.selftext = body of a text post, empty line for link posts
- # submission.author = author of a post
- # submission.remove(spam=False) = removes a post
- # re.match(pattern, string)
- # submission.title = title of a post
- # comment.reply("I am a cat") = how to reply to a comment
- #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement