Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- global wordsecond
- app_id = "YOUR ID HERE"
- app_secret = "YOUR SECRET HERE"
- app_uri = 'http://127.0.0.1:65010/authorize_callback'
- r = praw.Reddit('/u/mentionhelper reminds people who fail to mention users in the comments')
- r.set_oauth_app_info(app_id, app_secret, app_uri)
- #url = r.get_authorize_url('...', 'account creddits privatemessages edit history identity read save submit', True)
- #print(url)
- app_account_code = 'YOUR CODE HERE'
- #t = r.get_access_information("YOUR CODE HERE")
- #print(t)
- app_refresh = 'YOUR REFRESH TOKEN HERE'
- r.refresh_access_information('YOUR REFRESH TOKEN HERE')
- website = ['http://www.', 'http:', 'www.', '.com', "https:","/r/", "r/","edu/"]
- catcher = ['/u/', 'u/']
- blacklist = 'blacklist.txt'
- already_done_two = 'already_done_two.txt'
- def login():
- r = praw.Reddit(app_ua)
- r.set_oauth_app_info(app_id, app_secret, app_uri)
- r.refresh_access_information(app_refresh)
- return r
- login()
- def updateBlacklist():
- mail = r.get_inbox()
- for message in mail:
- if any (key in message.body.lower() for key in ['stop']) and message.id not in already_done_two_content:
- fileZero = open(already_done_two, 'a')
- fileZero.write(message.id + '\n')
- fileZero.close()
- mention_auth_this = str(message.author)
- mention_auth_final_this = mention_auth_this.lower()
- print(mention_auth_final_this)
- print(blacklist_content)
- if mention_auth_final_this not in blacklist_content:
- fileOne = open(blacklist, 'a')
- fileOne.write(mention_auth_final_this + '\n')
- fileOne.close()
- message.reply('You have been successfully blacklisted. I won\'t bother you again!')
- else:
- message.reply('You have already been blacklisted.')
- def run():
- limit = False
- with open(blacklist, 'r') as blacklist_open:
- global blacklist_content
- blacklist_content = blacklist_open.readlines()
- blacklist_content = [x.strip() for x in blacklist_content]
- with open(already_done_two, 'r') as already_done_two_open:
- global already_done_two_content
- already_done_two_content = already_done_two_open.read()
- subreddit = r.get_subreddit('all')
- submissions = subreddit.get_new(limit=200)
- for sub in submissions:
- to_remove = []
- number = 0
- mention_auth = str(sub.author)
- mention_auth_final = mention_auth.lower()
- caught = []
- variable = ''
- number = 0
- if sub.id not in already_done_two_content and any (key in sub.selftext for key in catcher):
- fileTwo = open(already_done_two, 'a')
- fileTwo.write(sub.id + '\n')
- fileTwo.close()
- p = sub.selftext
- pewp = p.replace('#','')
- slip = pewp.replace('<', ' ')
- prop = slip.replace('>',' ')
- wel = prop.replace('- ', ' ')
- pra = wel.replace('~',' ')
- por = pra.replace(':',' ')
- para = por.replace('(',' ')
- x = para.replace(')',' ')
- y = x.replace('.', ' ')
- z = y.replace(',', ' ')
- h = z.replace(';', ' ')
- j = h.replace('!', ' ')
- mb = j.replace('*', ' ')
- body = mb.replace("'",' ').replace('\n',' ')
- split = body.split(' ')
- for word in split:
- if any(key in word for key in catcher):
- if word not in caught:
- wordsecond = word + '\n'
- if wordsecond not in caught:
- if len(caught) < 3:
- print(sub.permalink)
- final = word.replace('\n','')
- print('FINAL:', final)
- if final.replace('u/','').replace('/','').lower() != mention_auth_final:
- caught.append(final)
- print(caught[:])
- print(final)
- else:
- limit = True
- for thing in caught:
- if any (key in thing for key in website):
- caught.remove(thing)
- print('Skipped website' + thing)
- print(len(caught))
- while number < len(caught):
- print('First letter:' + caught[number][0])
- if caught[number][0] != 'u':
- if caught[number][0] != '/':
- print('match')
- to_remove.append(caught[number])
- print(number)
- number += 1
- for thingy in to_remove:
- caught.remove(thingy)
- for name in caught:
- if name.replace('u/','').replace('/','').lower() not in blacklist_content:
- pass
- else:
- caught.remove(name)
- print(caught)
- for otherthing in caught:
- variable += '- ' + otherthing + '\n\n'
- newvar = variable.replace(',', '')
- finalvar = newvar.replace(')', '')
- otherfinalvar = finalvar.replace('(', '')
- if limit == True:
- otherfinalvar += '- *Further usernames omitted due to Reddit\'s limit of 3 mentions per comment.* \n\n'
- if len(caught) == 1 and mention_auth_final not in blacklist_content:
- #print("It looks like you're trying to mention another user, which only works if it's done in the comments, like this: \n\n " + variable + " \n *I am a bot, and this action was performed automatically. For all questions/concerns, please visit /r/smartmodbot.*")
- print('Left comment...')
- sub.add_comment("It looks like you're trying to mention another user, which only works if it's done in the comments like this (otherwise they don't receive a notification): \n\n" + otherfinalvar + '\n\n---\n\n ^I\'m ^a ^bot. ^Bleep. ^Bloop. ^| ^Visit ^/r/mentionhelper ^for ^discussion/feedback ^| ^Want ^to ^be ^left ^alone? ^Reply ^to ^this ^message ^with ^"stop"')
- elif len(caught) > 1 and mention_auth_final not in blacklist_content:
- print('Left comment...')
- #print("It looks like you're trying to mention other users, which only works if it's done in the comments, like this: ", *caught, sep='\n')
- sub.add_comment("It looks like you're trying to mention other users, which only works if it's done in the comments like this (otherwise they don't receive a notification): \n\n" + otherfinalvar + '\n\n---\n\n ^I\'m ^a ^bot. ^Bleep. ^Bloop. ^| ^Visit ^/r/mentionhelper ^for ^discussion/feedback ^| ^Want ^to ^be ^left ^alone? ^Reply ^to ^this ^message ^with ^"stop"')
- while True:
- try:
- run()
- updateBlacklist()
- except:
- pass
- #stop me with pkill -f other_bot.py
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement