refactor blackjack a bit

master
justcool393 2022-10-20 19:28:05 -05:00
parent c0fe4d03c0
commit 8fe73cb68e
6 changed files with 42 additions and 73 deletions

View File

@ -357,6 +357,33 @@ def execute_antispam_submission_check(title, v, url):
return False
return True
def execute_blackjack(v, target, body, type):
if not blackjack: return
if any(i in body.lower() for i in blackjack.split()):
v.shadowbanned = 'AutoJanny'
if not v.is_banned: v.ban_reason = f"Blackjack"
g.db.add(v)
notif = None
extra_info = None
if type == 'submission':
extra_info = f"submission ({target.permalink})"
send_repeatable_notification(CARP_ID, target.permalink)
elif type == 'comment' or type == 'message':
extra_info = f"{type} ({target.permalink})"
notif = Notification(comment_id=target.id, user_id=CARP_ID)
elif type == 'chat':
extra_info = "chat message"
elif type == 'flag':
extra_info = f"reports on {target.permalink}"
else:
extra_info = "unknown entity"
if notif:
g.db.add(notif)
g.db.flush()
elif extra_info: send_repeatable_notification(CARP_ID, f"Blackjack for {v.name}: {extra_info}")
return False
return True
def execute_antispam_comment_check(body, v):
if len(body) <= COMMENT_SPAM_LENGTH_THRESHOLD: return
now = int(time.time())
@ -391,4 +418,4 @@ def execute_antispam_comment_check(body, v):
)
g.db.add(ma)
g.db.commit()
abort(403, "Too much spam!")
abort(403, "Too much spam!")

View File

@ -6,6 +6,7 @@ from files.helpers.sanitize import sanitize
from files.helpers.const import *
from files.helpers.alerts import *
from files.helpers.regex import *
from files.helpers.actions import *
from flask_socketio import SocketIO, emit
from files.__main__ import app, limiter, cache
from flask import render_template
@ -78,14 +79,8 @@ def speak(data, v):
"time": int(time.time()),
}
if v.shadowbanned:
if v.shadowbanned or not execute_blackjack(v, None, text, "chat"):
emit('speak', data)
elif blackjack and any(i in text.lower() for i in blackjack.split()):
emit('speak', data)
v.shadowbanned = 'AutoJanny'
if not v.is_banned: v.ban_reason = 'Blackjack'
g.db.add(v)
send_repeatable_notification(CARP_ID, f"{v.username} has been shadowbanned because of a chat message.")
elif ('discord.gg' in text or 'discord.com' in text or 'discordapp.com' in text):
# Follows same logic as in users.py:message2/messagereply; TODO: unify?
emit('speak', data)

View File

@ -279,11 +279,7 @@ def comment(v):
g.db.add(c)
g.db.flush()
if blackjack and any(i in c.body.lower() for i in blackjack.split()):
v.shadowbanned = 'AutoJanny'
if not v.is_banned: v.ban_reason = 'Blackjack'
notif = Notification(comment_id=c.id, user_id=CARP_ID)
g.db.add(notif)
execute_blackjack(v, c, c.body, "comment")
if c.level == 1: c.top_comment_id = c.id
else: c.top_comment_id = parent.top_comment_id
@ -308,19 +304,13 @@ def comment(v):
execute_basedbot(c, level, body, parent_submission, parent_post, v)
if v.agendaposter and not v.marseyawarded and AGENDAPOSTER_PHRASE not in c.body.lower() and parent_post.sub != 'chudrama':
c.is_banned = True
c.ban_reason = "AutoJanny"
g.db.add(c)
body = AGENDAPOSTER_MSG.format(username=v.username, type='comment', AGENDAPOSTER_PHRASE=AGENDAPOSTER_PHRASE)
body_jannied_html = AGENDAPOSTER_MSG_HTML.format(id=v.id, username=v.username, type='comment', AGENDAPOSTER_PHRASE=AGENDAPOSTER_PHRASE)
c_jannied = Comment(author_id=AUTOJANNY_ID,
parent_submission=parent_submission,
distinguish_level=6,
@ -488,14 +478,7 @@ def edit_comment(cid, v):
c.body = body
c.body_html = body_html
if blackjack and any(i in c.body.lower() for i in blackjack.split()):
v.shadowbanned = 'AutoJanny'
if not v.is_banned: v.ban_reason = 'Blackjack'
g.db.add(v)
notif = g.db.query(Notification).filter_by(comment_id=c.id, user_id=CARP_ID).one_or_none()
if not notif:
notif = Notification(comment_id=c.id, user_id=CARP_ID)
g.db.add(notif)
execute_blackjack(v, c, c.body, "comment")
if v.agendaposter and not v.marseyawarded and AGENDAPOSTER_PHRASE not in c.body.lower() and c.post.sub != 'chudrama':
abort(403, f'You have to include "{AGENDAPOSTER_PHRASE}" in your comment!')

View File

@ -474,11 +474,8 @@ def edit_post(pid, v):
p.body = body
if blackjack and any(i in f'{p.body} {p.title} {p.url}'.lower() for i in blackjack.split()):
v.shadowbanned = 'AutoJanny'
if not v.is_banned: v.ban_reason = 'Blackjack'
g.db.add(v)
send_repeatable_notification(CARP_ID, p.permalink)
for text in [p.body, p.title, p.url]:
if not execute_blackjack(v, p, text, 'submission'): break
if len(body_html) > POST_BODY_HTML_LENGTH_LIMIT:
abort(400, f"Submission body_html too long! (max {POST_BODY_HTML_LENGTH_LIMIT} characters)")
@ -907,11 +904,8 @@ def submit_post(v, sub=None):
g.db.add(post)
g.db.flush()
if blackjack and any(i in f'{post.body} {post.title} {post.url}'.lower() for i in blackjack.split()):
v.shadowbanned = 'AutoJanny'
if not v.is_banned: v.ban_reason = 'Blackjack'
g.db.add(v)
send_repeatable_notification(CARP_ID, post.permalink)
for text in [p.body, p.title, p.url]:
if not execute_blackjack(v, p, text, 'submission'): break
for option in options:
option = SubmissionOption(

View File

@ -1,6 +1,7 @@
from files.helpers.wrappers import *
from files.helpers.get import *
from files.helpers.alerts import *
from files.helpers.actions import *
from flask import g
from files.__main__ import app, limiter
from os import path
@ -14,17 +15,10 @@ def flag_post(pid, v):
post = get_post(pid)
reason = request.values.get("reason", "").strip()
if blackjack and any(i in reason.lower() for i in blackjack.split()):
v.shadowbanned = 'AutoJanny'
if not v.is_banned: v.ban_reason = 'Blackjack'
send_repeatable_notification(CARP_ID, f"reports on {post.permalink}")
execute_blackjack(v, post, reason, 'flag')
if v.is_muted: abort(400, "You are forbidden from making reports.")
reason = reason[:100]
reason = filter_emojis_only(reason)
if len(reason) > 350: abort(400, "Too long.")
if reason.startswith('!') and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or post.sub and v.mods(post.sub)):
@ -120,14 +114,8 @@ def flag_comment(cid, v):
if existing: abort(409, "You already reported this comment!")
reason = request.values.get("reason", "").strip()
if blackjack and any(i in reason.lower() for i in blackjack.split()):
v.shadowbanned = 'AutoJanny'
if not v.is_banned: v.ban_reason = 'Blackjack'
send_repeatable_notification(CARP_ID, f"reports on {comment.permalink}")
execute_blackjack(v, comment, reason, 'flag')
reason = reason[:100]
reason = filter_emojis_only(reason)
if len(reason) > 350: abort(400, "Too long.")

View File

@ -8,6 +8,7 @@ from files.helpers.alerts import *
from files.helpers.sanitize import *
from files.helpers.const import *
from files.helpers.sorting_and_time import *
from files.helpers.actions import *
from files.mail import *
from flask import *
from files.__main__ import app, limiter, db_session
@ -542,17 +543,7 @@ def message2(v, username):
)
g.db.add(c)
g.db.flush()
if blackjack and any(i in c.body_html.lower() for i in blackjack.split()):
v.shadowbanned = 'AutoJanny'
if not v.is_banned: v.ban_reason = 'Blackjack'
g.db.add(v)
notif = g.db.query(Notification).filter_by(comment_id=c.id, user_id=CARP_ID).one_or_none()
if not notif:
notif = Notification(comment_id=c.id, user_id=CARP_ID)
g.db.add(notif)
g.db.flush()
execute_blackjack(v, c, c.body_html, 'message')
c.top_comment_id = c.id
if user.id not in bots:
@ -619,16 +610,7 @@ def messagereply(v):
)
g.db.add(c)
g.db.flush()
if blackjack and any(i in c.body_html.lower() for i in blackjack.split()):
v.shadowbanned = 'AutoJanny'
if not v.is_banned: v.ban_reason = 'Blackjack'
g.db.add(v)
notif = g.db.query(Notification).filter_by(comment_id=c.id, user_id=CARP_ID).one_or_none()
if not notif:
notif = Notification(comment_id=c.id, user_id=CARP_ID)
g.db.add(notif)
g.db.flush()
execute_blackjack(v, c, c.body_html, 'message')
if user_id and user_id not in (v.id, 2, bots):
notif = g.db.query(Notification).filter_by(comment_id=c.id, user_id=user_id).one_or_none()