Advertisement
Guest User

Untitled

a guest
May 29th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. #Moderator bot for r/lore_irl and r/mineycrafta to remove any posts that have negative scores
  2. #Bot messages author of the posts
  3. #Created by reddit u/dustonwithano
  4. #Please DM me on reddit with any issues
  5.  
  6. ###########################
  7. # import modules
  8. ###########################
  9.  
  10. import praw
  11. import config
  12. import datetime
  13. import time
  14. import sys
  15.  
  16. ###########################
  17. # definitions
  18. ###########################
  19.  
  20. #defining the log in process
  21. def bot_login():
  22. print('--------------------------------------------------')
  23. print('Logging in...')
  24. try:
  25. r = praw.Reddit(username = config.username,
  26. password = config.password,
  27. client_id = config.client_id,
  28. client_secret = config.client_secret,
  29. user_agent = 'Submission Mod Bot v1.0')
  30. except:
  31. #output if login fails
  32. print('Log-in failed. Ending Execution')
  33. print('--------------------------------------------------')
  34. sys.exit()
  35. else:
  36. #output if login successful
  37. print('Successfully logged in.')
  38. print('--------------------------------------------------')
  39. return r
  40.  
  41. #defining the sleeping process (set for 5 minutes)
  42. def sleeping():
  43. print('Sleeping. \nTime remaining: 10 minutes')
  44. time.sleep(120)
  45. print('Time remaining: 8 minutes')
  46. time.sleep(120)
  47. print('Time remaining: 6 minutes')
  48. time.sleep(120)
  49. print('STime remaining: 4 minutes')
  50. time.sleep(120)
  51. print('STime remaining: 2 minutes')
  52. time.sleep(120)
  53.  
  54. #defining the printing outcome
  55. def print_results():
  56. print('Review complete. \n--------------------------------------------------\nResults:')
  57. print('Removed ' + str(int(len(submissionsRemoved))) + ' submission(s).')
  58. if len(submissionsRemoved) >0: #if there were posts removed
  59. print('\nSubmission title(s) include: ')
  60. print(*submissionsRemoved, sep='\n')
  61. print('\nSubmission Author(s): ')
  62. print(*authorsMessaged, sep='\n')
  63. print('--------------------------------------------------')
  64.  
  65. #defining bot action
  66. def bot_action(r):
  67. global submissionsRemoved #making global
  68. global authorsMessaged #making global
  69. submissionsRemoved = [] #making list
  70. authorsMessaged = [] #making list
  71. print('Reviewing '+ selectedSubreddit + '...')
  72. for submission in r.subreddit(selectedSubreddit).new(limit=200): #limiting the review to 200 new posts
  73. author = str(submission.author) #converting author to string
  74. if submission.score < 0: #setting upvote parameters
  75. 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.)')
  76. praw.models.reddit.submission.SubmissionModeration(submission).remove() #removing submission
  77. submissionsRemoved.append(submission.title) #adding submission title to list of those removed
  78. authorsMessaged.append(submission.author) #adding author name to those messaged
  79.  
  80. ###########################
  81. # code execution
  82. ###########################
  83.  
  84. #calling the log in process
  85. r = bot_login()
  86.  
  87. #looping the bot
  88. while True:
  89. selectedSubreddit = 'modbottesting' #first subreddit
  90. bot_action(r)
  91. selectedSubreddit = 'modbottesting' #second subreddit
  92. print_results()
  93. sleeping()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement