forked from rDrama/rDrama
Merge branch 'frost' of https://github.com/Aevann1/rDrama into frost
commit
ab6aaf5787
|
@ -311,3 +311,83 @@ def execute_basedbot(c, level, body, parent_submission, parent_post, v):
|
|||
|
||||
n = Notification(comment_id=c_based.id, user_id=v.id)
|
||||
g.db.add(n)
|
||||
|
||||
def execute_antispam_submission_check(title, v, url):
|
||||
now = int(time.time())
|
||||
cutoff = now - 60 * 60 * 24
|
||||
|
||||
similar_posts = g.db.query(Submission).filter(
|
||||
Submission.author_id == v.id,
|
||||
Submission.title.op('<->')(title) < SPAM_SIMILARITY_THRESHOLD,
|
||||
Submission.created_utc > cutoff
|
||||
).all()
|
||||
|
||||
if url:
|
||||
similar_urls = g.db.query(Submission).filter(
|
||||
Submission.author_id == v.id,
|
||||
Submission.url.op('<->')(url) < SPAM_URL_SIMILARITY_THRESHOLD,
|
||||
Submission.created_utc > cutoff
|
||||
).all()
|
||||
else: similar_urls = []
|
||||
|
||||
threshold = SPAM_SIMILAR_COUNT_THRESHOLD
|
||||
if v.age >= (60 * 60 * 24 * 7): threshold *= 3
|
||||
elif v.age >= (60 * 60 * 24): threshold *= 2
|
||||
|
||||
if max(len(similar_urls), len(similar_posts)) >= threshold:
|
||||
text = "Your account has been banned for **1 day** for the following reason:\n\n> Too much spam!"
|
||||
send_repeatable_notification(v.id, text)
|
||||
|
||||
v.ban(reason="Spamming.",
|
||||
days=1)
|
||||
|
||||
for post in similar_posts + similar_urls:
|
||||
post.is_banned = True
|
||||
post.is_pinned = False
|
||||
post.ban_reason = "AutoJanny"
|
||||
g.db.add(post)
|
||||
ma=ModAction(
|
||||
user_id=AUTOJANNY_ID,
|
||||
target_submission_id=post.id,
|
||||
kind="ban_post",
|
||||
_note="spam"
|
||||
)
|
||||
g.db.add(ma)
|
||||
return False
|
||||
return True
|
||||
|
||||
def execute_antispam_comment_check(body, v):
|
||||
if len(body) <= COMMENT_SPAM_LENGTH_THRESHOLD: return
|
||||
now = int(time.time())
|
||||
cutoff = now - 60 * 60 * 24
|
||||
|
||||
similar_comments = g.db.query(Comment).filter(
|
||||
Comment.author_id == v.id,
|
||||
Comment.body.op('<->')(body) < COMMENT_SPAM_SIMILAR_THRESHOLD,
|
||||
Comment.created_utc > cutoff
|
||||
).all()
|
||||
|
||||
threshold = COMMENT_SPAM_COUNT_THRESHOLD
|
||||
if v.age >= (60 * 60 * 24 * 7):
|
||||
threshold *= 3
|
||||
elif v.age >= (60 * 60 * 24):
|
||||
threshold *= 2
|
||||
|
||||
if len(similar_comments) <= threshold: return
|
||||
text = "Your account has been banned for **1 day** for the following reason:\n\n> Too much spam!"
|
||||
send_repeatable_notification(v.id, text)
|
||||
v.ban(reason="Spamming.",
|
||||
days=1)
|
||||
for comment in similar_comments:
|
||||
comment.is_banned = True
|
||||
comment.ban_reason = "AutoJanny"
|
||||
g.db.add(comment)
|
||||
ma=ModAction(
|
||||
user_id=AUTOJANNY_ID,
|
||||
target_comment_id=comment.id,
|
||||
kind="ban_comment",
|
||||
_note="spam"
|
||||
)
|
||||
g.db.add(ma)
|
||||
g.db.commit()
|
||||
abort(403, "Too much spam!")
|
|
@ -341,6 +341,7 @@ TRANSFER_MESSAGE_LENGTH_LIMIT = 200 # do not make larger than 10000 characters (
|
|||
LOGGEDIN_ACTIVE_TIME = 15 * 60
|
||||
PFP_DEFAULT_MARSEY = True
|
||||
NOTIFICATION_SPAM_AGE_THRESHOLD = 0.5 * 86400
|
||||
COMMENT_SPAM_LENGTH_THRESHOLD = 50
|
||||
|
||||
HOLE_NAME = 'hole'
|
||||
HOLE_STYLE_FLAIR = False
|
||||
|
|
|
@ -260,43 +260,7 @@ def comment(v):
|
|||
|
||||
is_bot = v.id != BBBB_ID and (bool(request.headers.get("Authorization")) or (SITE == 'pcmemes.net' and v.id == SNAPPY_ID))
|
||||
|
||||
if len(body) > 50:
|
||||
now = int(time.time())
|
||||
cutoff = now - 60 * 60 * 24
|
||||
|
||||
similar_comments = g.db.query(Comment).filter(
|
||||
Comment.author_id == v.id,
|
||||
Comment.body.op('<->')(body) < COMMENT_SPAM_SIMILAR_THRESHOLD,
|
||||
Comment.created_utc > cutoff
|
||||
).all()
|
||||
|
||||
threshold = COMMENT_SPAM_COUNT_THRESHOLD
|
||||
if v.age >= (60 * 60 * 24 * 7):
|
||||
threshold *= 3
|
||||
elif v.age >= (60 * 60 * 24):
|
||||
threshold *= 2
|
||||
|
||||
if len(similar_comments) > threshold:
|
||||
text = "Your account has been banned for **1 day** for the following reason:\n\n> Too much spam!"
|
||||
send_repeatable_notification(v.id, text)
|
||||
|
||||
v.ban(reason="Spamming.",
|
||||
days=1)
|
||||
|
||||
for comment in similar_comments:
|
||||
comment.is_banned = True
|
||||
comment.ban_reason = "AutoJanny"
|
||||
g.db.add(comment)
|
||||
ma=ModAction(
|
||||
user_id=AUTOJANNY_ID,
|
||||
target_comment_id=comment.id,
|
||||
kind="ban_comment",
|
||||
_note="spam"
|
||||
)
|
||||
g.db.add(ma)
|
||||
|
||||
g.db.commit()
|
||||
abort(403, "Too much spam!")
|
||||
execute_antispam_comment_check(body, v)
|
||||
|
||||
if len(body_html) > COMMENT_BODY_HTML_LENGTH_LIMIT: abort(400)
|
||||
|
||||
|
@ -502,39 +466,7 @@ def edit_comment(cid, v):
|
|||
)
|
||||
g.db.add(option)
|
||||
|
||||
if len(body) > 50:
|
||||
now = int(time.time())
|
||||
cutoff = now - 60 * 60 * 24
|
||||
|
||||
similar_comments = g.db.query(Comment
|
||||
).filter(
|
||||
Comment.author_id == v.id,
|
||||
Comment.body.op('<->')(body) < SPAM_SIMILARITY_THRESHOLD,
|
||||
Comment.created_utc > cutoff
|
||||
).all()
|
||||
|
||||
threshold = SPAM_SIMILAR_COUNT_THRESHOLD
|
||||
if v.age >= (60 * 60 * 24 * 30):
|
||||
threshold *= 4
|
||||
elif v.age >= (60 * 60 * 24 * 7):
|
||||
threshold *= 3
|
||||
elif v.age >= (60 * 60 * 24):
|
||||
threshold *= 2
|
||||
|
||||
if len(similar_comments) > threshold:
|
||||
text = "Your account has been banned for **1 day** for the following reason:\n\n> Too much spam!"
|
||||
send_repeatable_notification(v.id, text)
|
||||
|
||||
v.ban(reason="Spamming.",
|
||||
days=1)
|
||||
|
||||
for comment in similar_comments:
|
||||
comment.is_banned = True
|
||||
comment.ban_reason = "AutoJanny"
|
||||
g.db.add(comment)
|
||||
|
||||
g.db.commit()
|
||||
abort(403, "Too much spam!")
|
||||
execute_antispam_comment_check(body, v)
|
||||
|
||||
body += process_files()
|
||||
body = body.strip()[:COMMENT_BODY_LENGTH_LIMIT] # process_files potentially adds characters to the post
|
||||
|
|
|
@ -832,48 +832,7 @@ def submit_post(v, sub=None):
|
|||
|
||||
if dup and SITE != 'localhost': return redirect(dup.permalink)
|
||||
|
||||
now = int(time.time())
|
||||
cutoff = now - 60 * 60 * 24
|
||||
|
||||
|
||||
similar_posts = g.db.query(Submission).filter(
|
||||
Submission.author_id == v.id,
|
||||
Submission.title.op('<->')(title) < SPAM_SIMILARITY_THRESHOLD,
|
||||
Submission.created_utc > cutoff
|
||||
).all()
|
||||
|
||||
if url:
|
||||
similar_urls = g.db.query(Submission).filter(
|
||||
Submission.author_id == v.id,
|
||||
Submission.url.op('<->')(url) < SPAM_URL_SIMILARITY_THRESHOLD,
|
||||
Submission.created_utc > cutoff
|
||||
).all()
|
||||
else: similar_urls = []
|
||||
|
||||
threshold = SPAM_SIMILAR_COUNT_THRESHOLD
|
||||
if v.age >= (60 * 60 * 24 * 7): threshold *= 3
|
||||
elif v.age >= (60 * 60 * 24): threshold *= 2
|
||||
|
||||
if max(len(similar_urls), len(similar_posts)) >= threshold:
|
||||
|
||||
text = "Your account has been banned for **1 day** for the following reason:\n\n> Too much spam!"
|
||||
send_repeatable_notification(v.id, text)
|
||||
|
||||
v.ban(reason="Spamming.",
|
||||
days=1)
|
||||
|
||||
for post in similar_posts + similar_urls:
|
||||
post.is_banned = True
|
||||
post.is_pinned = False
|
||||
post.ban_reason = "AutoJanny"
|
||||
g.db.add(post)
|
||||
ma=ModAction(
|
||||
user_id=AUTOJANNY_ID,
|
||||
target_submission_id=post.id,
|
||||
kind="ban_post",
|
||||
_note="spam"
|
||||
)
|
||||
g.db.add(ma)
|
||||
if not execute_antispam_submission_check(title, v, url):
|
||||
return redirect("/notifications")
|
||||
|
||||
if len(url) > 2048:
|
||||
|
|
|
@ -125,7 +125,10 @@ def vote_post_comment(target_id, new, v, cls, vote_cls):
|
|||
votes = votes.filter_by(vote_type=dir)
|
||||
if real_instead_of_dir:
|
||||
votes = votes.filter_by(real=True)
|
||||
elif vote_cls == Vote:
|
||||
else:
|
||||
votes = votes.filter_by(vote_type=dir)
|
||||
|
||||
if vote_cls == Vote:
|
||||
votes = votes.filter_by(submission_id=target.id)
|
||||
elif vote_cls == CommentVote:
|
||||
votes = votes.filter_by(comment_id=target.id)
|
||||
|
|
Loading…
Reference in New Issue