First 'working' version of the word-censor
This commit is contained in:
parent
b83e0c6665
commit
3fe170f012
4 changed files with 41 additions and 24 deletions
|
@ -1,16 +1,18 @@
|
||||||
|
from os import environ
|
||||||
import re
|
import re
|
||||||
|
import time
|
||||||
from urllib.parse import urlencode, urlparse, parse_qs
|
from urllib.parse import urlencode, urlparse, parse_qs
|
||||||
|
|
||||||
from flask import *
|
from flask import *
|
||||||
from sqlalchemy import *
|
from sqlalchemy import *
|
||||||
from sqlalchemy.orm import relationship, deferred, lazyload
|
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 files.__main__ import Base
|
||||||
from .flags import CommentFlag
|
from files.classes.votes import CommentVote
|
||||||
from os import environ
|
|
||||||
import time
|
|
||||||
from files.helpers.const import AUTOPOLLER_ACCOUNT
|
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()
|
site = environ.get("DOMAIN").strip()
|
||||||
|
|
||||||
|
@ -298,8 +300,7 @@ class Comment(Base):
|
||||||
|
|
||||||
if not body: return ""
|
if not body: return ""
|
||||||
|
|
||||||
if not v or v.slurreplacer:
|
body = censor_slurs(body)
|
||||||
for s, r in SLURS.items(): body = body.replace(s, r)
|
|
||||||
|
|
||||||
if v and not v.oldreddit: body = body.replace("old.reddit.com", "reddit.com")
|
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 body: return ""
|
||||||
|
|
||||||
if not v or v.slurreplacer:
|
body = censor_slurs(body)
|
||||||
for s, r in SLURS.items(): body = body.replace(s, r)
|
|
||||||
|
|
||||||
if v and not v.oldreddit: body = body.replace("old.reddit.com", "reddit.com")
|
if v and not v.oldreddit: body = body.replace("old.reddit.com", "reddit.com")
|
||||||
|
|
||||||
|
|
|
@ -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 import *
|
||||||
from sqlalchemy.orm import relationship, deferred
|
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.__main__ import Base
|
||||||
|
from files.helpers.const import SLURS, AUTOPOLLER_ACCOUNT
|
||||||
|
from files.helpers.lazy import lazy
|
||||||
from .flags import Flag
|
from .flags import Flag
|
||||||
from os import environ
|
from ..helpers.word_censor import censor_slurs
|
||||||
import time
|
|
||||||
|
|
||||||
site = environ.get("DOMAIN").strip()
|
site = environ.get("DOMAIN").strip()
|
||||||
site_name = environ.get("SITE_NAME").strip()
|
site_name = environ.get("SITE_NAME").strip()
|
||||||
|
|
||||||
|
|
||||||
class Submission(Base):
|
class Submission(Base):
|
||||||
|
|
||||||
__tablename__ = "submissions"
|
__tablename__ = "submissions"
|
||||||
|
|
||||||
id = Column(BigInteger, primary_key=True)
|
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"
|
if self.club and not (v and v.paid_dues): return "COUNTRY CLUB ONLY"
|
||||||
body = self.body_html
|
body = self.body_html
|
||||||
|
|
||||||
if not v or v.slurreplacer:
|
body = censor_slurs(body)
|
||||||
for s,r in SLURS.items():
|
|
||||||
body = body.replace(s, r)
|
|
||||||
|
|
||||||
if v and not v.oldreddit: body = body.replace("old.reddit.com", "reddit.com")
|
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")
|
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"
|
if self.club and not (v and v.paid_dues): return "COUNTRY CLUB ONLY"
|
||||||
body = self.body
|
body = self.body
|
||||||
|
|
||||||
if not v or v.slurreplacer:
|
body = censor_slurs(body)
|
||||||
for s,r in SLURS.items():
|
|
||||||
body = body.replace(s, r)
|
|
||||||
|
|
||||||
if v and not v.oldreddit: body = body.replace("old.reddit.com", "reddit.com")
|
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")
|
if v and v.nitter: body = body.replace("www.twitter.com", "nitter.net").replace("twitter.com", "nitter.net")
|
||||||
|
|
|
@ -37,6 +37,9 @@ def sub_matcher(match: Match):
|
||||||
|
|
||||||
|
|
||||||
def censor_slurs(v, body):
|
def censor_slurs(v, body):
|
||||||
|
if v and not v.slurreplacer:
|
||||||
|
return body
|
||||||
|
|
||||||
for (slur, replace) in SLURS.items():
|
for (slur, replace) in SLURS.items():
|
||||||
for variation in create_variations_slur_regex(slur):
|
for variation in create_variations_slur_regex(slur):
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -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 a manlet hehe")).is_equal_to("LLM is a little king hehe")
|
||||||
assert_that(censor_slurs(None, "LLM is :marseycapitalistmanlet: hehe")) \
|
assert_that(censor_slurs(None, "LLM is :marseycapitalistmanlet: hehe")) \
|
||||||
.is_equal_to("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>")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue