Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.23 KB | None | 0 0
  1. import praw
  2. import string
  3. import time
  4. import praw.models
  5. import re
  6. from collections import Counter
  7.  
  8. def submissions_and_comments(subreddit, **kwargs):
  9.     results = []
  10.     results.extend(subreddit.new(**kwargs))
  11.     results.extend(subreddit.comments(**kwargs))
  12.     results.sort(key=lambda post: post.created_utc, reverse=True)
  13.     return results
  14.  
  15. reddit = praw.Reddit(client_id='BLAH',
  16.                      client_secret="BLAH",
  17.                      user_agent='BLAH',
  18.                      username="BLAH",
  19.                      password="BLAH")
  20.  
  21.  
  22. listOfWords = ["ban","banned","bannable","banning","bans", "bann"
  23. ,"subreddit","reddit","redit","redditor","redditors","reddits",
  24. "special","specal","specail","spcial","specialized","specialty","specialization",
  25. "rectangle","rectangles","rectangular",
  26. "america","american","murica",
  27. "megaphone","megaphones","megaphoned"," megaphoning",
  28. "butthole","buttholes",
  29. "monday","mondays"
  30. "alphabet","alphabets","alphabetical","alphabetically",
  31. "country","countries",
  32. "moderate","moderated","moderates","moderating","moderation","moderator","moderators","moderately","moderateness","nonmoderate","nonmoderately","nonmoderateness","semimoderate","semimoderately","unmoderated","unmoderating",
  33. "thanks","thank","thankful","thankfully","thankfulness","unthankful","unthankfully","unthankfulness","thanked","thanking","unthanked","unthanking","thanker","rethank","rethanked","thanker","thankers","rethanking",
  34. "music","musical","musically","musicless","antimusic","musiclessly","antimusical","antimusically",
  35. "love","loves","loving","loved","lovely","loveliness","loveless","lovelessness","lover","lovers",
  36. "attack helicopter","attack helicopers",
  37. "redact","redacted","redacts","redaction","redactions","redacting","redactor","redactors",
  38. "synonym","synonyms","synonymic","synonimity",
  39. "number","numbers","numbered","numbering",
  40. "rules","ruled","ruler","ruling","rulers","rule","ruleless",
  41. "cheese","cheeses","cheesed","cheesing",
  42. "fun","funner","funnest","funs","funned","funning",
  43. "rock","rocks","rocked","rocking","rock-like","rockless","rocklet","rocklets",
  44. "please","pleased","pleases","pleasing",
  45. "agree","agreement","agreements","agrees","agreed","agreeing",
  46. "ten","tens","10",
  47. "world","worlds",
  48. "value","values","valued","valuing",
  49. "chart","charted","charts","charting",
  50. "stair","stairs",
  51. "night","nights","energy","energies" , "prize","prizes",
  52. "opinion","opinions","opinionated","lamp","lamps.lampshade","snout","snouts"
  53. ]
  54.  
  55. listOfMods = ["AstroFIJI", "SeamusLK", "Shiruet", "HellaHotLancelot", "MrCleansBleach", "AutoModerator", "windforce2","OneWordBot",
  56.               "JamesMBuddy123","jj23327"]
  57.  
  58. translator = str.maketrans('', '', string.punctuation)
  59. #str.maketrans(string.punctuation, ' '*len(string.punctuation))
  60.  
  61. startTime = int(time.time())
  62.  
  63. subreddit = reddit.subreddit('OneWordBan')
  64. stream = praw.models.util.stream_generator(lambda **kwargs: submissions_and_comments(subreddit, **kwargs))
  65.  
  66. #commentNumber = 0
  67.  
  68. '''allWords = []'''
  69.  
  70. for comment in stream:
  71.    
  72.     if hasattr(comment, 'body'):
  73.         commentBodyModified = comment.body.lower().translate(translator);
  74.     else:
  75.         commentBodyModified = comment.selftext.lower().translate(translator) + " " + comment.title.lower().translate(translator).translate(translator)
  76.    
  77.     banned = False
  78.    
  79.     bannedWordsUsed = []
  80.    
  81.     for bannedWord in listOfWords:
  82.         if (" "+bannedWord+" " in commentBodyModified
  83.                 or commentBodyModified.startswith(bannedWord+" ")
  84.                 or commentBodyModified.endswith(" " + bannedWord)
  85.                 or commentBodyModified is bannedWord):
  86.             if comment.author not in listOfMods:
  87.                 bannedWordsUsed.append(bannedWord)
  88.                
  89.     if len(bannedWordsUsed) > 0:
  90.        
  91.         wordsString = ", ".join(bannedWordsUsed)
  92.         if len(wordsString) > 120:
  93.             wordsString = "too many to count"
  94.        
  95.         print("-----------------")
  96.         print(commentBodyModified)
  97.         print("reddit.com" + comment.permalink)
  98.         print(comment.author)
  99.         print("Banned words: " + wordsString)
  100.        
  101.         if comment.created_utc > startTime:
  102.             try:
  103.                 userIsBanned = any(reddit.subreddit('OneWordBan').banned(redditor=comment.author))
  104.                 reddit.subreddit('OneWordBan').banned.add(comment.author
  105.                                                           , ban_reason = "Banned word - windforce2 bot"
  106.                                                           , ban_message = "reddit.com" + comment.permalink
  107.                                                           , note = "Automatically banned by windforce2's bot for this comment https://reddit.com" + comment.permalink + " for the words \"" + wordsString + "\"")
  108.                 banned = True
  109.                 if not userIsBanned:
  110.                     comment.reply("You have been banished for using the following words: " + wordsString + "\n\n*This is an automated posting by OneWordBan\'s Bot*")
  111.                     print("Banned user, replied")
  112.                 else:
  113.                     print("Skipping reply as user is already banned")
  114.             except Exception as e: print(e)
  115.         else:
  116.             print ("Skipping old")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement