feat: better profanity filtering

This commit is contained in:
Gerard Gascón 2025-04-23 16:24:22 +02:00
parent e97e204a5e
commit 3f5f2feff8
5 changed files with 1586 additions and 9 deletions

View file

@ -1,13 +1,20 @@
import json
import random
import profanity.templatetags.profanity
from django.db import IntegrityError
from django.http import HttpResponse, Http404
from server.filters import ProfanityFilter
from server.models import Dragon
pf = ProfanityFilter()
def is_profane(value):
return pf.is_profane(value)
def add(request, origin, name, color, shirt, hat, decor):
origin = origin.strip()
name = name.strip()
@ -16,11 +23,7 @@ def add(request, origin, name, color, shirt, hat, decor):
hat = int(hat.strip())
decor = int(decor.strip())
if profanity.templatetags.profanity.is_profane(name):
print("profanity detected")
return HttpResponse("profanity detected")
if profanity.templatetags.profanity.is_profane(origin):
if is_profane(name) or is_profane(origin):
print("profanity detected")
return HttpResponse("profanity detected")