Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import praw
- TIME_TO_MESSAGE = 1 * 60
- TIME_TO_DELETE = 3 * 60
- TIME_TO_SLEEP = 1 * 60
- SUBREDDIT_NAME = '@@@'
- USERNAME = '@@@'
- PASSWORD = '@@@'
- CLIENT_ID = '@@@'
- CLIENT_SECRET = '@@@'
- USER_AGENT = '@@@'
- reddit = praw.Reddit(
- client_id=CLIENT_ID,
- client_secret=CLIENT_SECRET,
- password=PASSWORD,
- user_agent=USER_AGENT,
- username=USERNAME)
- seenPosts = []
- DELETION_TITLE = "Your post was deleted because you didn't flair"
- WARNING_TITLE = "Please flair your post"
- def makeWarning(post):
- subredditLink = "https://reddit.com/" + post.subreddit_name_prefixed
- return "Hello {name}, \n Please give your post, [{postName}]({post}), a flair, otherwise it will be deleted after {TIME_TO_DELETE} minutes since posting. \n If you have any questions please send a message to the mods of [{subreddit}]({subredditLink}), not this bot.".format(
- name=post.author,
- postName=post.title,
- post=post.url,
- TIME_TO_DELETE=int(TIME_TO_DELETE / 60),
- subreddit=post.subreddit,
- subredditLink=subredditLink)
- def makeDeletionText(post):
- subredditLink = "https://reddit.com/" + post.subreddit_name_prefixed
- return "Hello {name}, \n Your post ,{postName}, in [{subreddit}]({subredditLink}) was deleted because you failed to give it a flair in a timely manner. \n If you have any questions please send them to the mod team of [{subreddit}]({subredditLink}), not this bot.".format(
- name=post.author,
- postName=post.title,
- subreddit=post.subreddit,
- subredditLink=subredditLink)
- if SUBREDDIT_NAME not in reddit.user.moderator_subreddits():
- print('This bot needs mod-rights to delete posts.')
- exit()
- while True:
- now = time.time()
- for post in reddit.subreddit(SUBREDDIT_NAME).stream.submissions(
- pause_after=0):
- if post is None:
- break
- elif post.link_flair_text is not None:
- if post in seenPosts:
- seenPosts.remove(post)
- #print(seenPosts)
- #from here on down all posts have no flair
- elif now - post.created_utc > TIME_TO_DELETE:
- if post in seenPosts:
- seenPosts.remove(post)
- #print(seenPosts)
- redditor = post.author
- sub = post.subreddit
- deletionText = makeDeletionText(post)
- redditor.message(DELETION_TITLE, deletionText, sub)
- post.mod.remove()
- elif now - post.created_utc > TIME_TO_MESSAGE:
- if post not in seenPosts:
- redditor = post.author
- sub = post.subreddit
- warningText = makeWarning(post)
- redditor.message(WARNING_TITLE, warningText, sub)
- seenPosts.append(post)
- #print(seenPosts)
- time.sleep(TIME_TO_SLEEP)
Add Comment
Please, Sign In to add comment