Skip to content

Commit

Permalink
Don't punish users when no profanity gets detected
Browse files Browse the repository at this point in the history
The automatic profanity detection in ModBot contained a bug, which
resulted in a false-positive profanity detection for every text in
that language, if the detected language didn't have any profanity terms
configured. This commit fixes that, by returning when no profanity terms
for the detected language are configured.
  • Loading branch information
Dunedan committed Oct 25, 2024
1 parent 0223ec0 commit 8f5bf22
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions xpartamupp/modbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,9 @@ async def _muc_check_profanity(self, msg: Message) -> None:
select(ProfanityTerms.term).filter(ProfanityTerms.language.in_(languages))
).scalars()
)
if not profanity_terms:
return

offending_terms = re.findall(
r"(?:^|(?<= ))(" + "|".join(profanity_terms) + r")(?= |$)",
" ".join(tokens_lemmatized),
Expand Down

0 comments on commit 8f5bf22

Please sign in to comment.