Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import config
- import time
- import re
- import datetime
- import os
- 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 = "r/rotmg autoremoval bot")
- print ("I've logged on!\n")
- return r
- limit = 5
- version = "0.7"
- Question_thread_goal = 50
- Fame_train_goal = 10
- Guild_recruitment_goal = 10
- Lost_halls_goal = 10
- Returning_player_goal = 10
- boolean = 0
- weekly_question_thread_link = "https://www.reddit.com/r/RotMG/comments/6soxcy/" # Posted August 10th
- # Main Function
- def main(r, posts_replied_to): # No idea why it needs r
- print("Start of a fresh run:")
- count = 0
- now = datetime.datetime.now()
- for submission in r.subreddit('rotmg').new(limit=limit): # For each of the submissions on r/rotmg/new, up to submission # limit...
- count = count + 1 # Numbering each of the submissions for easy reading in the terminal
- # 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 " + str(count) + ": " + submission.title)
- author = submission.author # Getting a reddit user object
- print(" Author: " + author.name) # Gets the username of the reddit user
- 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 and author.name not in whitelisted_users): # Checks if enough infractions were accumulated to remove the post at the end
- if(submission.id not in posts_replied_to):
- #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")
- posts_replied_to.append(submission.id)
- with open ("posts_replied_to.txt", "a") as f:
- f.write(submission.id + "\n")
- else:
- print(" This post has already been replied to!")
- # End of Question Thread Checker
- # Start of Fame Train Checker
- infractions = 0
- 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")
- matcher = re.match("(?i)what server (?:\w+ ?){0,4} \w*train",submission.title)
- if(matcher != None):
- infractions = infractions + 10
- print(" Infractions: " + str(infractions))
- print(" Number: 7 \n")
- if(infractions >= Fame_train_goal and author.name not in whitelisted_users):
- if(submission.id not in posts_replied_to):
- #submission.remove(spam=False) (Not on a moderator account atm)
- submission.reply("**Autodetect: Fame Train.** 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")
- posts_replied_to.append(submission.id)
- with open ("posts_replied_to.txt", "a") as f:
- f.write(submission.id + "\n")
- else:
- print(" This post has already been replied to!")
- # End of Fame Train Checker
- # Start of Guild Recruitment Checker
- infractions = 0
- 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 and author.name not in whitelisted_users):
- if(submission.id not in posts_replied_to):
- #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")
- posts_replied_to.append(submission.id)
- with open ("posts_replied_to.txt", "a") as f:
- f.write(submission.id + "\n")
- else:
- print(" This post has already been replied to!")
- # End of Guild Recruitment Checker
- # Beginning of Lost Halls Checker
- infractions = 0
- matcher = re.match("(?i)(where|what) (?:\w+ ?){0,4} (halls|lost|LH|lost halls) (discord|invite)",submission.title)
- if(matcher != None):
- infractions = infractions + 10
- print(" Infractions: " + str(infractions))
- print(" Number: 13 \n")
- matcher = re.match("(?i)(where|what) (?:\w+ ?){0,4} (halls|lost|LH|lost halls) (discord|invite)",submission.selftext)
- if(matcher != None):
- infractions = infractions + 10
- print(" Infractions: " + str(infractions))
- print(" Number: 14 \n")
- matcher = re.match("(?i)Looking for (?:\w+ ?){0,4} (Lost|halls|LH|lost halls) (discord|invite)",submission.title)
- if(matcher != None):
- infractions = infractions + 10
- print(" Infractions: " + str(infractions))
- print(" Number: 15 \n")
- matcher = re.match("(?i)Looking for (?:\w+ ?){0,4} (Lost|halls|LH|lost halls) (discord|invite)",submission.selftext)
- if(matcher != None):
- infractions = infractions + 10
- print(" Infractions: " + str(infractions))
- print(" Number: 16 \n")
- matcher = re.match("(?i)(Link|invite) (?:\w+ ?){0,4} (halls|lost|LH|lost halls) discord",submission.title)
- if(matcher != None):
- infractions = infractions + 10
- print(" Infractions: " + str(infractions))
- print(" Number: 17 \n")
- if(infractions >= Lost_halls_goal and author.name not in whitelisted_users):
- if(submission.id not in posts_replied_to):
- #submission.remove(spam=False) (Not on a moderator account atm)
- submission.reply("**Autodetect: Lost Halls discord. The Public Lost Halls discord can be found here: https://discord.gg/EKFPG73.** \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 Lost Halls comment! \n")
- posts_replied_to.append(submission.id)
- with open ("posts_replied_to.txt", "a") as f:
- f.write(submission.id + "\n")
- else:
- print(" This post has already been replied to!")
- # End of Lost Halls Checker
- # Beginning of Returning Player Checker
- matcher = re.match("(What|what's|anything) changed",submission.title)
- if(matcher != None):
- infractions = infractions + 10
- print(" Infractions: " + str(infractions))
- print(" Number: 18 \n")
- if(infractions >= Returning_player_goal and author.name not in whitelisted_users):
- if(submission.id not in posts_replied_to):
- #submission.remove(spam=False) (Not on a moderator account atm)
- submission.reply("**Autodetect: Returning Player. Please check the [Developement History]" +
- "(https://www.realmeye.com/wiki/development-and-release-history) on Realmeye and all the [Official Posts](https://www.reddit.com" +
- "/r/RotMG/search?sort=new&restrict_sr=on&q=flair%3AOfficial%2BDeca) made " +
- "by Deca on reddit for what's changed since you've been gone! \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 Returning Player comment! \n")
- posts_replied_to.append(submission.id)
- with open ("posts_replied_to.txt", "a") as f:
- f.write(submission.id + "\n")
- else:
- print(" This post has already been replied to!")
- print ("\n The time is " + str(now.hour) + ":" + str(now.minute) + "\n Finished! Sleeping for 5 minutes... \n") # Gives the time that it finished at
- time.sleep(300) # Sleeps for 5 minutes
- def get_saved_posts():
- if not os.path.isfile("posts_replied_to.txt"):
- posts_replied_to = []
- else:
- with open("posts_replied_to.txt", "r") as f:
- posts_replied_to = f.read()
- posts_replied_to = posts_replied_to.split("\n") # Entries in the list are divided by new lines
- posts_replied_to = list(filter(None, posts_replied_to)) # Dunno what this does, it works though
- return posts_replied_to
- def get_whitelisted_users():
- if not os.path.isfile("whitelisted_users.txt"):
- whitelisted_users = []
- else:
- with open("whitelisted_users.txt", "r") as f:
- whitelisted_users = f.read()
- whitelisted_users = whitelisted_users.split("\n")
- whitelisted_users = list(filter(None, whitelisted_users))
- return whitelisted_users
- posts_replied_to = get_saved_posts()
- r = bot_login() # Not sure what this does either honestly, but it works
- posts_replied_to = get_saved_posts() # Creating lists from .txt files for use above
- whitelisted_users = get_whitelisted_users()
- while True:
- main(r, posts_replied_to) # Runs the main function cotninuously when redditbot.py is run
- # 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
- # print now.year, now.month, now.day, now.hour, now.minute, now.second
- # 2015 5 6 8 53 40
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement