remotes/1693045480750635534/spooky-22
Aevann1 2021-07-25 16:23:53 +02:00
parent 1f2b1502e5
commit e8369daf01
13 changed files with 230 additions and 186 deletions

View File

@ -180,112 +180,6 @@ def get_posts(pids, v=None):
return sorted(output, key=lambda x: pids.index(x.id))
def get_post_with_comments(pid, sort="top", v=None):
post = get_post(pid, v=v)
if v:
votes = g.db.query(CommentVote).filter_by(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,
)
if v.admin_level >=4:
comms=comms.options(joinedload(Comment.oauth_app))
comms=comms.filter(
Comment.parent_submission == post.id
).join(
votes,
votes.c.comment_id == Comment.id,
isouter=True
).join(
blocking,
blocking.c.target_id == Comment.author_id,
isouter=True
).join(
blocked,
blocked.c.user_id == Comment.author_id,
isouter=True
)
if sort == "top":
comments = comms.order_by(Comment.score.desc()).all()
elif sort == "bottom":
comments = comms.order_by(Comment.score.asc()).all()
elif sort == "new":
comments = comms.order_by(Comment.created_utc.desc()).all()
elif sort == "old":
comments = comms.order_by(Comment.created_utc.asc()).all()
elif sort == "controversial":
comments = 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))
else:
abort(422)
output = []
for c in comments:
comment = c[0]
if comment.author and comment.author.shadowbanned and not (v and v.id == comment.author_id): continue
comment._voted = c[1] or 0
comment._is_blocking = c[2] or 0
comment._is_blocked = c[3] or 0
output.append(comment)
post._preloaded_comments = output
else:
comms = g.db.query(
Comment
).filter(
Comment.parent_submission == post.id
)
if sort == "top":
comments = comms.order_by(Comment.score.desc()).all()
elif sort == "bottom":
comments = comms.order_by(Comment.score.asc()).all()
elif sort == "new":
comments = comms.order_by(Comment.created_utc.desc()).all()
elif sort == "old":
comments = comms.order_by(Comment.created_utc.asc()).all()
elif sort == "controversial":
comments = sorted(comms.all(), key=lambda x: x.score_disputed, reverse=True)
elif sort == "random":
c = comms.all()
comments = random.sample(c, k=len(c))
else:
abort(422)
if random.random() < 0.1:
for comment in comments:
if comment.author and comment.author.shadowbanned:
rand = random.randint(500,1400)
vote = CommentVote(user_id=rand,
vote_type=random.choice([-1, 1]),
comment_id=comment.id)
g.db.add(vote)
try: g.db.flush()
except: g.db.rollback()
comment.upvotes = comment.ups
comment.downvotes = comment.downs
g.db.add(comment)
post._preloaded_comments = [x for x in comments if not (x.author and x.author.shadowbanned) or (v and v.id == x.author_id)]
return post
def get_comment(cid, v=None, graceful=False, **kwargs):
if isinstance(cid, str):
@ -411,16 +305,6 @@ def get_comments(cids, v=None, load_parent=False, **kwargs):
return output
def get_board(bid, graceful=False):
return g.db.query(Board).first()
def get_guild(name, graceful=False):
return g.db.query(Board).first()
def get_domain(s):
# parse domain into all possible subdomains
@ -445,43 +329,4 @@ def get_domain(s):
# property
doms = sorted(doms, key=lambda x: len(x.domain), reverse=True)
return doms[0]
def get_application(client_id, graceful=False):
application = g.db.query(OauthApp).filter_by(client_id=client_id).first()
if not application and not graceful:
abort(404)
return application
def get_from_permalink(link, v=None):
if "@" in link:
name = re.search("/@(\w+)", link)
if name:
name=name.match(1)
return get_user(name)
if "+" in link:
x = re.search("/\+(\w+)$", link)
if x:
name=x.match(1)
return get_guild(name)
ids = re.search("://[^/]+\w+/post/(\w+)/[^/]+(/(\w+))?", link)
try:
post_id = ids.group(1)
comment_id = ids.group(3)
except: abort(400)
if comment_id:
return get_comment(int(comment_id), v=v)
else:
return get_post(int(post_id), v=v)
return doms[0]

View File

@ -49,8 +49,4 @@ def js_str_escape(s):
@app.template_filter("app_config")
def app_config(x):
return app.config.get(x)
# @app.template_filter("general_chat_count")
# def general_chat_count(x):
# return get_guild("general").chat_count
return app.config.get(x)

View File

@ -196,6 +196,8 @@ def badge_grant_post(v):
if badge_id in [21,22,23,24]:
user.patron = True
user.animatedname = True
if badge_id == 23: user.banawards = 1
elif badge_id == 24: user.banawards = 3
g.db.add(user)
return redirect(user.permalink)
@ -265,10 +267,22 @@ def participation_stats(v):
def admin_vote_info_get(v):
if v and v.is_banned and not v.unban_utc: return render_template("seized.html")
if not request.args.get("link"):
return render_template("admin/votes.html", v=v)
link = request.args.get("link")
if not link: return render_template("admin/votes.html", v=v)
ids = re.search("://[^/]+\w+/post/(\w+)/[^/]+(/(\w+))?", link)
try:
post_id = ids.group(1)
comment_id = ids.group(3)
except: abort(400)
if comment_id:
thing = get_comment(int(comment_id), v=v)
else:
thing = get_post(int(post_id), v=v)
thing = get_from_permalink(request.args.get("link"), v=v)
if isinstance(thing, Submission):

View File

@ -128,7 +128,7 @@ def mod_rescind_bid_username(bid, username, board, v):
@api("guildmaster")
def mod_accept_board(bid, v):
board = get_board(bid)
board = g.db.query(Board).first()
x = board.has_invite(v)
if not x:
@ -222,7 +222,7 @@ def mod_remove_username(bid, username, board, v):
@public("read")
def board_about_mods(v):
board = get_guild("general")
g.db.query(Board).first()
me = board.has_mod(v)

View File

@ -668,7 +668,7 @@ def api_comment(v):
# print(f"Content Event: @{v.username} comment {c.base36id}")
board = get_board(1)
board = g.db.query(Board).first()
cache.delete_memoized(comment_idlist)
cache.delete_memoized(User.commentlisting, v)

View File

@ -11,6 +11,14 @@ from drama.__main__ import app
@app.errorhandler(400)
@auth_desired
@api()
def error_400(e, v):
return{"html": lambda: (render_template('errors/400.html', v=v), 400),
"api": lambda: (jsonify({"error": "400 Bad Request"}), 400 )
}
@app.errorhandler(401)
def error_401(e):
@ -25,6 +33,7 @@ def error_401(e):
else:
return redirect(output)
@app.errorhandler(403)
@auth_desired
@api()
@ -61,12 +70,28 @@ def error_409(e, v):
}
@app.errorhandler(410)
@auth_desired
@api()
def error_410(e, v):
return{"html": lambda: (render_template('errors/410.html', v=v), 410),
"api": lambda: (jsonify({"error": "410 Request Payload Too Large"}), 410)
}
@app.errorhandler(413)
@auth_desired
@api()
def error_413(e, v):
return{"html": lambda: (render_template('errors/413.html', v=v), 413),
"api": lambda: (jsonify({"error": "413 Request Payload Too Large"}), 413)
"api": lambda: (jsonify({"error": "413 Image Size Too Large"}), 413)
}
@app.errorhandler(418)
@auth_desired
@api()
def error_418(e, v):
return{"html": lambda: (render_template('errors/418.html', v=v), 418),
"api": lambda: (jsonify({"error": "418 I'm A Teapot"}), 418)
}
@ -111,6 +136,24 @@ def error_500(e, v):
}
@app.errorhandler(502)
@auth_desired
@api()
def error_502(e, v):
return{"html": lambda: (render_template('errors/502.html', v=v), 502),
"api": lambda: (jsonify({"error": "502 Bad Gateway"}), 502)
}
@app.errorhandler(503)
@auth_desired
@api()
def error_503(e, v):
return{"html": lambda: (render_template('errors/503.html', v=v), 503),
"api": lambda: (jsonify({"error": "503 Service Unavailable"}), 503)
}
@app.route("/allow_nsfw_logged_in/<bid>", methods=["POST"])
@auth_required
@validate_formkey

View File

@ -427,7 +427,7 @@ def all_comments(v):
idlist = idlist[0:25]
board = get_board(1)
board = g.db.query(Board).first()
return {"html": lambda: render_template("home_comments.html",
v=v,
sort=sort,

View File

@ -29,7 +29,9 @@ def oauth_authorize_prompt(v):
client_id = request.args.get("client_id")
application = get_application(client_id)
application = g.db.query(OauthApp).filter_by(client_id=client_id).first()
if not application:
return jsonify({"oauth_error": "Invalid `client_id`"}), 401
@ -90,7 +92,7 @@ def oauth_authorize_post(v):
state = request.form.get("state")
redirect_uri = request.form.get("redirect_uri")
application = get_application(client_id)
application = g.db.query(OauthApp).filter_by(client_id=client_id).first()
if not application:
return jsonify({"oauth_error": "Invalid `client_id`"}), 401
if application.is_banned:

View File

@ -93,7 +93,7 @@ def publish(pid, v):
def submit_get(v):
if v and v.is_banned and not v.unban_utc: return render_template("seized.html")
b = get_guild("general")
b = g.db.query(Board).first()
return render_template("submit.html",
v=v,
@ -113,9 +113,149 @@ def post_base36id(pid, anything=None, v=None):
if v: defaultsortingcomments = v.defaultsortingcomments
else: defaultsortingcomments = "top"
sort=request.args.get("sort", defaultsortingcomments)
post = get_post_with_comments(pid, v=v, sort=sort)
post = get_post(pid, v=v)
if v:
votes = g.db.query(CommentVote).filter_by(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,
)
if v.admin_level >=4:
comms=comms.options(joinedload(Comment.oauth_app))
comms=comms.filter(
Comment.parent_submission == post.id
).join(
votes,
votes.c.comment_id == Comment.id,
isouter=True
).join(
blocking,
blocking.c.target_id == Comment.author_id,
isouter=True
).join(
blocked,
blocked.c.user_id == Comment.author_id,
isouter=True
)
if sort == "top":
comments = comms.order_by(Comment.score.desc()).all()
elif sort == "bottom":
comments = comms.order_by(Comment.score.asc()).all()
elif sort == "new":
comments = comms.order_by(Comment.created_utc.desc()).all()
elif sort == "old":
comments = comms.order_by(Comment.created_utc.asc()).all()
elif sort == "controversial":
comments = 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))
else:
abort(422)
output = []
for c in comments:
comment = c[0]
if comment.author and comment.author.shadowbanned and not (v and v.id == comment.author_id): continue
comment._voted = c[1] or 0
comment._is_blocking = c[2] or 0
comment._is_blocked = c[3] or 0
output.append(comment)
post._preloaded_comments = output
else:
comms = g.db.query(
Comment
).filter(
Comment.parent_submission == post.id
)
if sort == "top":
comments = comms.order_by(Comment.score.desc()).all()
elif sort == "bottom":
comments = comms.order_by(Comment.score.asc()).all()
elif sort == "new":
comments = comms.order_by(Comment.created_utc.desc()).all()
elif sort == "old":
comments = comms.order_by(Comment.created_utc.asc()).all()
elif sort == "controversial":
comments = sorted(comms.all(), key=lambda x: x.score_disputed, reverse=True)
elif sort == "random":
c = comms.all()
comments = random.sample(c, k=len(c))
else:
abort(422)
if random.random() < 0.1:
for comment in comments:
if comment.author and comment.author.shadowbanned:
rand = random.randint(500,1400)
vote = CommentVote(user_id=rand,
vote_type=random.choice([-1, 1]),
comment_id=comment.id)
g.db.add(vote)
try: g.db.flush()
except: g.db.rollback()
comment.upvotes = comment.ups
comment.downvotes = comment.downs
g.db.add(comment)
post._preloaded_comments = [x for x in comments if not (x.author and x.author.shadowbanned) or (v and v.id == x.author_id)]
post.views += 1
g.db.add(post)
g.db.commit()
@ -482,9 +622,7 @@ def submit_post(v):
if repost:
return redirect(repost.permalink)
board = get_guild(request.form.get('board', 'general'), graceful=True)
if not board:
board = get_guild('general')
board = g.db.query(Board).first()
if not title:
return {"html": lambda: (render_template("submit.html",
@ -616,7 +754,7 @@ def submit_post(v):
board_name = board_name.lstrip("+")
board_name = board_name.strip()
board = get_guild(board_name, graceful=True)
board = g.db.query(Board).first()
if not board:

View File

@ -413,7 +413,7 @@ def u_username_comments(username, v=None):
is_following = (v and user.has_follower(v))
board = get_board(1)
board = g.db.query(Board).first()
return {"html": lambda: render_template("userpage_comments.html",
u=user,
v=v,

View File

@ -1,17 +1,17 @@
{% extends "default.html" %}
{% block title %}
<title>403 Unauthorized</title>
<title>401 Not Authorized</title>
{% endblock %}
{% block pagetype %}error-405{% endblock %}
{% block pagetype %}error-401{% endblock %}
{% block content %}
<div class="row justify-content-center">
<div class="col-10 col-md-5">
<div class="text-center px-3 my-8">
<i class="fad fa-ban text-muted mb-5" style="font-size: 5rem;"></i>
<h1 class="h5">403 Unauthorized</h1>
<h1 class="h5">401 Not Authorized</h1>
<p class="text-muted">You have 0 ban awards (they're a patron perk):</p>
<a href="https://rdrama.gumroad.com/l/tfcvri">https://rdrama.gumroad.com/l/tfcvri</a>
<br>

View File

@ -1,17 +1,17 @@
{% extends "default.html" %}
{% block title %}
<title>403 Unauthorized</title>
<title>401 Not Authorized</title>
{% endblock %}
{% block pagetype %}error-403{% endblock %}
{% block pagetype %}error-401{% endblock %}
{% block content %}
<div class="row justify-content-center">
<div class="col-10 col-md-5">
<div class="text-center px-3 my-8">
<i class="fad fa-ban text-muted mb-5" style="font-size: 5rem;"></i>
<h1 class="h5">403 Unauthorized</h1>
<h1 class="h5">401 Not Authorized</h1>
<p class="text-muted">This page is only available to patrons:</p>
<a href="https://rdrama.gumroad.com/l/tfcvri">https://rdrama.gumroad.com/l/tfcvri</a>
<br>

View File

@ -2129,4 +2129,10 @@ Fuck it, I'm gonna take my meds and go out for my daily run
Because I'm not fat, you see, but I am a schizo
:crazyeyes:
:crazyeyes:
{[para]}
My plan is to buy a slumlord rental property in a shithole city, get a bunch of illegal women living there on section 8, knock them all up while keeping my name off the birth certificates, and then report them to health and human services once they can't make babies any more. My kids will end up in the foster care system, where the half-mexican boys will be turned gay by pedophiles (thereby preventing dilution of white women and ensuring that the gays are too busy with brown kids to molest white kids), and the girls will do as hapa/castillo girls do and exclusively date white guys.
Without their kids the illegal women will invariably go insane or kill themselves, ensuring that tax dollars don't go towards their maintenance in old age.
I also want to set up something that looks from the outside like a hippy commune, but is actually a fascist compound - American Juche with Crunchy Granola Characteristics, if you want to get technical. All the women will wear sundresses and sandals, all the men will be jacked, and the only thing vaccinated will be the livestock. As long as we say on paper that our kids are all gay or trans, and all the men and women are gay or trans, we should escape notice until it's too late. If the feds try to pull an ATF we'll put the men in sundresses and play music at them until they go away, or do oiled up Greco-Roman wrestling until they get uncomfortable and look away.