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 ("\nLoggin 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
- limit = 5
- version = "0.4"
- Question_thread_goal = 50
- Fame_train_goal = 10
- Guild_recruitment_goal = 10
- weekly_question_thread_link = "https://www.reddit.com/r/RotMG/comments/6soxcy/" # Posted August 10th
- # Main Function
- def main(r): # No idea why it needs r
- print("Start of` a fresh run:")
- for submission in r.subreddit('rotmg').new(limit=limit): # 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
- # 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("\n" + submission.title)
- infractions = 0
- matcher = re.match(".+\?",submission.title) # Question mark at the end of the title
- if(matcher != None):
- infractions = infractions + 40
- print("Infractions: " + str(infractions))
- print("Number: 1")
- 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: " + str(infractions))
- print("Number: 2 \n")
- 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: " + str(infractions))
- print("Number: 3 \n")
- 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: " + str(infractions))
- print("Number: 4 \n")
- if(infractions >= Question_thread_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("**Autodetect: Question.** Please comment your question on the [stickied weekly question thread]" +
- (weekly_question_thread_link) + "instead of making a post on the subreddit, thank you! \n \n" +
- "--- \n \n ^(I am a bot, and this action was performed automatically) ^| ^(Version: " + version + " (Beta)^) ^| ^(Reply to leave feedback)")
- print("I've left a weekly question thread comment! \n")
- # End of Question Thread Checker
- infractions = 0
- # Start of Fame Train Checker
- matcher = re.match("(?i)Looking for (?:\w+ ?){0,4} \w*train discord",submission.title)
- if(matcher != None):
- infractions = infractions + 10
- print("Infractions: " + str(infractions))
- print("Number: 5 \n")
- matcher = re.match("(?i)Looking for \w*train discord",submission.title)
- if(matcher != None):
- infractions = infractions + 10
- print("Infractions: " + str(infractions))
- print("Number: 6 \n")
- matcher = re.match("(?i)(where|what) is (?:\w+ ?){0,4} (\w*train|\w*train discord)",submission.title)
- if(matcher != None):
- infractions = infractions + 10
- print("Infractions: " + str(infractions))
- print("Number: 7 \n")
- if(infractions >= Fame_train_goal):
- #submission.remove(spam=False) (Not on a moderator account atm)
- submission.reply("**Autodetect: Fame Train.** location. The Fame Train, previously located on the server EUN2, now moves around to whichever" +
- "realm provides the best fpm (fame per minute). Their current location can be found in the #click-here-for-train channel of their discord:" +
- "https://discord.gg/pVGQe7g. \n \n" +
- "--- \n \n ^(I am a bot, and this action was performed automatically) ^| ^(Version: " + version + " (Beta)^) ^| ^(Reply to leave feedback)")
- print("I've left a fame train comment! \n")
- # End of Fame Train Checker
- infractions = 0
- # Start of Guild Recruitment Checker
- matcher = re.match("(?i)Recruiting for",submission.title)
- if(matcher != None):
- infractions = infractions + 10
- print("Infractions: " + str(infractions))
- print("Number: 8 \n")
- matcher = re.match("(?i)Looking for (?:\w+ ?){0,3} guild",submission.title)
- if(matcher != None):
- infractions = infractions + 10
- print("Infractions: " + str(infractions))
- print("Number: 9 \n")
- matcher = re.match("(?i)Looking for (?:\w+ ?){0,3} guild",submission.selftext)
- if(matcher != None):
- infractions = infractions + 10
- print("Infractions: " + str(infractions))
- print("Number: 10 \n")
- matcher = re.match("(?i)Requirement (?:\w+ ?){0,4} (./8|fame)",submission.selftext)
- if(matcher != None):
- infractions = infractions + 10
- print("Infractions: " + str(infractions))
- print("Number: 11 \n")
- matcher = re.match("(?i)Requirement (?:\w+ ?){0,4} (./8|fame)",submission.title)
- if(matcher != None):
- infractions = infractions + 10
- print("Infractions: " + str(infractions))
- print("Number: 12 \n")
- if(infractions >= Guild_recruitment_goal):
- #submission.remove(spam=False) (Not on a moderator account atm)
- submission.reply("**Autodetect: Guild Recruitment/Looking to join a guild.** Please post over at the" +
- "[Realmeye Forums'] (https://www.realmeye.com/forum/c/guilds) guild recruitment section instead of reddit, thanks! \n \n" +
- "--- \n \n ^(I am a bot, and this action was performed automatically) ^| ^(Version: " + version + " (Beta)^) ^| ^(Reply to leave feedback)")
- print("I've left a guild recruitment comment! \n")
- # End of Guild Recruitment Checker\
- print ("\nFinished! Sleeping for 5 minutes... \n")
- time.sleep(300)
- r = bot_login() # Not sure what this does either honestly, but it works
- while True:
- 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