Merge branch 'master' into mistletoe

master
kek7198 2021-12-10 21:25:43 -06:00
commit b4940f8b96
4 changed files with 24 additions and 6 deletions

View File

@ -7,7 +7,7 @@ from sqlalchemy import *
from sqlalchemy.orm import relationship
from files.__main__ import Base
from files.classes.votes import CommentVote
from files.helpers.const import AUTOPOLLER_ID, censor_slurs
from files.helpers.const import AUTOPOLLER_ID, AUTOBETTER_ID, censor_slurs
from files.helpers.lazy import lazy
from .flags import CommentFlag
from random import randint
@ -187,7 +187,7 @@ class Comment(Base):
def replies(self):
r = self.__dict__.get("replies", None)
if r: r = [x for x in r if not x.author.shadowbanned]
if not r and r != []: r = sorted([x for x in self.child_comments if not x.author.shadowbanned and x.author_id.notin_((AUTOPOLLER_ID, AUTOBETTER_ID))], key=lambda x: x.score, reverse=True)
if not r and r != []: r = sorted([x for x in self.child_comments if not x.author.shadowbanned and x.author_id not in (AUTOPOLLER_ID, AUTOBETTER_ID)], key=lambda x: x.score, reverse=True)
return r
@replies.setter
@ -205,7 +205,7 @@ class Comment(Base):
@property
def replies3(self):
r = self.__dict__.get("replies", None)
if not r and r != []: r = sorted([x for x in self.child_comments if x.author_id.notin_((AUTOPOLLER_ID, AUTOBETTER_ID))], key=lambda x: x.score, reverse=True)
if not r and r != []: r = sorted([x for x in self.child_comments if x.author_id not in (AUTOPOLLER_ID, AUTOBETTER_ID)], key=lambda x: x.score, reverse=True)
return r
@property

View File

@ -87,11 +87,11 @@ class Submission(Base):
@property
@lazy
def bet_options(self):
return g.db.query(Comment).filter_by(parent_submission = self.id, author_id = AUTOBETTER_ID, level=1).order_by(Comment.upvotes.desc())
return g.db.query(Comment).filter_by(parent_submission = self.id, author_id = AUTOBETTER_ID, level=1)
def total_poll_voted(self, v):
if v:
for option in self.options + self.bet_options:
for option in self.options:
if option.poll_voted(v): return True
return False

View File

@ -56,7 +56,7 @@ class CommentVote(Base):
app_id = Column(Integer, ForeignKey("oauth_apps.id"))
real = Column(Boolean, default=True)
user = relationship("User", lazy="subquery", viewonly=True)
user = relationship("User", lazy="subquery")
comment = relationship("Comment", lazy="subquery", viewonly=True)
def __init__(self, *args, **kwargs):

View File

@ -21,6 +21,24 @@ SITE_NAME = environ.get("SITE_NAME", "").strip()
if SITE_NAME == 'PCM': cc = "splash mountain"
else: cc = "country club"
@app.get("/distribute/<cid>")
@admin_level_required(2)
def distribute(v, cid):
try: int(cid)
except: abort(400)
votes = g.db.query(CommentVote).filter_by(comment_id=cid)
autobetter = g.db.query(User).filter_by(id=AUTOBETTER_ID).first()
coinsperperson = int(autobetter.coins / votes.count())
for vote in votes:
u = vote.user
u.coins += coinsperperson
g.db.add(u)
autobetter.coins = 0
g.db.add(autobetter)
g.db.commit()
return str(coinsperperson)
@app.get("/marseys")
@auth_desired
def marseys(v):