remotes/1693045480750635534/spooky-22
Aevann1 2021-07-31 07:59:25 +02:00
parent 8f60626ede
commit 66d9c36105
7 changed files with 122 additions and 204 deletions

View File

@ -78,26 +78,16 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None):
for i in range(6 - context):
if v:
votes = g.db.query(CommentVote).filter(
CommentVote.user_id == v.id).subquery()
blocking = v.blocking.subquery()
blocked = v.blocked.subquery()
comms = g.db.query(
Comment,
votes.c.vote_type,
blocking.c.id,
blocked.c.id,
aliased(ModAction, alias=exile)
).filter(
Comment.parent_comment_id.in_(current_ids)
).join(
votes,
votes.c.comment_id == Comment.id,
isouter=True
).join(
blocking,
blocking.c.target_id == Comment.author_id,
@ -106,10 +96,6 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None):
blocked,
blocked.c.user_id == Comment.author_id,
isouter=True
).join(
exile,
exile.c.target_comment_id==Comment.id,
isouter=True
)
if sort == "top":
@ -129,47 +115,35 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None):
abort(422)
output = []
for c in comms:
for c in comments:
comment = c[0]
comment._voted = c[1] or 0
comment._is_blocking = c[2] or 0
comment._is_blocked = c[3] or 0
comment._is_exiled_for=c[4] or 0
comment._is_blocking = c[1] or 0
comment._is_blocked = c[2] or 0
output.append(comment)
else:
comms = g.db.query(
Comment,
aliased(ModAction, alias=exile)
Comment
).filter(
Comment.parent_comment_id.in_(current_ids)
).join(
exile,
exile.c.target_comment_id==Comment.id,
isouter=True
)
if sort == "top":
comments = comms.order_by(Comment.score.asc()).all()
output = comms.order_by(Comment.score.asc()).all()
elif sort == "bottom":
comments = comms.order_by(Comment.score.desc()).all()
output = comms.order_by(Comment.score.desc()).all()
elif sort == "new":
comments = comms.order_by(Comment.created_utc.desc()).all()
output = comms.order_by(Comment.created_utc.desc()).all()
elif sort == "old":
comments = comms.order_by(Comment.created_utc.asc()).all()
output = comms.order_by(Comment.created_utc.asc()).all()
elif sort == "controversial":
comments = sorted(comms.all(), key=lambda x: x[0].score_disputed, reverse=True)
output = sorted(comms.all(), key=lambda x: x[0].score_disputed, reverse=True)
elif sort == "random":
c = comms.all()
comments = random.sample(c, k=len(c))
output = random.sample(c, k=len(c))
else:
abort(422)
output = []
for c in comms:
comment=c[0]
comment._is_exiled_for=c[1] or 0
output.append(comment)
post._preloaded_comments += output
@ -180,9 +154,9 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None):
post.replies=[top_comment]
return {'html': lambda: post.rendered_page(v=v, sort=sort, comment=top_comment, comment_info=comment_info),
'api': lambda: top_comment.json
}
if request.headers.get("Authorization"): return top_comment.json
else: return post.rendered_page(v=v, sort=sort, comment=top_comment, comment_info=comment_info)
@app.post("/comment")
@limiter.limit("6/minute")
@ -573,7 +547,7 @@ def api_comment(v):
v.comment_count = v.comments.filter(Comment.parent_submission != None).filter_by(is_banned=False, deleted_utc=0).count()
g.db.add(v)
if request.headers.get("Authorization"): return "sex"
if request.headers.get("Authorization"): return c.json
else: return render_template("comments.html", v=v, comments=[c], render_replies=False)
@ -610,16 +584,14 @@ def edit_comment(cid, v):
if ban.reason:
reason += f" {ban.reason_text}"
return {'html': lambda: render_template("comment_failed.html",
if request.headers.get("Authorization"): return {'error': f'A blacklisted domain was used.'}, 400
else: return render_template("comment_failed.html",
action=f"/edit_comment/{c.id}",
badlinks=[
x.domain for x in bans],
body=body,
v=v
),
'api': lambda: ({'error': f'A blacklisted domain was used.'}, 400)
}
)
# check badlinks
soup = BeautifulSoup(body_html, features="html.parser")
links = [x['href'] for x in soup.find_all('a') if x.get('href')]

View File

@ -14,10 +14,8 @@ from drama.__main__ import app
@app.errorhandler(400)
@auth_desired
def error_400(e, v):
return{"html": lambda: (render_template('errors/400.html', v=v), 400),
"api": lambda: ({"error": "400 Bad Request"}, 400 )
}
if request.headers.get("Authorization"): return {"error": "400 Bad Request"}, 400
else: return render_template('errors/400.html', v=v), 400
@app.errorhandler(401)
def error_401(e):
@ -34,79 +32,71 @@ def error_401(e):
@app.errorhandler(403)
@auth_desired
def error_403(e, v):
return{"html": lambda: (render_template('errors/403.html', v=v), 403),
"api": lambda: ({"error": "403 Forbidden"}, 403)
}
if request.headers.get("Authorization"): return {"error": "403 Forbidden"}, 403
else: return render_template('errors/403.html', v=v), 403
@app.errorhandler(404)
@auth_desired
def error_404(e, v):
return{"html": lambda: (render_template('errors/404.html', v=v), 404),
"api": lambda: ({"error": "404 Not Found"}, 404)
}
if request.headers.get("Authorization"): return {"error": "404 Not Found"}, 404
else: return render_template('errors/404.html', v=v), 404
@app.errorhandler(405)
@auth_desired
def error_405(e, v):
return{"html": lambda: (render_template('errors/405.html', v=v), 405),
"api": lambda: ({"error": "405 Method Not Allowed"}, 405)
}
if request.headers.get("Authorization"): return {"error": "405 Method Not Allowed"}, 405
else: return render_template('errors/405.html', v=v), 405
@app.errorhandler(409)
@auth_desired
def error_409(e, v):
return{"html": lambda: (render_template('errors/409.html', v=v), 409),
"api": lambda: ({"error": "409 Conflict"}, 409)
}
if request.headers.get("Authorization"): return {"error": "409 Conflict"}, 409
else: return render_template('errors/409.html', v=v), 409
@app.errorhandler(410)
@auth_desired
def error_410(e, v):
return{"html": lambda: (render_template('errors/410.html', v=v), 410),
"api": lambda: ({"error": "410 Request Payload Too Large"}, 410)
}
if request.headers.get("Authorization"): return {"error": "410 Request Payload Too Large"}, 410
else: return render_template('errors/410.html', v=v), 410
@app.errorhandler(413)
@auth_desired
def error_413(e, v):
return{"html": lambda: (render_template('errors/413.html', v=v), 413),
"api": lambda: ({"error": "413 Image Size Too Large"}, 413)
}
if request.headers.get("Authorization"): return {"error": "413 Image Size Too Large"}, 413
else: return render_template('errors/413.html', v=v), 413
@app.errorhandler(418)
@auth_desired
def error_418(e, v):
return{"html": lambda: (render_template('errors/418.html', v=v), 418),
"api": lambda: ({"error": "418 I'm A Teapot"}, 418)
}
if request.headers.get("Authorization"): return {"error": "418 I'm A Teapot"}, 418
else: return render_template('errors/418.html', v=v), 418
@app.errorhandler(422)
@auth_desired
def error_422(e, v):
return{"html": lambda: (render_template('errors/422.html', v=v), 422),
"api": lambda: ({"error": "422 Unprocessable Entity"}, 422)
}
if request.headers.get("Authorization"): return {"error": "422 Unprocessable Entity"}, 422
else: return render_template('errors/422.html', v=v), 422
@app.errorhandler(429)
@auth_desired
def error_429(e, v):
return{"html": lambda: (render_template('errors/429.html', v=v), 429),
"api": lambda: ({"error": "429 Too Many Requests"}, 429)
}
if request.headers.get("Authorization"): return {"error": "429 Too Many Requests"}, 429
else: return render_template('errors/429.html', v=v), 429
@app.errorhandler(451)
@auth_desired
def error_451(e, v):
return{"html": lambda: (render_template('errors/451.html', v=v), 451),
"api": lambda: ({"error": "451 Unavailable For Legal Reasons"}, 451)
}
if request.headers.get("Authorization"): return {"error": "451 Unavailable For Legal Reasons"}, 451
else: return render_template('errors/451.html', v=v), 451
@app.errorhandler(500)
@ -117,25 +107,23 @@ def error_500(e, v):
except AttributeError:
pass
return{"html": lambda: (render_template('errors/500.html', v=v), 500),
"api": lambda: ({"error": "500 Internal Server Error"}, 500)
}
if request.headers.get("Authorization"): return {"error": "500 Internal Server Error"}, 500
else: return render_template('errors/500.html', v=v), 500
@app.errorhandler(502)
@auth_desired
def error_502(e, v):
return{"html": lambda: (render_template('errors/502.html', v=v), 502),
"api": lambda: ({"error": "502 Bad Gateway"}, 502)
}
if request.headers.get("Authorization"): return {"error": "502 Bad Gateway"}, 502
else: return render_template('errors/502.html', v=v), 502
@app.errorhandler(503)
@auth_desired
def error_503(e, v):
return{"html": lambda: (render_template('errors/503.html', v=v), 503),
"api": lambda: ({"error": "503 Service Unavailable"}, 503)
}
if request.headers.get("Authorization"): return {"error": "503 Service Unavailable"}, 503
else: return render_template('errors/503.html', v=v), 503
@app.post("/allow_nsfw")

View File

@ -208,10 +208,9 @@ def post_id(pid, anything=None, v=None):
post.tree_comments()
return {
"html":lambda:post.rendered_page(v=v, sort=sort),
"api":lambda:post.json
}
if request.headers.get("Authorization"): return post.json
else: return post.rendered_page(v=v, sort=sort)
@app.post("/edit_post/<pid>")
@is_not_banned
@ -964,15 +963,6 @@ def undelete_post_pid(pid, v):
return "", 204
@app.get("/embed/post/<pid>")
def embed_post_pid(pid):
post = get_post(int(pid))
if post.is_banned:
abort(410)
return render_template("embeds/submission.html", p=post)
@app.post("/toggle_comment_nsfw/<cid>")
@is_not_banned

View File

@ -14,10 +14,8 @@ def patrons(v):
@auth_desired
def badmins(v):
badmins = g.db.query(User).filter_by(admin_level=6).order_by(User.dramacoins.desc()).all()
return {
"html":lambda:render_template("badmins.html", v=v, badmins=badmins),
"api":lambda:{"data":[x.json for x in badmins]}
}
render_template("badmins.html", v=v, badmins=badmins)
@app.get("/log")
@auth_desired
@ -31,16 +29,7 @@ def log(v):
next_exists=len(actions)==26
actions=actions[:25]
return {
"html":lambda:render_template(
"modlog.html",
v=v,
actions=actions,
next_exists=next_exists,
page=page
),
"api":lambda:{"data":[x.json for x in actions]}
}
return render_template("log.html", v=v, actions=actions, next_exists=next_exists, page=page)
@app.get("/log/<id>")
@auth_desired
@ -57,7 +46,7 @@ def log_item(id, v):
if request.path != action.permalink:
return redirect(action.permalink)
return render_template("modlog.html",
return render_template("log.html",
v=v,
actions=[action],
next_exists=False,

View File

@ -249,11 +249,11 @@ def u_username(username, v=None):
return redirect(request.path.replace(username, u.username))
if u.reserved:
return {'html': lambda: render_template("userpage_reserved.html",
u=u,
v=v),
'api': lambda: {"error": f"That username is reserved for: {u.reserved}"}
if request.headers.get("Authorization"): return {"error": f"That username is reserved for: {u.reserved}"}
}
else: return render_template("userpage_reserved.html",
u=u,
v=v)
# viewers
if v and u.id != v.id:
@ -275,38 +275,33 @@ def u_username(username, v=None):
if u.is_private and (not v or (v.id != u.id and v.admin_level < 3)):
paidrent = False
if v and u.id == 253:
if int(time.time()) - v.rent_utc < 600: paidrent = True
elif request.args.get("rent") == "true" and v.dramacoins > 500:
v.dramacoins -= 500
v.rent_utc = int(time.time())
g.db.add(v)
u.dramacoins += 500
g.db.add(u)
send_notification(1046, u, f"@{v.username} has paid rent!")
paidrent = True
# paidrent = False
# if v and u.id == 253:
# if int(time.time()) - v.rent_utc < 600: paidrent = True
# elif request.args.get("rent") == "true" and v.dramacoins > 500:
# v.dramacoins -= 500
# v.rent_utc = int(time.time())
# g.db.add(v)
# u.dramacoins += 500
# g.db.add(u)
# send_notification(1046, u, f"@{v.username} has paid rent!")
# paidrent = True
# if not paidrent:
if request.headers.get("Authorization"): return {"error": "That userpage is private"}
else: return render_template("userpage_private.html", u=u, v=v)
if not paidrent:
return {'html': lambda: render_template("userpage_private.html",
u=u,
v=v),
'api': lambda: {"error": "That userpage is private"}
}
if u.is_blocking and (not v or v.admin_level < 3):
return {'html': lambda: render_template("userpage_blocking.html",
u=u,
v=v),
'api': lambda: {"error": f"You are blocking @{u.username}."}
}
if request.headers.get("Authorization"): return {"error": f"You are blocking @{u.username}."}
else: return render_template("userpage_blocking.html", u=u, v=v)
if u.is_blocked and (not v or v.admin_level < 3):
return {'html': lambda: render_template("userpage_blocked.html",
u=u,
v=v),
'api': lambda: {"error": "This person is blocking you."}
}
if request.headers.get("Authorization"): return {"error": "This person is blocking you."}
else: return render_template("userpage_blocked.html", u=u, v=v)
sort = request.args.get("sort", "new")
t = request.args.get("t", "all")
@ -330,21 +325,8 @@ def u_username(username, v=None):
listing = get_posts(ids, v=v)
if u.unban_utc:
#unban = datetime.fromtimestamp(u.unban_utc).strftime('%c')
return {'html': lambda: render_template("userpage.html",
unban=u.unban_string,
u=u,
v=v,
listing=listing,
page=page,
sort=sort,
t=t,
next_exists=next_exists,
is_following=(v and u.has_follower(v))),
'api': lambda: {"data": [x.json for x in listing]}
}
return {'html': lambda: render_template("userpage.html",
if request.headers.get("Authorization"): return [x.json for x in listing]
else: return render_template("userpage.html",
u=u,
v=v,
listing=listing,
@ -352,9 +334,8 @@ def u_username(username, v=None):
sort=sort,
t=t,
next_exists=next_exists,
is_following=(v and u.has_follower(v))),
'api': lambda: {"data": [x.json for x in listing]}
}
is_following=(v and u.has_follower(v)))
@app.get("/@<username>/comments")
@ -375,45 +356,43 @@ def u_username_comments(username, v=None):
u = user
if u.reserved:
return {'html': lambda: render_template("userpage_reserved.html",
if request.headers.get("Authorization"): return {"error": f"That username is reserved for: {u.reserved}"}
else: return render_template("userpage_reserved.html",
u=u,
v=v),
'api': lambda: {"error": f"That username is reserved for: {u.reserved}"}
}
v=v)
if u.is_private and (not v or (v.id != u.id and v.admin_level < 3)):
paidrent = False
if v and u.id == 253:
if int(time.time()) - v.rent_utc < 600: paidrent = True
elif request.args.get("rent") == "true" and v.dramacoins > 500:
v.dramacoins -= 500
v.rent_utc = int(time.time())
g.db.add(v)
u.dramacoins += 500
g.db.add(u)
send_notification(1046, u, f"@{v.username} has paid rent!")
paidrent = True
# paidrent = False
# if v and u.id == 253:
# if int(time.time()) - v.rent_utc < 600: paidrent = True
# elif request.args.get("rent") == "true" and v.dramacoins > 500:
# v.dramacoins -= 500
# v.rent_utc = int(time.time())
# g.db.add(v)
# u.dramacoins += 500
# g.db.add(u)
# send_notification(1046, u, f"@{v.username} has paid rent!")
# paidrent = True
if not paidrent:
return {'html': lambda: render_template("userpage_private.html",
# if not paidrent:
if request.headers.get("Authorization"): return {"error": "That userpage is private"}
else: return render_template("userpage_private.html",
u=u,
v=v),
'api': lambda: {"error": "That userpage is private"}
}
v=v)
if u.is_blocking and (not v or v.admin_level < 3):
return {'html': lambda: render_template("userpage_blocking.html",
u=u,
v=v),
'api': lambda: {"error": f"You are blocking @{u.username}."}
}
if request.headers.get("Authorization"): return {"error": f"You are blocking @{u.username}."}
else: return render_template("userpage_blocking.html",
u=u,
v=v)
if u.is_blocked and (not v or v.admin_level < 3):
return {'html': lambda: render_template("userpage_blocked.html",
u=u,
v=v),
'api': lambda: {"error": "This person is blocking you."}
}
if request.headers.get("Authorization"): return {"error": "This person is blocking you."}
else: return render_template("userpage_blocked.html",
u=u,
v=v)
page = int(request.args.get("page", "1"))
sort=request.args.get("sort","new")
@ -522,15 +501,14 @@ def saved_posts(v, username):
listing = get_posts(ids, v=v)
return {'html': lambda: render_template("userpage.html",
if request.headers.get("Authorization"): return [x.json for x in listing]
else: return render_template("userpage.html",
u=v,
v=v,
listing=listing,
page=page,
next_exists=next_exists,
),
'api': lambda: {"data": [x.json for x in listing]}
}
)
@app.get("/@<username>/saved/comments")
@ -548,12 +526,11 @@ def saved_comments(v, username):
listing = get_comments(ids, v=v)
return {'html': lambda: render_template("userpage_comments.html",
if request.headers.get("Authorization"): return [x.json for x in listing]
else: return render_template("userpage_comments.html",
u=v,
v=v,
listing=listing,
page=page,
next_exists=next_exists,
standalone=True),
'api': lambda: {"data": [x.json for x in listing]}
}
standalone=True)

View File

@ -2190,4 +2190,6 @@ I did this to show my interlocutors that their language doesn't impress me, that
You can see from their reactions that it worked-they were clearly taken aback.
It was a power move which I am entirely unashamed of, but I understand how that language might have upset some of you. This is an example of what I would call an invocation of a slur's power for good', but that's a subjective judgement. I invite you all to discuss this in the comments, critically or otherwise!
{[para]}
Save us Uncle Ted.
Save us Uncle Ted.
{[para]}
Holy crap! What a pos. If I see him again I'm going to talk to him really loudly about how I reject his racist ideology and that he should too. Thank you very much for the answer.