Files
thisORthat/app/base_moderation.py
T
IgorVolochay 99867cef80 feat: creating FastAPI routes for working with cards
Added 3 routes:
- add_card (add a card via POST request with AddCardBody scheme)
- get_card (get a specific card by card_id)
- get_random_cards (get 10 random cards)
2025-02-25 19:11:35 +03:00

21 lines
681 B
Python

import re
from dirty_words import dirty_words_set
def is_not_empty(text: str) -> bool:
"""Checks that the text is not empty."""
return bool(text.strip())
def has_no_links(text: str) -> bool:
"""Checks that there are no links in the text."""
url_pattern = re.compile(r'https?://\S+|www\.\S+')
return not bool(url_pattern.search(text))
def has_no_dirty_words(text: str) -> bool:
"""Checks that there are no forbidden words in the text."""
words = set(re.findall(r'\w+', text.lower()))
return not bool(words & dirty_words_set)
def moderate_text(text: str) -> bool:
return is_not_empty(text) and has_no_links(text) and has_no_dirty_words(text)