First 'working' version of the word-censor

remotes/1693045480750635534/spooky-22
Yo Mama 2021-10-16 20:06:21 +02:00
parent 7e1e9ccc5b
commit 5f7824b6c7
4 changed files with 41 additions and 24 deletions

View File

@ -1,16 +1,18 @@
from os import environ
import re
import time
from urllib.parse import urlencode, urlparse, parse_qs
from flask import *
from sqlalchemy import *
from sqlalchemy.orm import relationship, deferred, lazyload
from files.classes.votes import CommentVote
from files.helpers.lazy import lazy
from files.helpers.const import SLURS
from files.__main__ import Base
from .flags import CommentFlag
from os import environ
import time
from files.classes.votes import CommentVote
from files.helpers.const import AUTOPOLLER_ACCOUNT
from files.helpers.lazy import lazy
from .flags import CommentFlag
from ..helpers.word_censor import censor_slurs
site = environ.get("DOMAIN").strip()
@ -298,8 +300,7 @@ class Comment(Base):
if not body: return ""
if not v or v.slurreplacer:
for s, r in SLURS.items(): body = body.replace(s, r)
body = censor_slurs(body)
if v and not v.oldreddit: body = body.replace("old.reddit.com", "reddit.com")
@ -325,8 +326,7 @@ class Comment(Base):
if not body: return ""
if not v or v.slurreplacer:
for s, r in SLURS.items(): body = body.replace(s, r)
body = censor_slurs(body)
if v and not v.oldreddit: body = body.replace("old.reddit.com", "reddit.com")

View File

@ -1,21 +1,24 @@
from flask import render_template, g
from os import environ
import random
import re
import time
from urllib.parse import urlparse
from flask import render_template
from sqlalchemy import *
from sqlalchemy.orm import relationship, deferred
import re, random
from urllib.parse import urlparse
from files.helpers.lazy import lazy
from files.helpers.const import SLURS, AUTOPOLLER_ACCOUNT
from files.__main__ import Base
from files.helpers.const import SLURS, AUTOPOLLER_ACCOUNT
from files.helpers.lazy import lazy
from .flags import Flag
from os import environ
import time
from ..helpers.word_censor import censor_slurs
site = environ.get("DOMAIN").strip()
site_name = environ.get("SITE_NAME").strip()
class Submission(Base):
__tablename__ = "submissions"
id = Column(BigInteger, primary_key=True)
@ -339,9 +342,7 @@ class Submission(Base):
if self.club and not (v and v.paid_dues): return "COUNTRY CLUB ONLY"
body = self.body_html
if not v or v.slurreplacer:
for s,r in SLURS.items():
body = body.replace(s, r)
body = censor_slurs(body)
if v and not v.oldreddit: body = body.replace("old.reddit.com", "reddit.com")
if v and v.nitter: body = body.replace("www.twitter.com", "nitter.net").replace("twitter.com", "nitter.net")
@ -351,9 +352,7 @@ class Submission(Base):
if self.club and not (v and v.paid_dues): return "COUNTRY CLUB ONLY"
body = self.body
if not v or v.slurreplacer:
for s,r in SLURS.items():
body = body.replace(s, r)
body = censor_slurs(body)
if v and not v.oldreddit: body = body.replace("old.reddit.com", "reddit.com")
if v and v.nitter: body = body.replace("www.twitter.com", "nitter.net").replace("twitter.com", "nitter.net")

View File

@ -37,6 +37,9 @@ def sub_matcher(match: Match):
def censor_slurs(v, body):
if v and not v.slurreplacer:
return body
for (slur, replace) in SLURS.items():
for variation in create_variations_slur_regex(slur):
try:

View File

@ -74,3 +74,18 @@ def test_censor_slurs():
assert_that(censor_slurs(None, "LLM is a manlet hehe")).is_equal_to("LLM is a little king hehe")
assert_that(censor_slurs(None, "LLM is :marseycapitalistmanlet: hehe")) \
.is_equal_to("LLM is :marseycapitalistmanlet: hehe")
@patch("files.helpers.word_censor.SLURS", {'retard': 'r-slur', 'manlet': 'little king'})
def test_censor_slurs_does_not_censor_on_flag_disabled():
word_censor.REPLACE_MAP = create_replace_map()
class V:
def __init__(self, slurreplacer):
self.slurreplacer = slurreplacer
v = V(False)
assert_that(censor_slurs(v, "<p>retard</p>")).is_equal_to("<p>retard</p>")
v = V(True)
assert_that(censor_slurs(v, "<p>retard</p>")).is_equal_to("<p>r-slur</p>")