Help Needed: Making a profanity filter
Posted: Wed Jul 22, 2020 2:24 pm
Hi, all!
I hope everyone is doing well.
So I've been working on creating a code that can filter/censor bad words on the fly.
Below is my pseudo code.
So I was kind of messing around with this code that is made to censor bad words and it seems to work as intended (outside of RenPy).
But now I'm struggling to figure out how to implement it correctly to work properly in RenPy.
Here's the code as a function;
So I've tried;
But this results in an exception occurring;
... I kinda understand what it's trying to tell me, but... I have no idea how to solve this.
Any and all suggestions are welcome. Thank you!
EDIT: Upon further testing I realised that the function above is actually really agressive.
Example;
Perhaps I may be asking for too much, but of course, this code isn't ideal to censor part of a word that isn't meant to be censored.
I hope everyone is doing well.
So I've been working on creating a code that can filter/censor bad words on the fly.
Below is my pseudo code.
So I was kind of messing around with this code that is made to censor bad words and it seems to work as intended (outside of RenPy).
But now I'm struggling to figure out how to implement it correctly to work properly in RenPy.
Here's the code as a function;
Code: Select all
init python:
def profane_filter(sentence, text_censor=False):
p_filter = { <list of bad words here> } ## Removed bad words for the sake of keeping it friendly.
if sentence is not None:
if text_censor:
for f in p_filter:
sentence = sentence.replace(f, ('*' * len(f)))
sentence = sentence.replace(f.upper(), ('*' * len(f)))
sentence = sentence.replace(f.capitalize(), ('*' * len(f)))
return sentence
## Not sure if I'm using this correctly or if it's not the one I want, but it doesn't yield any results.
config.say_menu_text_filter = profane_filter(renpy.get_say_attributes(), text_censor=True)
Code: Select all
screen say(who, what):
style_prefix "say"
python:
## Hm. Maybe this list should be outside the python block?
p_filter = { <list of bad words here> }
for f in p_filter:
what = what.replace(f, ('*' * len(f)))
what = what.replace(f.upper(), ('*' * len(f)))
what = what.replace(f.capitalize(), ('*' * len(f)))
window:
id "window"
if who is not None:
window:
id "namebox"
style "namebox"
text who.upper() id "who"
text what id "what"
...
Code: Select all
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/script.rpy", line 31, in script
"What the fuck?"
Exception: The displayable with id 'what' was not given the exact contents of the what variable given to the say screen.
Any and all suggestions are welcome. Thank you!
EDIT: Upon further testing I realised that the function above is actually really agressive.
Example;
Code: Select all
def profane_filter(sentence, text_censor=False):
p_filter = { 'tit' } ## Removed bad words for the sake of keeping it friendly.
if sentence is not None:
if text_censor:
for f in p_filter:
sentence = sentence.replace(f, ('*' * len(f)))
sentence = sentence.replace(f.upper(), ('*' * len(f)))
sentence = sentence.replace(f.capitalize(), ('*' * len(f)))
return sentence
print(profane_filter("Title", text_censor=True))
Output <<< "***le".