Guest User

Untitled

a guest
Jun 7th, 2017
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.42 KB | None | 0 0
  1. import praw
  2. from termcolor import colored
  3. import pickle as pl
  4.  
  5. r = praw.Reddit(client_id='<>',
  6. client_secret='<>',
  7. password='<>',
  8. user_agent='NewTubers Mod Bot',
  9. username='NewTubersModBot')
  10.  
  11.  
  12. TEMPLATE_COMMENT = '''
  13. #This is a critique thread! Here's a friendly reminder about the rules for a critique:\n\n
  14.  
  15. - **2** - In order to post your plug in a Critique thread, you **must** give meaningful feedback on at least **TWO (2)** other plugs in the thread. You should give feedback before posting your own plug.
  16.  
  17. - **2a** - In cases where you are the first or second plug post in a Critique thread, you may post your link before giving feedback, so long as you give feedback within ONE HOUR of your initial link. If you don't give feedback within an hour, your post will be removed. If you're a repeat offender, you will be marked as such and prohibited from posting links until your behavior improves.\n\n
  18.  
  19. See the [full rules here](https://www.reddit.com/r/NewTubers/comments/63fygf/newtubers_rules_v30/) or in the sidebar. Note that the OP (/u/{}) holds the chief responsibility for policing the thread by reporting rule violations and otherwise inappropriate content.
  20. '''
  21.  
  22. activeThreads = dict()
  23. checkedPostIds = list()
  24. checkedCommentIds = list()
  25. RUNSUB = 'NewTubersTesting'
  26.  
  27. class critiqueThread:
  28. def __init__(self, ident):
  29. self.ident = ident
  30. self.contributors = {} #dict, username : comment count
  31. self.watchList = [] #first three commenters to keep an eye on
  32. self.timerStarted = False #contains a UTC value when the third comment is added to the post
  33.  
  34. def get_submission(x):
  35. while type(x.parent()) != 'submission':
  36. x = x.parent()
  37. return x
  38.  
  39. def runBot():
  40. for post in r.subreddit(RUNSUB).new(limit=5):
  41. if post.link_flair_text == 'GIVE CONTENT CRITIQUE' and post.id not in checkedPostIds:
  42. post.reply(TEMPLATE_COMMENT.format(str(post.author))).mod.distinguish(how='yes', sticky=True)
  43. activeThreads[post.id] = critiqueThread(post.id)
  44. checkedPostIds.append(post.id, post)
  45. for comment in [comment for comment in r.subreddit(RUNSUB).new(limit=5) if comment.id not in checkedCommentIds and str(comment.author) != 'NewTubersModBot']:
  46. checkedCommentIds.append(comment.id)
  47. psub = get_submission(comment)
  48. if psub.id in checkedPostIds:
  49. if type(comment.parent()) == 'comment' and len(comment.body) >= 40:
  50. try:
  51. activeThreads[psub.id].contributors[str(comment.author)] += 1
  52. except:
  53. activeThreads[psub.id].contributors[str(comment.author)] = 1
  54. elif type(comment.parent()) == 'comment' and len(comment.body) < 40:
  55. try:
  56. cur = activeThreads[psub.id].contributors[str(comment.author)]
  57. if cur < 2:
  58. r.redditor(str(comment.author)).message('Invalid Feedback', 'Your [recent comment]({}) did not count towards the **TWO (2)** required comments to submit a link in [this thread]{} because it was too short. If you believe this was an error, please do not hesitate to [contact the moderators](https://www.reddit.com/message/compose?to=%2Fr%2FNewTubers).'.format(comment.permalink, psub.permalink))
  59. except:
  60. r.redditor(str(comment.author)).message('Invalid Feedback', 'Your [recent comment]({}) did not count towards the **TWO (2)** required comments to submit a link in [this thread]{} because it was too short. If you believe this was an error, please do not hesitate to [contact the moderators](https://www.reddit.com/message/compose?to=%2Fr%2FNewTubers).'.format(comment.permalink, psub.permalink))
  61. elif type(comment.parent()) == 'submission' and ('youtube.com' not in comment.body or 'you.tube' not in comment.body):
  62. comment.mod.remove()
  63. r.redditor(str(comment.author)).message('Invalid Comment', 'Your [recent comment]({}) was removed because all top-level replies on a Critique Thread must be a valid link to a YouTube channel or video.')
  64. elif type(comment.parent()) == 'submission' and len(psub.comments) >= 3:
  65. try:
  66. curcount = activeThreads[psub.id].contributors[str(comment.author)]
  67. if curcount < 2:
  68. r.redditor(str(comment.author)).message('Invalid Comment', 'Your [recent comment]({}) was removed because you failed to post the **TWO (2)** required comments before submitting a link.')
  69. comment.mod.remove()
  70. except:
  71. r.redditor(str(comment.author)).message('Invalid Comment', 'Your [recent comment]({}) was removed because you failed to post the **TWO (2)** required comments before submitting a link.')
  72. comment.mod.remove()
  73. elif type(comment.parent()) == 'submission' and len(psub.comments) <= 3:
  74. activeThreads[psub.id].watchList.append(str(comment.author))
  75. r.redditor(str(comment.author)).message('Early Commenter!', 'Congratulations! You were one of the first people to comment on [this Critique Thread]({}). Please be aware, however, that you are not exempt from the feedback requirements. If you do not post **TWO (2)** comments within an hour of the post reaching **at least 3** comments, [your comment]({}) will be removed'.format(psub.permalink, comment.permalink))
Add Comment
Please, Sign In to add comment