forked from rDrama/rDrama
Exclude sb'd from vote counts, retain in tables.
Addressing the downvote spamming on WPD. Correctly shows jannies which users are SB'd, shows all voters (sans SB icons) to SB'd users, and only shows real voters to normies. SB'd users votes are still tracked so the icons look to them like they're doing something.master
parent
4ab8825d35
commit
ebc3e9a3f2
|
@ -17,20 +17,42 @@ def vote_info_get(v, link):
|
||||||
if thing.ghost and v.id != AEVANN_ID: abort(403)
|
if thing.ghost and v.id != AEVANN_ID: abort(403)
|
||||||
|
|
||||||
if isinstance(thing, Submission):
|
if isinstance(thing, Submission):
|
||||||
if thing.author.shadowbanned and not (v and v.admin_level >= PERMS['USER_SHADOWBAN']):
|
if (thing.author.shadowbanned
|
||||||
thing_id = g.db.query(Submission.id).filter_by(upvotes=thing.upvotes, downvotes=thing.downvotes).order_by(Submission.id).first()[0]
|
and not (v and v.admin_level >= PERMS['USER_SHADOWBAN'])):
|
||||||
|
thing_id = g.db.query(Submission.id) \
|
||||||
|
.filter_by(upvotes=thing.upvotes, downvotes=thing.downvotes) \
|
||||||
|
.order_by(Submission.id).first()[0]
|
||||||
else: thing_id = thing.id
|
else: thing_id = thing.id
|
||||||
|
|
||||||
ups = g.db.query(Vote).filter_by(submission_id=thing_id, vote_type=1).order_by(Vote.created_utc).all()
|
query = g.db.query(Vote).join(Vote.user).filter(
|
||||||
downs = g.db.query(Vote).filter_by(submission_id=thing_id, vote_type=-1).order_by(Vote.created_utc).all()
|
Vote.submission_id == thing_id,
|
||||||
|
Vote.vote_type == 1,
|
||||||
|
).order_by(Vote.created_utc)
|
||||||
|
|
||||||
|
if not v.can_see_shadowbanned:
|
||||||
|
query = query.filter(User.shadowbanned == None)
|
||||||
|
|
||||||
|
ups = query.filter(Vote.vote_type == 1).all()
|
||||||
|
downs = query.filter(Vote.vote_type == -1).all()
|
||||||
|
|
||||||
elif isinstance(thing, Comment):
|
elif isinstance(thing, Comment):
|
||||||
if thing.author.shadowbanned and not (v and v.admin_level >= PERMS['USER_SHADOWBAN']):
|
if (thing.author.shadowbanned
|
||||||
thing_id = g.db.query(Comment.id).filter_by(upvotes=thing.upvotes, downvotes=thing.downvotes).order_by(Comment.id).first()[0]
|
and not (v and v.admin_level >= PERMS['USER_SHADOWBAN'])):
|
||||||
|
thing_id = g.db.query(Comment.id) \
|
||||||
|
.filter_by(upvotes=thing.upvotes, downvotes=thing.downvotes) \
|
||||||
|
.order_by(Comment.id).first()[0]
|
||||||
else: thing_id = thing.id
|
else: thing_id = thing.id
|
||||||
|
|
||||||
ups = g.db.query(CommentVote).filter_by(comment_id=thing_id, vote_type=1).order_by(CommentVote.created_utc).all()
|
query = g.db.query(CommentVote).join(CommentVote.user).filter(
|
||||||
downs = g.db.query(CommentVote).filter_by(comment_id=thing_id, vote_type=-1 ).order_by(CommentVote.created_utc).all()
|
CommentVote.comment_id == thing_id,
|
||||||
|
CommentVote.vote_type == 1,
|
||||||
|
).order_by(CommentVote.created_utc)
|
||||||
|
|
||||||
|
if not v.can_see_shadowbanned:
|
||||||
|
query = query.filter(User.shadowbanned == None)
|
||||||
|
|
||||||
|
ups = query.filter(CommentVote.vote_type == 1).all()
|
||||||
|
downs = query.filter(CommentVote.vote_type == -1).all()
|
||||||
|
|
||||||
else: abort(400)
|
else: abort(400)
|
||||||
|
|
||||||
|
@ -40,6 +62,7 @@ def vote_info_get(v, link):
|
||||||
ups=ups,
|
ups=ups,
|
||||||
downs=downs)
|
downs=downs)
|
||||||
|
|
||||||
|
|
||||||
def vote_post_comment(target_id, new, v, cls, vote_cls):
|
def vote_post_comment(target_id, new, v, cls, vote_cls):
|
||||||
if new == "-1" and DISABLE_DOWNVOTES: abort(403)
|
if new == "-1" and DISABLE_DOWNVOTES: abort(403)
|
||||||
if new not in {"-1", "0", "1"}: abort(400)
|
if new not in {"-1", "0", "1"}: abort(400)
|
||||||
|
@ -91,7 +114,8 @@ def vote_post_comment(target_id, new, v, cls, vote_cls):
|
||||||
existing.coins = coin_value
|
existing.coins = coin_value
|
||||||
g.db.add(existing)
|
g.db.add(existing)
|
||||||
elif existing.vote_type != 0 and new == 0:
|
elif existing.vote_type != 0 and new == 0:
|
||||||
target.author.charge_account('coins', existing.coins, should_check_balance=False)
|
target.author.charge_account('coins', existing.coins,
|
||||||
|
should_check_balance=False)
|
||||||
target.author.truescore -= coin_delta
|
target.author.truescore -= coin_delta
|
||||||
g.db.add(target.author)
|
g.db.add(target.author)
|
||||||
g.db.delete(existing)
|
g.db.delete(existing)
|
||||||
|
@ -126,16 +150,17 @@ def vote_post_comment(target_id, new, v, cls, vote_cls):
|
||||||
|
|
||||||
# this is hacky but it works, we should probably do better later
|
# this is hacky but it works, we should probably do better later
|
||||||
def get_vote_count(dir, real_instead_of_dir):
|
def get_vote_count(dir, real_instead_of_dir):
|
||||||
votes = g.db.query(vote_cls)
|
votes = g.db.query(vote_cls).join(vote_cls.user) \
|
||||||
|
.filter(User.shadowbanned == None)
|
||||||
if real_instead_of_dir:
|
if real_instead_of_dir:
|
||||||
votes = votes.filter_by(real=True)
|
votes = votes.filter(vote_cls.real == True)
|
||||||
else:
|
else:
|
||||||
votes = votes.filter_by(vote_type=dir)
|
votes = votes.filter(vote_cls.vote_type == dir)
|
||||||
|
|
||||||
if vote_cls == Vote:
|
if vote_cls == Vote:
|
||||||
votes = votes.filter_by(submission_id=target.id)
|
votes = votes.filter(vote_cls.submission_id == target.id)
|
||||||
elif vote_cls == CommentVote:
|
elif vote_cls == CommentVote:
|
||||||
votes = votes.filter_by(comment_id=target.id)
|
votes = votes.filter(vote_cls.comment_id == target.id)
|
||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
return votes.count()
|
return votes.count()
|
||||||
|
@ -150,9 +175,13 @@ def vote_post_comment(target_id, new, v, cls, vote_cls):
|
||||||
if target.author.progressivestack or target.author.id in BOOSTED_USERS:
|
if target.author.progressivestack or target.author.id in BOOSTED_USERS:
|
||||||
mul = 2
|
mul = 2
|
||||||
elif cls == Submission:
|
elif cls == Submission:
|
||||||
if target.domain.endswith('.win') or (target.domain in BOOSTED_SITES and not target.url.startswith('/')) or target.sub in BOOSTED_HOLES:
|
if (target.domain.endswith('.win')
|
||||||
|
or (target.domain in BOOSTED_SITES and not target.url.startswith('/'))
|
||||||
|
or target.sub in BOOSTED_HOLES):
|
||||||
mul = 2
|
mul = 2
|
||||||
elif not target.sub and target.body_html and target.author.id not in {8768,3402,5214,12719}:
|
elif (not target.sub
|
||||||
|
and target.body_html
|
||||||
|
and target.author.id not in {8768,3402,5214,12719}):
|
||||||
x = target.body_html.count('" target="_blank" rel="nofollow noopener">')
|
x = target.body_html.count('" target="_blank" rel="nofollow noopener">')
|
||||||
x += target.body_html.count('<a href="/images/')
|
x += target.body_html.count('<a href="/images/')
|
||||||
target.realupvotes += min(x*2, 20)
|
target.realupvotes += min(x*2, 20)
|
||||||
|
@ -164,6 +193,7 @@ def vote_post_comment(target_id, new, v, cls, vote_cls):
|
||||||
g.db.add(target)
|
g.db.add(target)
|
||||||
return "", 204
|
return "", 204
|
||||||
|
|
||||||
|
|
||||||
@app.post("/vote/post/<post_id>/<new>")
|
@app.post("/vote/post/<post_id>/<new>")
|
||||||
@limiter.limit("5/second;60/minute;1000/hour;2000/day")
|
@limiter.limit("5/second;60/minute;1000/hour;2000/day")
|
||||||
@is_not_permabanned
|
@is_not_permabanned
|
||||||
|
|
Loading…
Reference in New Issue