Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import string
- import time
- import praw.models
- import re
- from collections import Counter
- def submissions_and_comments(subreddit, **kwargs):
- results = []
- results.extend(subreddit.new(**kwargs))
- results.extend(subreddit.comments(**kwargs))
- results.sort(key=lambda post: post.created_utc, reverse=True)
- return results
- reddit = praw.Reddit(client_id='BLAH',
- client_secret="BLAH",
- user_agent='BLAH',
- username="BLAH",
- password="BLAH")
- listOfWords = ["ban","banned","bannable","banning","bans", "bann"
- ,"subreddit","reddit","redit","redditor","redditors","reddits",
- "special","specal","specail","spcial","specialized","specialty","specialization",
- "rectangle","rectangles","rectangular",
- "america","american","murica",
- "megaphone","megaphones","megaphoned"," megaphoning",
- "butthole","buttholes",
- "monday","mondays"
- "alphabet","alphabets","alphabetical","alphabetically",
- "country","countries",
- "moderate","moderated","moderates","moderating","moderation","moderator","moderators","moderately","moderateness","nonmoderate","nonmoderately","nonmoderateness","semimoderate","semimoderately","unmoderated","unmoderating",
- "thanks","thank","thankful","thankfully","thankfulness","unthankful","unthankfully","unthankfulness","thanked","thanking","unthanked","unthanking","thanker","rethank","rethanked","thanker","thankers","rethanking",
- "music","musical","musically","musicless","antimusic","musiclessly","antimusical","antimusically",
- "love","loves","loving","loved","lovely","loveliness","loveless","lovelessness","lover","lovers",
- "attack helicopter","attack helicopers",
- "redact","redacted","redacts","redaction","redactions","redacting","redactor","redactors",
- "synonym","synonyms","synonymic","synonimity",
- "number","numbers","numbered","numbering",
- "rules","ruled","ruler","ruling","rulers","rule","ruleless",
- "cheese","cheeses","cheesed","cheesing",
- "fun","funner","funnest","funs","funned","funning",
- "rock","rocks","rocked","rocking","rock-like","rockless","rocklet","rocklets",
- "please","pleased","pleases","pleasing",
- "agree","agreement","agreements","agrees","agreed","agreeing",
- "ten","tens","10",
- "world","worlds",
- "value","values","valued","valuing",
- "chart","charted","charts","charting",
- "stair","stairs",
- "night","nights","energy","energies" , "prize","prizes",
- "opinion","opinions","opinionated","lamp","lamps.lampshade","snout","snouts"
- ]
- listOfMods = ["AstroFIJI", "SeamusLK", "Shiruet", "HellaHotLancelot", "MrCleansBleach", "AutoModerator", "windforce2","OneWordBot",
- "JamesMBuddy123","jj23327"]
- translator = str.maketrans('', '', string.punctuation)
- #str.maketrans(string.punctuation, ' '*len(string.punctuation))
- startTime = int(time.time())
- subreddit = reddit.subreddit('OneWordBan')
- stream = praw.models.util.stream_generator(lambda **kwargs: submissions_and_comments(subreddit, **kwargs))
- #commentNumber = 0
- '''allWords = []'''
- for comment in stream:
- if hasattr(comment, 'body'):
- commentBodyModified = comment.body.lower().translate(translator);
- else:
- commentBodyModified = comment.selftext.lower().translate(translator) + " " + comment.title.lower().translate(translator).translate(translator)
- banned = False
- bannedWordsUsed = []
- for bannedWord in listOfWords:
- if (" "+bannedWord+" " in commentBodyModified
- or commentBodyModified.startswith(bannedWord+" ")
- or commentBodyModified.endswith(" " + bannedWord)
- or commentBodyModified is bannedWord):
- if comment.author not in listOfMods:
- bannedWordsUsed.append(bannedWord)
- if len(bannedWordsUsed) > 0:
- wordsString = ", ".join(bannedWordsUsed)
- if len(wordsString) > 120:
- wordsString = "too many to count"
- print("-----------------")
- print(commentBodyModified)
- print("reddit.com" + comment.permalink)
- print(comment.author)
- print("Banned words: " + wordsString)
- if comment.created_utc > startTime:
- try:
- userIsBanned = any(reddit.subreddit('OneWordBan').banned(redditor=comment.author))
- reddit.subreddit('OneWordBan').banned.add(comment.author
- , ban_reason = "Banned word - windforce2 bot"
- , ban_message = "reddit.com" + comment.permalink
- , note = "Automatically banned by windforce2's bot for this comment https://reddit.com" + comment.permalink + " for the words \"" + wordsString + "\"")
- banned = True
- if not userIsBanned:
- comment.reply("You have been banished for using the following words: " + wordsString + "\n\n*This is an automated posting by OneWordBan\'s Bot*")
- print("Banned user, replied")
- else:
- print("Skipping reply as user is already banned")
- except Exception as e: print(e)
- else:
- print ("Skipping old")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement