def is_input_valid(input_value): value = input_value.lower() pf = ProfanityFilter() for invalid_string in invalid_list: if re.search(invalid_string, value, re.IGNORECASE): return False if not pf.is_clean(value): return False return True
def get_word_web(start_word): ph = Phyme() perfect_rhymes = ph.get_perfect_rhymes(start_word) pf = ProfanityFilter() #gets one syllable perfect rhymes if 1 in perfect_rhymes: list_single_rhymes = perfect_rhymes[1] else: list_single_rhymes = perfect_rhymes[2] word_web = {} antonyms = [] for word in list_single_rhymes: if pf.is_clean(word): syns = wordnet.synsets(word) associated_words = {} associated_words["v"] = [] #verb associated_words["n"] = [] #noun associated_words["s"] = [] associated_words["a"] = [] #adjective associated_words["r"] = [] associated_words["i"] = [] for l in syns: arr = l.name().split(".") if len(arr[1]) == 1: results = associated_words[arr[1]] results.append(l.lemmas()[0].name()) associated_words[arr[1]] = results if len(l.hypernyms()) > 0: for hyp in l.hypernyms(): arr = hyp.name().split(".") if len(arr[1]) == 1: results = associated_words[arr[1]] results.append(hyp.lemmas()[0].name()) associated_words[arr[1]] = results if len(l.hyponyms()) > 0: for hyp in l.hyponyms(): arr = hyp.name().split(".") if len(arr[1]) == 1: results = associated_words[arr[1]] results.append(hyp.lemmas()[0].name()) associated_words[arr[1]] = results for syn in l.lemmas(): if syn.antonyms(): antonyms.append(syn.antonyms()[0].name()) word_web[word] = associated_words word_web["antonyms"] = antonyms return word_web
async def adopt_pet(self, context): # create instance of the user who wishes to feed their pet pet_owner = Users(context.author.id) if pet_owner.find_pet() == 1: msg = await context.send("Failed! You already have a pet!") await asyncio.sleep(5) await msg.delete() return intro_msg = "Welcome to the **Pet Shelter**!\n\nPlease enter your desired pet name now:" # embed intro message, then overwrite the variable with the actual message object em = discord.Embed(description=intro_msg, colour=0x607D4A) em.set_thumbnail( url= "https://cdn.discordapp.com/emojis/746904102650249296.gif?size=128" ) await context.send(embed=em) # wait for user's pet name entry # helper to check if it's the author that it's responding. def is_author(m): return m.author == context.author and m.channel == context.channel pet_name = await self.client.wait_for("message", check=is_author, timeout=60) # remove everything except alphanumerics from the user's pet name entry pet_name = re.sub(r"\W+", "", pet_name.clean_content) # create an object to scan profanity pf = ProfanityFilter() # while the pet name entry has profanity, prompt user to re-enter a name while not pf.is_clean(pet_name): await context.send( "Pet name has profanity! Please enter a new one now:") # wait for user's new pet name entry pet_name = await self.client.wait_for("message", check=is_author, timeout=60) # remove everything except alphanumerics from the user's pet name entry pet_name = re.sub(r"\W+", "", pet_name.clean_content) adoption_msg = pet_owner.add_pet(pet_name[:15]) # embed confirmation message em = discord.Embed(description=adoption_msg, colour=0x607D4A) em.set_thumbnail( url="https://cdn.discordapp.com/emojis/563872560308289536.png?v=1") await context.send(embed=em)
def main(argv): with open(sys.argv[1], 'r') as inputfile, open(sys.argv[2], 'a') as outputfile: df = pd.read_csv(inputfile) #return df #def check_profanity(df): pf = ProfanityFilter() profanity = [] for row in df['body']: prof = pf.is_clean(row) profanity.append(prof) df['profanity'] = profanity df.to_csv(outputfile)
async def update_pet_name(self, context): # create instance of the user who wishes to change their pet name pet_owner = Users(context.author.id) # retrieve pet name pet_name = pet_owner.get_user_pet_name() intro_msg = f"Welcome to the **Pet Shelter**!\n\nPlease enter your new name for **{pet_name}** now:" # embed intro message, then overwrite the variable with the actual message object em = discord.Embed(description=intro_msg, colour=0x607D4A) em.set_thumbnail( url= "https://cdn.discordapp.com/emojis/560065150489722880.png?size=128" ) await context.send(embed=em) # wait for user's pet name entry # helper to check if it's the author that it's responding. def is_author(m): return m.author == context.author and m.channel == context.channel pet_name = await self.client.wait_for("message", check=is_author, timeout=60) # remove everything except alphanumerics from the user's pet name entry pet_name = re.sub(r"\W+", "", pet_name.clean_content) # create an object to scan profanity pf = ProfanityFilter() # while the pet name entry has profanity, prompt user to re-enter a name while not pf.is_clean(pet_name): await context.send( "Pet name has profanity! Please enter a new one now:") # wait for user's new pet name entry pet_name = await self.client.wait_for("message", check=is_author, timeout=60) # remove everything except alphanumerics from the user's pet name entry pet_name = re.sub(r"\W+", "", pet_name.clean_content) confirmation_msg = pet_owner.update_user_pet_name(pet_name[:15]) # embed confirmation message em = discord.Embed(description=confirmation_msg, colour=0x607D4A) em.set_thumbnail( url="https://cdn.discordapp.com/emojis/746904102650249296.gif?v=1") await context.send(embed=em)
def clean_tweets(username): """A program to clean up all your twitter of any profanity.""" # Get API keys # keys_path = os.getcwd() + "/clean/twitter/secrets.json" with open(keys_path, 'r') as filein: try: keys = json.load(filein) except ValueError: # simplejson.decoder.JSONDecodeError print("Error_JSON could not read json file") exit(1) # Authorization to consumer key and consumer secret auth = tweepy.OAuthHandler(keys["consumer_key"], keys["consumer_secret"]) # Access to user's access key and access secret auth.set_access_token(keys["access_token"], keys["access_token_secret"]) # Calling api api = tweepy.API(auth) try: redirect_url = auth.get_authorization_url() except tweepy.TweepError: print ('Error! Failed to get request token.') # Get tweets # # 200 tweets to be extracted number_of_tweets=200 tweets = api.user_timeline(screen_name=username, tweet_mode='extended', count = number_of_tweets) # profanity filter pf = ProfanityFilter() # Printing the tweets for tweet in tweets: if not(pf.is_clean(tweet.full_text)): print(tweet.full_text + "\n")
# In[8]: pf.define_words(["icecream", "choco"]) # In[9]: pf.censor("I love icecream and choco!") # In[10]: pf.is_clean("That's awesome!") # In[11]: pf.is_clean("That's bullshit!") # In[12]: pf_custom = ProfanityFilter(custom_censor_list=["chocolate", "orange"]) pf_custom.censor("F**k orange chocolates")
def new_comment(request): if request.method == "POST": # set environment variable `DISABLE_RECAPTCHA` to disable recaptcha # verification and delete the variable to enable recaptcha verification disable_recaptcha = os.getenv("DISABLE_RECAPTCHA", None) flag = True if not disable_recaptcha: recaptcha_response = request.POST.get("g-recaptcha-response") url = "https://www.google.com/recaptcha/api/siteverify" payload = { "secret": settings.RECAPTCHA_PRIVATE_KEY, "response": recaptcha_response, } data = urllib.parse.urlencode(payload).encode() req = urllib.request.Request(url, data=data) response = urllib.request.urlopen(req) result = json.loads(response.read().decode()) flag = result["success"] if flag: # if score greater than threshold allow to add comment = request.POST.get("comment") article_pk = request.POST.get("article") article = Article.objects.get(pk=article_pk) user_pk = request.POST.get("user", None) parent_pk = request.POST.get("parent", None) if parent_pk: parent = Comment.objects.get(pk=parent_pk) else: parent = None if user_pk: user = User.objects.get(pk=user_pk) username = user.username else: user = None username = request.POST.get("username") pf = ProfanityFilter() if pf.is_clean(comment) and pf.is_clean(username): c = Comment( username=username, content=comment, user=user, article=article, parent=parent, ) c.save() else: messages.add_message( request, messages.ERROR, "Abusive content detected! Please refrain\ from using any indecent words while commenting.", ) else: messages.add_message(request, messages.ERROR, "reCAPTCHA verification failed.") redirect_path = request.POST.get("redirect") cache.clear() # mem = MemcachedStats() # keys = [_[3:] for _ in mem.keys()] # for key in keys: # if 'cache_page' in key or 'cache_header' in key: # print(key, cache.get(key)) # cache.delete(key) if redirect_path: return redirect(redirect_path) else: return redirect("/")
def new_comment(request): if request.method == 'POST': # set environment variable `DISABLE_RECAPTCHA` to disable recaptcha # verification and delete the variable to enable recaptcha verification disable_recaptcha = os.getenv('DISABLE_RECAPTCHA', None) if not disable_recaptcha: recaptcha_response = request.POST.get('g-recaptcha-response') url = 'https://www.google.com/recaptcha/api/siteverify' payload = { 'secret': settings.RECAPTCHA_PRIVATE_KEY, 'response': recaptcha_response } data = urllib.parse.urlencode(payload).encode() req = urllib.request.Request(url, data=data) response = urllib.request.urlopen(req) result = json.loads(response.read().decode()) flag = True if not disable_recaptcha: flag = (result['success'] and result['action'] == 'comment' and result['score'] >= settings.RECAPTCHA_THRESHOLD) if flag: # if score greater than threshold allow to add comment = request.POST.get('comment') article_pk = request.POST.get('article') article = Article.objects.get(pk=article_pk) user_pk = request.POST.get('user', None) parent_pk = request.POST.get('parent', None) if parent_pk: parent = Comment.objects.get(pk=parent_pk) else: parent = None if user_pk: user = User.objects.get(pk=user_pk) username = user.username else: user = None username = request.POST.get('username') pf = ProfanityFilter() if pf.is_clean(comment) and pf.is_clean(username): c = Comment(username=username, content=comment, user=user, article=article, parent=parent) c.save() else: messages.add_message( request, messages.ERROR, 'Abusive content detected! Please refrain\ from using any indecent words while commenting.' ) else: messages.add_message(request, messages.ERROR, 'reCAPTCHA verification failed.') redirect_path = request.POST.get('redirect') if redirect_path: return redirect(redirect_path) else: return redirect('/')
class TwitchAIDungeon: def __init__(self): # Initialize variables to None self.host = None self.port = None self.chan = None self.nick = None self.auth = None capability = ["tags"] self.access_token = None self.cooldown = 0 self.last_command_time = 0 self.allowed_ranks = [] self.allowed_users = [] self.custom_prompt = "" with open("blacklist.txt", "r") as f: censor = [l.replace("\n", "") for l in f.readlines()] self.pf = ProfanityFilter(custom_censor_list=censor) # Create an Api instance to connect to AI Dungeon 2. logging.debug("Creating API instance.") self.api = API(self) # Update variables logging.debug("Setting settings.") Settings(self) # Create a Database instance for storing which users do not want to be whispered logging.debug("Creating Database instance.") self.db = Database(self.chan) # Get the session_id self.session_id = self.api.get_session_id() # Create Websocket object logging.debug("Creating TwitchWebsocket object.") self.ws = TwitchWebsocket(host=self.host, port=self.port, chan=self.chan, nick=self.nick, auth=self.auth, callback=self.message_handler, capability=capability, live=True) # Start a blocking websocket connection logging.debug("Starting Websocket connection.") self.ws.start_bot() def set_settings(self, host, port, chan, nick, auth, cooldown, access_token, allowed_ranks, allowed_users, custom_prompt): self.host, self.port, self.chan, self.nick, self.auth, self.cooldown, self.access_token, self.allowed_ranks, self.allowed_users, self.custom_prompt = host, port, chan, nick, auth, cooldown, access_token, [rank.lower() for rank in allowed_ranks], [user.lower() for user in allowed_users], custom_prompt def message_handler(self, m): if m.type == "366": logging.info(f"Successfully joined channel: #{m.channel}") elif m.type == "PRIVMSG": if m.message.startswith("!do"): self.command_do(m) elif m.message.startswith("!remember"): self.command_remember(m) elif m.message.startswith("!revert"): self.command_revert(m) elif m.message.startswith("!event"): self.command_event(m) elif m.message.startswith(("!say", "!talk", "!ask")): self.command_say(m) elif m.message.startswith("!help"): self.command_help(m) elif m.message.startswith("!restart") and self.check_permissions(m): self.command_restart(m) def extract_message(self, m): try: # Extract the message after the first space. return m.message[m.message.index(" ") + 1:] except ValueError: # If no spaces, return empty string return "" def check_permissions(self, m): for rank in self.allowed_ranks: if rank in m.tags["badges"]: return True return m.user.lower() in self.allowed_users def check_cooldown(self): # True iff it has been `self.cooldown` seconds since the last command use. return self.last_command_time + self.cooldown < time.time() def check_cooldown(self, m): # Difference is the amount of seconds remaining on the cooldown difference = self.last_command_time + self.cooldown - time.time() if difference <= 0: return True # If the cooldown has been hit, and the user has not said they don't want to be whispered, then whisper them the cooldown. if not self.db.check_whisper_ignore(m.user): out = f"Cooldown hit: {difference:.2f} out of {self.cooldown:.0f}s remaining. !nopm to stop these cooldown pm's." logging.debug(out) self.ws.send_whisper(m.user, out) return False def response_task(self, message, prefix, postfix, custom_output): # Get the actual output from the API out = self.api.say(prefix + message + postfix) # If a custom output is warranted for this action type, use that as output instead if custom_output: out = custom_output else: # Censor the output out = self.censor(out) # Convert to a better format, eg remove newlines. out = self.parse_output(out) if out: logging.info(f"Chat output: {out}") # If `out` could be considered a command, # then prepend a space which does not get filtered out by twitch, # which should prevent the message as being considered a command if out.startswith(("!", "~", ".", "/", "\\")): out = "Рађ" + out self.ws.send_message(out) else: out = "AI Dungeon 2 responded with an empty message, sadly." logging.error(out) self.ws.send_message(out) def command_action(self, message, prefix="", postfix="", custom_output="", force=False): # If force is True, then we will communicate with the API even if the message is empty. # Function to handle communication between API and this class if message or force: logging.debug(f"Calling api.say with \"{prefix + message + postfix}\"") # Check if the input contains a banned word if self.is_clean(message): # Set the last_command_time to the current time for cooldown self.last_command_time = time.time() # Create a threading daemon task for sending responses to the API t = threading.Thread(target=self.response_task, args=(message, prefix, postfix, custom_output), daemon=True) t.start() return logging.warning(f"The input \"{message}\" was filtered out.") out = "This input contained a banned word or phrase!" else: out = "Please also enter a message alongside your command." logging.info(f"Chat output: {out}") self.ws.send_message(out) def is_clean(self, message): # True if message does not contain a banned word. return self.pf.is_clean(message) def censor(self, message): # Replace banned phrase with *** censored = self.pf.censor(message) if message != censored: logging.warning(f"Censored \"{message}\" into \"{censored}\".") return censored def command_do(self, m): if self.check_cooldown(m): # Force is True for `!do`, as an empty message will allow more dialoge to generate on its own self.command_action(self.extract_message(m), force=True) def command_remember(self, m): #if self.check_cooldown(m): message = self.extract_message(m) self.command_action(message, prefix="/remember ", custom_output=f"Added \"{message}\" to game's memory.") def command_revert(self, m): # Note that reverting is not affected by the cooldown and can be done whenever. # TODO: Add a short cooldown to prevent two people from reverting at once, and reverting twice. self.command_action("/revert", custom_output=f"The last action has been reverted.") def command_event(self, m): if self.check_cooldown(m): self.command_action(self.extract_message(m), prefix="!") def command_say(self, m): if self.check_cooldown(m): self.command_action(self.extract_message(m), prefix="\"", postfix="\"") def command_help(self, m): self.ws.send_message("!do <text> to take an action. !remember <text> to remember `text`. !revert to revert the last action. !event <text> to have `text` occur. !say <text> to speak `text`.") def parse_output(self, message): # TODO: Improve upon this. # Make it so conversations with different perspectives are clearly separated. return message.replace("\n", " ") def restart_task(self): # Get a new session_id and story from a new adventure session_id, story = self.api.start(self.custom_prompt) # Only if successful if session_id: self.session_id = session_id self.ws.send_message(story) logging.debug("Successfully started new story.") logging.info(story) else: self.ws.send_message("Failed to restart story.") logging.error("Failed to start new story.") def command_restart(self, m): # Set the last_command_time to the current time for cooldown self.last_command_time = time.time() # Asyncronously start a new story t = threading.Thread(target=self.restart_task, daemon=True) t.start()
except: break # Update the scroll ID sid = res['_scroll_id'] # Get the number of results that we returned in the last scroll scroll_size = len(res['hits']['hits']) print("scroll size: " + str(scroll_size)) for re in res['hits']['hits']: q=re['_source']['data']['origin']['query'] print(q) try: t=translator.translate(q).text print(type(t)) if pf.is_clean(t) and pf.is_clean(q) : with open('di_analysis_clean_all_2xt', 'a') as f: f.write(q+'\n') if q not in searches: searches.append(q) counter += 1 q_and_freq.update({q:1}) else: oldfred=q_and_freq[q] q_and_freq.pop(q) q_and_freq.update({q:oldfred+1}) except: print("something went wrong") print(counter)
async def on_message(self, message): if "lain" in message.author.display_name: await message.author.edit(nick="f****t") if "🐊" in message.author.display_name: await message.author.edit(nick="Gatorfree zone") if message.author.bot or message.content.startswith("."): return message.content = message.content.lower().replace('', '') user = message.author username = message.author.display_name pfp = message.author.avatar_url_as(size=1024) channelid = message.channel.name webhookurl = 'https://discord.com/api/webhooks/whatever' if "discordapp.com/attachments" in message.content: return #if "tenor." in message.content: # await message.delete(); if "discord.com/channels" in message.content: return if "discord.gg" in message.content or "discord." in message.content or ".gg/" in message.content: await message.delete() quotee = re.compile( r'(?!\bbased\b|\bsexpilled\b|\bis\b|\bare\b|\bhow\b|\byou\b|\bhello\b|\band\b|\bad\b|\byou\b|\blain\b|\bmy\b|\bdick\b|\bpenis\b|\bpussy\b|\bfag\b|\bam\b|\bnigger\b|\bi|\bI\b|\bu\b)\b[^\s]+\b' ) subit = "https://cdn.discordapp.com/attachments/673308690157404211/743601553356751002/unknown.png" result = re.sub(quotee, subit, message.content) print(message.content) print(result) async with aiohttp.ClientSession() as session: webhook = Webhook.from_url( webhookurl, adapter=AsyncWebhookAdapter(session)) await webhook.send(f'{result}', username=str(username), avatar_url=str(pfp)) if discord.utils.get(message.author.roles, name="Muted") != None: if message.author.id == 759621355708350484: return else: return await message.delete() if discord.utils.get(message.author.roles, name="Hardmute") != None: if message.author.id == 759621355708350484: return else: return await message.delete() if message.content == 'f': await message.channel.send( f"**{message.author.name}** has paid their respect {random.choice(['❤', '💛', '💚', '💙', '💜'])}" ) elif message.content.startswith('f '): reason = message.content.partition("f ")[2] await message.channel.send( f"**{message.author.name}** has paid their respect for **{reason}** {random.choice(['❤', '💛', '💚', '💙', '💜'])}" ) elif message.content.startswith('say'): if message.content.endswith('name'): embed = discord.Embed(color=0xe1a6e1) embed.set_image( url= "https://cdn.discordapp.com/attachments/660982562331820032/834182511781347328/unknown-61.png" ) await message.channel.send(embed=embed) #-------------------------------------------------------------------- if channelid != "degeneral": return if message.author.bot: return if ":trump" in message.content or "kenya" in message.content or "maya" in message.content or "sanya" in message.content or "tanya" in message.content or "chechnya" in message.content or "thnyan" in message.content or ":nyan:" in message.content or "nyaggot" in message.content or "https://" in message.content or "indication" in message.content or "excludedfag" in message.content or "blacksmith" in message.content: return a = message.content b = lists.censorship if "chinese" in a: pf = ProfanityFilter() if pf.is_profane(f"{a}") == True: word1 = "chinese" word2 = "GLORIOUS CHINESE" a = a.replace(f"{word1}", f"{word2}") if "china" in a: pf = ProfanityFilter() if pf.is_profane(f"{a}") == True: word1 = "china" word2 = "CHINA IS GLORIOUS RIDE DA TIGA I LOVE CHINA" a = a.replace(f"{word1}", f"{word2}") if "black woman" in a: answer = random.choice(lists.niggerresponse) word1 = "black woman" word2 = str(answer) a = a.replace(f"{word1}", f"{word2}") if "black people" in a: answer = random.choice(lists.niggerresponse) word1 = "black people" word2 = str(answer) a = a.replace(f"{word1}", f"{word2}") if "black person" in a: answer = random.choice(lists.niggerresponse) word1 = "black person" word2 = str(answer) a = a.replace(f"{word1}", f"{word2}") if "african" in a: answer = random.choice(lists.niggerresponse) word1 = "african" word2 = str(answer) a = a.replace(f"{word1}", f"{word2}") if "blacks" in a: if "blacksmith" in a: return answer = random.choice(lists.niggerresponse) word1 = "blacks" word2 = str(answer) + "s" a = a.replace(f"{word1}", f"{word2}") for x, y in b.items(): a = a.replace(x, y) if message.content == a: return async with aiohttp.ClientSession() as session: webhook = Webhook.from_url(webhookurl, adapter=AsyncWebhookAdapter(session)) await message.delete() await webhook.send(f'{a}', username=str(username), avatar_url=str(pfp)) try: if "https:" in message.content or "brother" in message.content: return else: for wordw in data: #print(wordw) if wordw.lower() in message.content.lower(): print(wordw.lower()) async with aiohttp.ClientSession() as session: fuckkw = message.content.lower() fuwfuwfu = fuckkw.replace( f"{wordw.lower()}", f"((({wordw.lower()})))") webhook = Webhook.from_url( webhookurl, adapter=AsyncWebhookAdapter(session)) await message.delete() await webhook.send(f'{fuwfuwfu}', username=str(username), avatar_url=str(pfp)) except Exception as e: print(f"{e}") if "@everyone" in message.content or "@here" in message.content: if discord.utils.get(user.roles, name="Heimdallar") != None: return elif message.author.id == 857346075585151006: return else: await message.delete() elif "pornhub.com/" in message.content: await message.channel.send(f'Meet someone in real lyfe, virgin xd') if "bot" in message.content or "laika" in message.content: if "both" in message.content: return pf = ProfanityFilter() if "kill" in message.content or "hate" in message.content: answer = random.choice(lists.anger) await message.channel.send(f'{answer}') if pf.is_profane(f"{message.content}") == True: answer = random.choice(lists.anger) await message.channel.send(f'{answer}') elif pf.is_clean(f"{message.content}") == True: return if "kill myself" in message.content: answer = random.choice(lists.suicide) await message.channel.send(f'{answer}') if "fix your bot" in message.content: answer = random.choice(lists.anger) await message.channel.send(f'{answer}')