Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Moderator bot for r/lore_irl and r/mineycrafta to remove any posts that have negative scores
- #Bot messages author of the posts
- #Created by reddit u/dustonwithano
- #Please DM me on reddit with any issues
- ###########################
- # import modules
- ###########################
- import praw
- import config
- import datetime
- import time
- import sys
- ###########################
- # definitions
- ###########################
- #defining the log in process
- def bot_login():
- print('--------------------------------------------------')
- print('Logging in...')
- try:
- r = praw.Reddit(username = config.username,
- password = config.password,
- client_id = config.client_id,
- client_secret = config.client_secret,
- user_agent = 'Submission Mod Bot v1.0')
- except:
- #output if login fails
- print('Log-in failed. Ending Execution')
- print('--------------------------------------------------')
- sys.exit()
- else:
- #output if login successful
- print('Successfully logged in.')
- print('--------------------------------------------------')
- return r
- #defining the sleeping process (set for 5 minutes)
- def sleeping():
- print('Sleeping. \nTime remaining: 10 minutes')
- time.sleep(120)
- print('Time remaining: 8 minutes')
- time.sleep(120)
- print('Time remaining: 6 minutes')
- time.sleep(120)
- print('STime remaining: 4 minutes')
- time.sleep(120)
- print('STime remaining: 2 minutes')
- time.sleep(120)
- #defining the printing outcome
- def print_results():
- print('Review complete. \n--------------------------------------------------\nResults:')
- print('Removed ' + str(int(len(submissionsRemoved))) + ' submission(s).')
- if len(submissionsRemoved) >0: #if there were posts removed
- print('\nSubmission title(s) include: ')
- print(*submissionsRemoved, sep='\n')
- print('\nSubmission Author(s): ')
- print(*authorsMessaged, sep='\n')
- print('--------------------------------------------------')
- #defining bot action
- def bot_action(r):
- global submissionsRemoved #making global
- global authorsMessaged #making global
- submissionsRemoved = [] #making list
- authorsMessaged = [] #making list
- print('Reviewing '+ selectedSubreddit + '...')
- for submission in r.subreddit(selectedSubreddit).new(limit=200): #limiting the review to 200 new posts
- author = str(submission.author) #converting author to string
- if submission.score < 0: #setting upvote parameters
- submission.reply('Hello /u/' + str(author) + ': \n\nThis post has been removed due to negative votes. \n\n-------------------------\n\n^(I am a bot. This was done automatically.)')
- praw.models.reddit.submission.SubmissionModeration(submission).remove() #removing submission
- submissionsRemoved.append(submission.title) #adding submission title to list of those removed
- authorsMessaged.append(submission.author) #adding author name to those messaged
- ###########################
- # code execution
- ###########################
- #calling the log in process
- r = bot_login()
- #looping the bot
- while True:
- selectedSubreddit = 'modbottesting' #first subreddit
- bot_action(r)
- selectedSubreddit = 'modbottesting' #second subreddit
- print_results()
- sleeping()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement