def test_custom_wordlist(self): custom_badwords = ['happy', 'jolly', 'merry'] profanity.load_words(custom_badwords) # make sure it doesn't find real profanity anymore self.failIf(profanity.contains_profanity("F**k you!")) # make sure it finds profanity in a sentence containing custom_badwords self.failUnless(profanity.contains_profanity("Have a merry day! :)"))
def test_custom_wordlist(self): custom_badwords = ["happy", "jolly", "merry"] profanity.load_words(custom_badwords) # make sure it doesn't find real profanity anymore self.failIf(profanity.contains_profanity("F**k you!")) # make sure it finds profanity in a sentence containing custom_badwords self.failUnless(profanity.contains_profanity("Have a merry day! :)"))
def is_there_profanity(X): res = np.zeros((len(X), 1)) for i in range(len(X)): comment = X[i] prof = profanity.contains_profanity(comment) res[i] = int(prof) return res
def tweetInfo(api, initial, timeScore): """ Tweet the user given initial and timescore. inintals get parsed for profanity """ status = '{} cleared the junction in {}s!' # Check initial not empty if len(initial) == 0: name = 'NONE' api.PostUpdate(status.format(name, timeScore)) # limit iniital to 4 chars and remove symbols name = initial[:4].lower() # Use only 4 letter max words name = ''.join([c for c in name if c.isalnum()]) # All chars were symbols case if len(name) == 0: initial = 'NONE' api.PostUpdate(status.format(name, timeScore)) findMap = ['1', '3', '4', '7', '8', '9', '5', '0', '2'] replMap = ['i', 'e', 'a', 'l', 'b', 'g', 's', 'o', 'r'] for i, j in zip(findMap, replMap): name.replace(i, j) # profanity filter if profanity.contains_profanity(name): # name = initial[:4].upper() # name = name[0] + '***' name = name[0].upper() + '***' else: name = initial[:4].upper() # Post result to twitter api.PostUpdate(status.format(name, timeScore))
def verify_nice(word): profanity.load_words(profane_words()) clear_word = remove_duplicates(word) if not word.isalpha(): raise Exception('Input can contain only letters') if any([w for w in [word, clear_word] if profanity.contains_profanity(w)]): raise Exception('Input should not be a profanity')
def check_answer(user_message): answer_data['user_answers'].append(user_message) split_answer = user_message.lower().split(' ') if profanity.contains_profanity(user_message): return bad_manners_api() if len(answer_data['user_answers']) == 1: return greet(split_answer[-1]) if any(x in user_message.lower() for x in keywords['greeting_list'] ): # In case user wants to change his name. return keywords['my name'](split_answer[-1]) if split_answer[-1] == '?': for word in split_answer: if word in keywords.keys(): return keywords[word]() else: return bot_answer( 'bored', "I see you want to ask a question,but i don't get it. Ask for help to see a list of commands!" ) else: chatbot_answer = "I don't get it. Don't forget the question mark if you want to ask a question!" return bot_answer("confused", chatbot_answer)
async def on_message(message): print('message received from ' + message.author.display_name + " in " + message.channel.name) global channel channel = message.channel global server server = channel.server global caller global init caller = message.author if (init == False and caller.id != myself): await torgo.send_message( channel, "I AM TORGO. Type `$commands` to see a list of commands.") init = True #checks if the name "TORGO" has been said if re.search('torgo', message.content, re.IGNORECASE): await torgo.add_reaction(message, u'\U0001f440') #eyes emoji #checks for profanity and sends a cool message if profanity.contains_profanity(message.content): await torgo.send_typing(channel) #create the text from the message to_draw = message.content print(to_draw) #create an image based on the number of chars in the message txt = Image.new('RGBA', (35 * (len(to_draw)), 100), (255, 255, 255, 0)) fnt = ImageFont.truetype('resources/ModerneFraktur.ttf', 64) rend = ImageDraw.Draw(txt) rend.text((1, 20), to_draw, fill=(200, 0, 0, 255), font=fnt) #save, send, and delete txt.save('temp/texto.png') await torgo.send_file(channel, 'temp/texto.png') os.remove(filepath + '/temp/texto.png') await torgo.process_commands(message)
def main(): racial_slurs = [ 'abbie', 'abe', 'abie', 'abc', 'abcd', 'abid', 'abeed', 'abo', 'abbo', 'annamite', 'arabuh', 'armo', 'aseng', 'arab', 'bamboula', 'beaner', 'bluegum', 'bosche', 'boche', 'bosch', 'boonga', 'boong', 'bunga', 'boonie', 'bootlip', 'brownie', 'chankoro', 'chankoro', 'cheesehead', 'chinaman', 'cholo', 'coon', 'cracker', 'cushi', 'darky', 'dothead', 'fob', 'goy', 'goyim', 'goyum', 'gringo', 'groid', 'guido', 'gypsy', 'hairyback', 'half-breed', 'haole', 'heeb', 'hebe', 'hillbilly', 'honky', 'honkey', 'honkie', 'hymie', 'jap', 'jewboy', 'jigaboo', 'kaffir', 'kaffer', 'kafir', 'kaffre', 'kuffar', 'kalar', 'kanaka', 'mooncricket', 'niglet', 'nignog', 'nig-nog', 'nip', 'oreo', 'paki', 'raghead', 'russki', 'shylock', 'slant', 'sooty', 'tacohead', 'tar-baby', 'wigger', 'zipperhead', 'chink', 'nigger', 'kike', 'spic', 'wetback', 'towelhead' ] offbeat_slurs = ['cuck', 'libtard', 'maga'] total_lines = 0 profanity_lines = 0 allFiles = getListOfFiles('Multiplayer') for filename in allFiles: content = [line.rstrip('\n') for line in open(filename)] total_lines += 1 for line in content: if profanity.contains_profanity(line): profanity_lines += 1 print(line[25:]) writeToFile("Profanities.txt", re.sub(r'\W+', ' ', line[25:]).upper()) print(profanity_lines)
async def on_message(self, message): custom_badwords = ["bitch", "shit", "ass", "dumbass"] profanity.load_words(custom_badwords) if profanity.contains_profanity(message.content): await message.delete() await message.channel.send( "Stop cursing this server doesn't allow it.")
def removePetsWithProfanity(): conn = sqlite3.connect('../db.sqlite3') c = conn.cursor() petListing = c.execute( "SELECT breed,name,city,zip,petid FROM FurFinderAPI_pet ").fetchall() for i in range(len(petListing)): if profanity.contains_profanity( petListing[i][0]) == True or profanity.contains_profanity( petListing[i][1]) == True or profanity.contains_profanity( petListing[i] [2]) == True or profanity.contains_profanity( petListing[i][3]) == True: removePet(petListing[i][4]) conn.commit() conn.close()
def __vulgar_and_density(self, text): length = float(len(self.__tokenized_text)) prof = 0 for word in self.__tokenized_text: if profanity.contains_profanity(word): prof += 1 return [prof, prof/length]
def check_profanity(text_to_check): is_it_dirty = profanity.contains_profanity(text_to_check) if is_it_dirty: suggested_text = profanity.censor(text_to_check) print("\nThe following text was censored:\n") print(suggested_text) return is_it_dirty
async def on_message(message): if message.content.startswith(client.user.mention): InitialMsg = await client.send_message(message.channel, message.author.mention + " **Thinking...**") SlashResponse = message.content SlashResponse = SlashResponse.replace(client.user.mention, "") if profanity.contains_profanity(SlashResponse): response = """```ERROR: You cannot send controversial messages using this bot.```""" else: response = str(chatbot.get_response(SlashResponse)) if profanity.contains_profanity(response): response = str(profanity.censor(response)) await client.edit_message(InitialMsg, message.author.mention + " " + response) if message.content.startswith('$$reload'): cw = [line.rstrip('\n') for line in open('controversialwords.txt')] profanity.load_words(cw) await client.send_message(message.channel, message.author.mention + " **Controversial words reloaded!**")
def profanity_analysis(content): content = re.sub(r'#(\w+)\b', ' $1 ', content) content = re.sub(r'@\w+\b', '', content) #tokens=nltk.word_tokenize(content.lower()) contain_profanity = profanity.contains_profanity(content) return contain_profanity
def index(): stored_days = get_stored_days() end_date = get_end_date(stored_days) if request.method == 'POST': if profanity.contains_profanity(request.form['username']) == False: write_to_file('data/users.txt', request.form['username'] + '\n') return redirect(request.form['username']) return render_template('index.html', end_date=end_date)
def check_profanity(text_to_check): output = profanity.contains_profanity(text_to_check) if "True" in str(output): print("profanity alert!") print(profanity.censor(text_to_check)) elif "False" in str(output): print("this document is good to go.") else: print("cannot scan the document properly.")
async def on_message(self, message): if profanity.contains_profanity(message.content): await message.delete() await message.author.send( f"{message.author.mention} don't use that type of language") return elif not await automod.check_curses(self, message): return await self.client.process_commands(message)
def check_if_containing_bad_words(sentence): try: is_offensive = profanity.contains_profanity(sentence) return is_offensive except: pass return False
def is_bad_message(msg): if(profanity.contains_profanity(msg)): return True with open('project/phrases.json') as f: data = json.load(f) for phrase in data: for word in data[phrase]: ratio = fuzz.token_set_ratio(word,msg) if ratio > 60: return True return False
async def on_message(message): if profanity.contains_profanity(message.content): await bot.delete_message(message) if db.contains(Users.id == message.author.id): if db.contains((Users.id == message.author.id) & (Users.swears == 2)): await bot.kick(message.author) db.update({'swears': 0}, Users.id == message.author.id) else: db.update(increment('swears'), Users.id == message.author.id) else: db.insert({'id': message.author.id, 'swears': 0}) await bot.send_message(message.author,"You have recived a strike if you recive three strikes you will be kicked")
def new_artist(artist): out = [] for artist in musicbrainzngs.search_artists(artist)["artist-list"]: if not profanity.contains_profanity(artist["name"]): if "disambiguation" in artist.keys(): out.append([ artist["name"] + " (" + artist["disambiguation"] + ")", artist["id"], ]) else: out.append([artist["name"], artist["id"]]) return render_template("newartist.html", list=out[:10])
def read_text(): quotes = open(r"C:\Users\Saikat\Documents\SavedPyFiles\test.txt") contents_of_file = quotes.read() print(contents_of_file) output = profanity.contains_profanity(contents_of_file) #print(output) if output == True: print("Alert: This file is not good") elif output == False: print("No problem, file is good") else: print("Could not scan the file") quotes.close()
async def on_message_edit(before, after): message = after if profanity.contains_profanity(message.content): await bot.delete_message(message) if db.contains(Users.id == message.author.id): if db.contains((Users.id == message.author.id) & (Users.swears == 2)): await bot.kick(message.author) db.update({'swears': 0}, Users.id == message.author.id) else: db.update(increment('swears'), Users.id == message.author.id) else: db.insert({'id': message.author.id, 'swears': 0}) await bot.send_message(message.author,"Don't curse, bitch. You have 2 more chances.")
def _process_name(name): if not name: raise ValueError() if len(name) > 25: raise ValueError() profane = profanity.contains_profanity(name) if profane: raise ValueError() name = name.strip() if name.lower() == name: # no capital letters, make some assumptions return name.title() return name
def home_screen(): command_strings = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "--h"] help_info = "\t- (1) To find out how old I am!\n\t- (2) If you would like to hear a joke!\n\t- (3) If you wanna throw a party! (CTRL+C to stop the party!)\n\t- (4) If you would like to play a game!\n\t- (5) If you would like to hear a joke generated by the Interwebs!\n\t- (6) To attempt to cross the Bridge!!\n\t- (7) To Talk to Forrest Gump!\n\t- (8) To release the Dancing Elves! \n\t- (9) If you would like to leave\n\tOr just talk to me!" greeting() print('{}\n--h to display this menu again'.format(help_info)) active = True while (active is True): text = input(">>>: ") if text not in command_strings: if profanity.contains_profanity(text): print("WATCH YO PROFANITY!!") else: append_phrases(text) print(random_message()) elif text == "1": print(age()) elif text == "2": print(get_jokes()) elif text == "3": os.system('curl parrot.live') print('\n\n') elif text == "4": play_the_guessing_game() elif text == "5": print( requests.get('https://icanhazdadjoke.com', headers={ 'Accept': 'application/json' }).json()['joke']) elif text == "6": crossing_the_bridge() elif text == "7": talking_with_Gump() elif text == "8": release_the_elves() elif text == '9': active = False print("\n" + "Goodbye" + "\n") elif text.lower() == "--h": print(help_info)
def run(self): depression = Depression(self.txt, self.general_words, self.academic_words, self.suicidal_words, self.social_words, self.family_words, self.drugs_words, self.financial_words, self.guns_words, self.date_words, self.revenge_words) score = depression.totalRatio + profanity.contains_profanity( self.txt) * 0.2 * depression.totalRatio if score > 50: #depressed return (depression.getCategory(), score) else: #not depressed return (0, 0)
def save_user_trial_segue_sample(): """Takes a sample of json files saved by save_segues() and save it into another folder, to be used for drawing it during the user trial. We'd like to pose a limit on the number of different segues that we show, so that there would be also a limit on the number of segues we'll have to label manually. We choose to take a sample of 200 segues. """ sample_size = 200 folder_src = f"{preprocessed_dataset_path}/user_trial" folder_dst = f"{preprocessed_dataset_path}/user_trial_sample" number = len(glob.glob1(folder_src, "*.json")) # filter out profanity pool = [] from tqdm import tqdm for j in tqdm(range(1, number + 1)): with open(f"{folder_src}/{j}.json") as fp: d = json.load(fp) if not profanity.contains_profanity(d['seed_song']['artist_name']) and \ not profanity.contains_profanity(d['seed_song']['track_name']) and \ not profanity.contains_profanity(d['song_the_chain']['artist_name']) and \ not profanity.contains_profanity(d['song_the_chain']['track_name']) and \ not profanity.contains_profanity(d['song_dave']['artist_name']) and \ not profanity.contains_profanity(d['song_dave']['track_name']) and \ not profanity.contains_profanity(d['segue_dave']['line']) and \ not profanity.contains_profanity(d['segue_the_chain']): pool.append(j) # sampling random.seed(42) sample = random.sample(pool, sample_size) for j in sample: with open(f"{folder_src}/{j}.json") as fp: d = json.load(fp) with open(f"{folder_dst}/{j}.json", 'w') as fp: json.dump(d, fp)
def create_team(*, user_id): if "name" not in flask.request.json: raise util.APIError(400, message="Please provide a team name.") # Validate team name name = flask.request.json["name"] if len(name) > TEAM_NAME_LENGTH or \ profanity.contains_profanity(name) or \ wordfilter.blacklisted(name) or \ not TEAM_NAME_REGEX.match(name): raise util.APIError( 400, message= "Invalid team name. Team name must begin with an upper or lower case ASCII letter and may only contain up to {} alphanumeric characters plus dashes and underscores." .format(TEAM_NAME_LENGTH)) team_name = "Team " + name verification_code = secrets.token_hex(16) # Check if user is already on a team with model.engine.begin() as conn: if conn.execute( model.teams.select( sqlalchemy.sql.func.lower(model.teams.c.name) == team_name.lower())).first(): raise util.APIError(400, message="That team name is taken, sorry.") query = model.users.select((model.users.c.id == user_id) & (model.users.c.team_id != None)) if conn.execute(query).first(): raise util.APIError(400, message="You're already on a team.") try: team_id = conn.execute(model.teams.insert().values( name=team_name, verification_code=verification_code, leader_id=user_id, )).inserted_primary_key[0] except sqlalchemy.exc.IntegrityError: raise util.APIError(400, message="Duplicate team name.") conn.execute(model.users.update().values( team_id=team_id, ).where(model.users.c.id == user_id)) return util.response_success({ "team_id": team_id, "verification_code": verification_code, })
def index(): if request.method == 'POST': keyword = request.form['keyword'] keywords = keyword.split(" ") keywords = [a.lower() for a in keywords] if profanity.contains_profanity(keyword): return render_template('index.html', is_profane=True, query=None, keyword=None) if keyword: return render_template('index.html', is_profane=False, query=results(keywords), keyword=keyword) return render_template('index.html')
def emotional_reaction(self, text): # how does the user feel user_emotion_data = self.extract_user_emotions(text) # how do i feel about the text content deepmoji_data = self.extract_text_emotions(text) # profanity bias if contains_profanity(text): self.add_emotion("disgust") data = {"bias": "disgust"} self.status_update("detected profanity", data) # TODO reactions from emotions reactions = [] return reactions
def post(self): json_data = request.get_json(force=True) try: userId = json_data["userId"] except: userId = None current_user = load_user(userId) try: groupIdPosted = json_data["groupId"] except: groupIdPosted = None try: content = json_data["content"] except: content = None if content is not None: if profanity.contains_profanity(content): res = "The post contents offensive language therefore we are censoring it" content = profanity.censor(content) try: visibility = json_data["visibility"] except: visibility = None datetimePost = datetime.utcnow() if hasattr(current_user, "domain"): groupIdOwner = current_user.id postt = GroupPost(groupIdPosted=groupIdPosted, content=content, visibility=visibility, datetime=datetimePost, groupIdOwner=groupIdOwner) else: userIdOwner = current_user.id postt = UserPost(groupIdPosted=groupIdPosted, content=content, visibility=visibility, datetime=datetimePost, userIdOwner=userIdOwner) db.session.add(postt) db.session.commit() return jsonify({"description": "The post has been successfully made"}), 200, headers
def __get_random_title(self, url): """ Returns a (one) random post title """ try: titles = self.__get_titles(self.__get_json(url)) post = titles[self.__rand()] retries = 20 custom_badwords = ['reddit', 'redditor'] profanity.load_words(custom_badwords) while profanity.contains_profanity(post): post = titles[self.__rand()] retries -= 1 if retries < 1: break return post except Exception as ex: return 'There is a feed problem at the moment: ' + str(ex)
def filtered_words(wordlist): ''' Input an unfiltered list of words as the first arg `python language_filter.py unfiltered_words.txt` Return a word if it is not considered offensive. Arguments: word : string Returns: Word, if it is not included in the offensive_filter ''' # Load custom offensive dictionary with open('offensive_filter.txt', 'r') as readfile: bad_words = readfile.readlines() bad_words = [word.strip() for word in bad_words] profanity.load_words(bad_words) with open(wordlist, 'r') as readfile: for word in readfile: if not profanity.contains_profanity(word): print word
def post_process_review(review_id): review = database.Review.get_one_by(id=review_id) if not review: return original_review_body = review.body # check for profanity review.profanity = profanity.contains_profanity(original_review_body) if review.profanity: review.profanity_not_removed_body = original_review_body review.body = profanity.censor(original_review_body) # sentiment analysis text_blob = TextBlob(original_review_body) review.sentiment_polarity = text_blob.sentiment.polarity review.sentiment_subjectivity = text_blob.sentiment.subjectivity review.spell_checked_body = unicode(text_blob.correct()) # store database.add(review) database.push()
def test_contains_profanity(self): profane = profanity.contains_profanity("dude, SHIT!") self.failUnless(profane)
access_token_key = '' access_token_secret = '' profanity.set_censor_characters('💩') search_terms = profanity.get_words() api = TwitterAPI(consumer_key, consumer_secret, access_token_key, access_token_secret) r = api.request('search/tweets', {'q': random.choice(search_terms), 'lang': 'en'}) for tweet in r: tweet_text = tweet.get('text') tweet_poster = tweet.get('user').get('screen_name') tweet_id = tweet.get('id') if 'RT' not in tweet_text.split()[0] and len(tweet_text) < (133 - len(tweet_poster)): if profanity.contains_profanity(tweet_text): # tweet at the user with their corrected tweet censorship_tweet = api.request( 'statuses/update', { 'status': "{}*ftfy @{}".format(profanity.censor(tweet_text), tweet_poster), 'in_reply_to_status_id': int(tweet_id) } ) print('Censored: {}'.format(censorship_tweet.status_code)) # like the tweet like = api.request('favorites/create', {'id': int(tweet_id)}) print('Like: {}'.format(like.status_code)) # follow the user