Merge branch 'frost' of https://github.com/justcool393/themotte-rDrama into rename-truecoins-to-truescore
This commit is contained in:
commit
caa89755f8
243 changed files with 8868 additions and 8017 deletions
|
@ -1,23 +1,19 @@
|
|||
from files.helpers.wrappers import *
|
||||
from files.helpers.alerts import *
|
||||
from files.helpers.media import process_image
|
||||
from files.helpers.const import *
|
||||
from files.helpers.comments import comment_on_publish
|
||||
from files.classes import *
|
||||
from flask import *
|
||||
from files.__main__ import app, limiter
|
||||
from files.helpers.sanitize import filter_emojis_only
|
||||
import requests
|
||||
from shutil import copyfile
|
||||
from json import loads
|
||||
from collections import Counter
|
||||
from files.classes import *
|
||||
from files.classes.visstate import StateMod
|
||||
from files.helpers.alerts import *
|
||||
from files.helpers.comments import comment_on_publish
|
||||
from files.helpers.config.const import *
|
||||
from files.helpers.media import process_image
|
||||
from files.helpers.wrappers import *
|
||||
from files.routes.importstar import *
|
||||
|
||||
from datetime import datetime, timezone
|
||||
|
||||
@app.get("/comment/<cid>")
|
||||
@app.get("/post/<pid>/<anything>/<cid>")
|
||||
# @app.get("/h/<sub>/comment/<cid>")
|
||||
# @app.get("/h/<sub>/post/<pid>/<anything>/<cid>")
|
||||
@auth_desired
|
||||
def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=None):
|
||||
def post_pid_comment_cid(cid, pid=None, anything=None, v=None):
|
||||
comment = get_comment(cid, v=v)
|
||||
|
||||
if v and request.values.get("read"):
|
||||
|
@ -29,9 +25,9 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=None):
|
|||
|
||||
if comment.post and comment.post.club and not (v and (v.paid_dues or v.id in [comment.author_id, comment.post.author_id])): abort(403)
|
||||
|
||||
if comment.post and comment.post.private and not (v and (v.admin_level > 1 or v.id == comment.post.author.id)): abort(403)
|
||||
if comment.post and comment.post.private and not (v and (v.admin_level >= 2 or v.id == comment.post.author.id)): abort(403)
|
||||
|
||||
if not comment.parent_submission and not (v and (comment.author.id == v.id or comment.sentto == v.id)) and not (v and v.admin_level > 1) : abort(403)
|
||||
if not comment.parent_submission and not (v and (comment.author.id == v.id or comment.sentto == v.id)) and not (v and v.admin_level >= 2) : abort(403)
|
||||
|
||||
if not pid:
|
||||
if comment.parent_submission: pid = comment.parent_submission
|
||||
|
@ -71,7 +67,7 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=None):
|
|||
blocked.c.target_id,
|
||||
)
|
||||
|
||||
if not (v and v.shadowbanned) and not (v and v.admin_level > 2):
|
||||
if not (v and v.shadowbanned) and not (v and v.admin_level >= 3):
|
||||
comments = comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None)
|
||||
|
||||
comments=comments.filter(
|
||||
|
@ -102,9 +98,9 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=None):
|
|||
|
||||
if request.headers.get("Authorization"): return top_comment.json
|
||||
else:
|
||||
if post.is_banned and not (v and (v.admin_level > 1 or post.author_id == v.id)): template = "submission_banned.html"
|
||||
if post.state_mod != StateMod.VISIBLE and not (v and (v.admin_level >= 2 or post.author_id == v.id)): template = "submission_banned.html"
|
||||
else: template = "submission.html"
|
||||
return render_template(template, v=v, p=post, sort=sort, comment_info=comment_info, render_replies=True, sub=post.subr)
|
||||
return render_template(template, v=v, p=post, sort=sort, comment_info=comment_info, render_replies=True)
|
||||
|
||||
@app.post("/comment")
|
||||
@limiter.limit("1/second;20/minute;200/hour;1000/day")
|
||||
|
@ -115,24 +111,20 @@ def api_comment(v):
|
|||
parent_fullname = request.values.get("parent_fullname", "").strip()
|
||||
|
||||
if len(parent_fullname) < 4: abort(400)
|
||||
id = parent_fullname[3:]
|
||||
parent = None
|
||||
parent_post = None
|
||||
parent_comment_id = None
|
||||
sub = None
|
||||
|
||||
if parent_fullname.startswith("t2_"):
|
||||
parent = get_post(id, v=v)
|
||||
if parent_fullname.startswith("post_"):
|
||||
parent = get_post(parent_fullname.split("post_")[1], v=v)
|
||||
parent_post = parent
|
||||
elif parent_fullname.startswith("t3_"):
|
||||
parent = get_comment(id, v=v)
|
||||
elif parent_fullname.startswith("comment_"):
|
||||
parent = get_comment(parent_fullname.split("comment_")[1], v=v)
|
||||
parent_post = get_post(parent.parent_submission, v=v) if parent.parent_submission else None
|
||||
parent_comment_id = parent.id
|
||||
else: abort(400)
|
||||
if not parent_post: abort(404) # don't allow sending comments to the ether
|
||||
level = 1 if isinstance(parent, Submission) else parent.level + 1
|
||||
sub = parent_post.sub
|
||||
if sub and v.exiled_from(sub): abort(403, f"You're exiled from /h/{sub}")
|
||||
|
||||
body = sanitize_raw(request.values.get("body"), allow_newlines=True, length_limit=COMMENT_BODY_LENGTH_MAXIMUM)
|
||||
if not body and not request.files.get('file'):
|
||||
|
@ -158,7 +150,7 @@ def api_comment(v):
|
|||
|
||||
existing = g.db.query(Comment.id).filter(
|
||||
Comment.author_id == v.id,
|
||||
Comment.deleted_utc == 0,
|
||||
Comment.state_user_deleted_utc == None,
|
||||
Comment.parent_comment_id == parent_comment_id,
|
||||
Comment.parent_submission == parent_post.id,
|
||||
Comment.body_html == body_html
|
||||
|
@ -183,9 +175,9 @@ def api_comment(v):
|
|||
).all()
|
||||
|
||||
threshold = app.config["COMMENT_SPAM_COUNT_THRESHOLD"]
|
||||
if v.age >= (60 * 60 * 24 * 7):
|
||||
if v.age_seconds >= (60 * 60 * 24 * 7):
|
||||
threshold *= 3
|
||||
elif v.age >= (60 * 60 * 24):
|
||||
elif v.age_seconds >= (60 * 60 * 24):
|
||||
threshold *= 2
|
||||
|
||||
if len(similar_comments) > threshold:
|
||||
|
@ -196,13 +188,13 @@ def api_comment(v):
|
|||
days=1)
|
||||
|
||||
for comment in similar_comments:
|
||||
comment.is_banned = True
|
||||
comment.ban_reason = "AutoJanny"
|
||||
comment.state_mod = StateMod.REMOVED
|
||||
comment.state_mod_set_by = "AutoJanny"
|
||||
g.db.add(comment)
|
||||
ma=ModAction(
|
||||
user_id=AUTOJANNY_ID,
|
||||
target_comment_id=comment.id,
|
||||
kind="ban_comment",
|
||||
kind="remove_comment",
|
||||
_note="spam"
|
||||
)
|
||||
g.db.add(ma)
|
||||
|
@ -221,7 +213,7 @@ def api_comment(v):
|
|||
body_html=body_html,
|
||||
body=body[:COMMENT_BODY_LENGTH_MAXIMUM],
|
||||
ghost=parent_post.ghost,
|
||||
filter_state='filtered' if is_filtered else 'normal'
|
||||
state_mod=StateMod.FILTERED if is_filtered else StateMod.VISIBLE,
|
||||
)
|
||||
|
||||
c.upvotes = 1
|
||||
|
@ -280,11 +272,11 @@ def edit_comment(cid, v):
|
|||
).all()
|
||||
|
||||
threshold = app.config["SPAM_SIMILAR_COUNT_THRESHOLD"]
|
||||
if v.age >= (60 * 60 * 24 * 30):
|
||||
if v.age_seconds >= (60 * 60 * 24 * 30):
|
||||
threshold *= 4
|
||||
elif v.age >= (60 * 60 * 24 * 7):
|
||||
elif v.age_seconds >= (60 * 60 * 24 * 7):
|
||||
threshold *= 3
|
||||
elif v.age >= (60 * 60 * 24):
|
||||
elif v.age_seconds >= (60 * 60 * 24):
|
||||
threshold *= 2
|
||||
|
||||
if len(similar_comments) > threshold:
|
||||
|
@ -295,8 +287,8 @@ def edit_comment(cid, v):
|
|||
days=1)
|
||||
|
||||
for comment in similar_comments:
|
||||
comment.is_banned = True
|
||||
comment.ban_reason = "AutoJanny"
|
||||
comment.state_mod = StateMod.REMOVED
|
||||
comment.state_mod_set_by = "AutoJanny"
|
||||
g.db.add(comment)
|
||||
|
||||
abort(403, "Too much spam!")
|
||||
|
@ -321,7 +313,7 @@ def edit_comment(cid, v):
|
|||
|
||||
g.db.add(c)
|
||||
|
||||
if c.filter_state != 'filtered':
|
||||
if c.state_mod == StateMod.VISIBLE:
|
||||
notify_users = NOTIFY_USERS(body, v)
|
||||
|
||||
for x in notify_users:
|
||||
|
@ -340,17 +332,13 @@ def edit_comment(cid, v):
|
|||
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
||||
@auth_required
|
||||
def delete_comment(cid, v):
|
||||
|
||||
c = get_comment(cid, v=v)
|
||||
|
||||
if not c.deleted_utc:
|
||||
|
||||
if c.author_id != v.id: abort(403)
|
||||
|
||||
c.deleted_utc = int(time.time())
|
||||
|
||||
g.db.add(c)
|
||||
g.db.commit()
|
||||
if c.state_user_deleted_utc: abort(409)
|
||||
if c.author_id != v.id: abort(403)
|
||||
c.state_user_deleted_utc = datetime.now(tz=timezone.utc)
|
||||
# TODO: update stateful counters
|
||||
g.db.add(c)
|
||||
g.db.commit()
|
||||
|
||||
return {"message": "Comment deleted!"}
|
||||
|
||||
|
@ -358,16 +346,13 @@ def delete_comment(cid, v):
|
|||
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
||||
@auth_required
|
||||
def undelete_comment(cid, v):
|
||||
|
||||
c = get_comment(cid, v=v)
|
||||
|
||||
if c.deleted_utc:
|
||||
if c.author_id != v.id: abort(403)
|
||||
|
||||
c.deleted_utc = 0
|
||||
|
||||
g.db.add(c)
|
||||
g.db.commit()
|
||||
if not c.state_user_deleted_utc: abort(409)
|
||||
if c.author_id != v.id: abort(403)
|
||||
c.state_user_deleted_utc = None
|
||||
# TODO: update stateful counters
|
||||
g.db.add(c)
|
||||
g.db.commit()
|
||||
|
||||
return {"message": "Comment undeleted!"}
|
||||
|
||||
|
@ -375,7 +360,6 @@ def undelete_comment(cid, v):
|
|||
@app.post("/pin_comment/<cid>")
|
||||
@auth_required
|
||||
def pin_comment(cid, v):
|
||||
|
||||
comment = get_comment(cid, v=v)
|
||||
|
||||
if not comment.is_pinned:
|
||||
|
@ -417,51 +401,10 @@ def unpin_comment(cid, v):
|
|||
return {"message": "Comment unpinned!"}
|
||||
|
||||
|
||||
@app.post("/mod_pin/<cid>")
|
||||
@auth_required
|
||||
def mod_pin(cid, v):
|
||||
|
||||
comment = get_comment(cid, v=v)
|
||||
|
||||
if not comment.is_pinned:
|
||||
if not (comment.post.sub and v.mods(comment.post.sub)): abort(403)
|
||||
|
||||
comment.is_pinned = v.username + " (Mod)"
|
||||
|
||||
g.db.add(comment)
|
||||
|
||||
if v.id != comment.author_id:
|
||||
message = f"@{v.username} (Mod) has pinned your [comment]({comment.shortlink})!"
|
||||
send_repeatable_notification(comment.author_id, message)
|
||||
|
||||
g.db.commit()
|
||||
return {"message": "Comment pinned!"}
|
||||
|
||||
|
||||
@app.post("/unmod_pin/<cid>")
|
||||
@auth_required
|
||||
def mod_unpin(cid, v):
|
||||
|
||||
comment = get_comment(cid, v=v)
|
||||
|
||||
if comment.is_pinned:
|
||||
if not (comment.post.sub and v.mods(comment.post.sub)): abort(403)
|
||||
|
||||
comment.is_pinned = None
|
||||
g.db.add(comment)
|
||||
|
||||
if v.id != comment.author_id:
|
||||
message = f"@{v.username} (Mod) has unpinned your [comment]({comment.shortlink})!"
|
||||
send_repeatable_notification(comment.author_id, message)
|
||||
g.db.commit()
|
||||
return {"message": "Comment unpinned!"}
|
||||
|
||||
|
||||
@app.post("/save_comment/<cid>")
|
||||
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
||||
@auth_required
|
||||
def save_comment(cid, v):
|
||||
|
||||
comment=get_comment(cid)
|
||||
|
||||
save=g.db.query(CommentSaveRelationship).filter_by(user_id=v.id, comment_id=comment.id).one_or_none()
|
||||
|
@ -478,7 +421,6 @@ def save_comment(cid, v):
|
|||
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
||||
@auth_required
|
||||
def unsave_comment(cid, v):
|
||||
|
||||
comment=get_comment(cid)
|
||||
|
||||
save=g.db.query(CommentSaveRelationship).filter_by(user_id=v.id, comment_id=comment.id).one_or_none()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue