antispam: sanity check

remotes/1693176582716663532/tmp_refs/heads/watchparty
justcool393 2022-11-13 21:48:52 -06:00
parent 79e6d237c1
commit 84d9ed6655
3 changed files with 20 additions and 6 deletions

View File

@ -385,6 +385,24 @@ def execute_blackjack(v, target, body, type):
return False
return True
def execute_antispam_duplicate_comment_check(v:User, body_html:str):
'''
Sanity check for newfriends
'''
if v.id in ANTISPAM_BYPASS_IDS or v.admin_level: return
if v.age >= NOTIFICATION_SPAM_AGE_THRESHOLD: return
if len(body_html) < 16: return
if body_html == '!wordle': return # wordle
compare_time = int(time.time()) - 60 * 60 * 24
comment = g.db.query(Comment.id).filter(Comment.body_html == body_html,
Comment.created_utc >= compare_time).first()
if not comment: return
v.ban(reason="Spamming.", days=0.0)
send_repeatable_notification(v.id, "Your account has been banned **permanently** for the following reason:\n\n> Too much spam!")
g.db.add(v)
g.db.commit()
abort(403, "Too much spam!")
def execute_antispam_comment_check(body:str, v:User):
if v.id in ANTISPAM_BYPASS_IDS: return
if len(body) <= COMMENT_SPAM_LENGTH_THRESHOLD: return

View File

@ -217,6 +217,7 @@ def comment(v):
or (SITE == 'pcmemes.net' and v.id == SNAPPY_ID))
execute_antispam_comment_check(body, v)
execute_antispam_duplicate_comment_check(v, body_html)
if len(body_html) > COMMENT_BODY_HTML_LENGTH_LIMIT: abort(400)

View File

@ -218,12 +218,7 @@ def submit_contact(v):
body = body.strip()
body_html = sanitize(body)
existing = g.db.query(Comment.id).filter(Comment.author_id == v.id,
Comment.parent_submission == None,
Comment.level == 1,
Comment.sentto == 2,
Comment.body_html == body_html).first()
if existing: abort(409, f"You already sent that message")
execute_antispam_duplicate_comment_check(v, body_html)
new_comment = Comment(author_id=v.id,
parent_submission=None,