xv
This commit is contained in:
parent
71b05b7e47
commit
8ef929002d
13 changed files with 198 additions and 72 deletions
|
@ -266,9 +266,6 @@ function poll_vote(cid, parentid) {
|
||||||
for(let el of document.getElementsByClassName('presult-'+parentid)) {
|
for(let el of document.getElementsByClassName('presult-'+parentid)) {
|
||||||
el.classList.remove('d-none');
|
el.classList.remove('d-none');
|
||||||
}
|
}
|
||||||
for(let el of document.getElementsByClassName('presult')) {
|
|
||||||
el.classList.remove('d-none');
|
|
||||||
}
|
|
||||||
var type = document.getElementById(cid).checked;
|
var type = document.getElementById(cid).checked;
|
||||||
var scoretext = document.getElementById('poll-' + cid);
|
var scoretext = document.getElementById('poll-' + cid);
|
||||||
var score = Number(scoretext.textContent);
|
var score = Number(scoretext.textContent);
|
||||||
|
@ -277,6 +274,26 @@ function poll_vote(cid, parentid) {
|
||||||
post('/vote/poll/' + cid + '?vote=' + type);
|
post('/vote/poll/' + cid + '?vote=' + type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function choice_vote(cid, parentid) {
|
||||||
|
for(let el of document.getElementsByClassName('presult-'+parentid)) {
|
||||||
|
el.classList.remove('d-none');
|
||||||
|
}
|
||||||
|
|
||||||
|
let curr = document.getElementById(`current-${parentid}`)
|
||||||
|
if (curr.value)
|
||||||
|
{
|
||||||
|
var scoretext = document.getElementById('choice-' + curr.value);
|
||||||
|
var score = Number(scoretext.textContent);
|
||||||
|
scoretext.textContent = score - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
var scoretext = document.getElementById('choice-' + cid);
|
||||||
|
var score = Number(scoretext.textContent);
|
||||||
|
scoretext.textContent = score + 1;
|
||||||
|
post('/vote/choice/' + cid);
|
||||||
|
curr.value = cid
|
||||||
|
}
|
||||||
|
|
||||||
function handle_blackjack_action(cid, action) {
|
function handle_blackjack_action(cid, action) {
|
||||||
const form = new FormData();
|
const form = new FormData();
|
||||||
form.append('formkey', formkey());
|
form.append('formkey', formkey());
|
||||||
|
@ -288,12 +305,6 @@ function handle_blackjack_action(cid, action) {
|
||||||
xhr.setRequestHeader('xhr', 'xhr');
|
xhr.setRequestHeader('xhr', 'xhr');
|
||||||
|
|
||||||
xhr.onload = function() {
|
xhr.onload = function() {
|
||||||
if (xhr.status == 200) {
|
if (xhr.status == 200) location.reload();
|
||||||
window.location.reload();
|
|
||||||
} else {
|
|
||||||
// Handle error.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
xhr.send(form);
|
xhr.send(form);
|
||||||
}
|
}
|
|
@ -11,6 +11,7 @@ from files.helpers.const import *
|
||||||
from files.helpers.lazy import lazy
|
from files.helpers.lazy import lazy
|
||||||
from .flags import CommentFlag
|
from .flags import CommentFlag
|
||||||
from random import randint
|
from random import randint
|
||||||
|
from .votes import CommentVote
|
||||||
|
|
||||||
class Comment(Base):
|
class Comment(Base):
|
||||||
|
|
||||||
|
@ -79,22 +80,31 @@ class Comment(Base):
|
||||||
@lazy
|
@lazy
|
||||||
def poll_voted(self, v):
|
def poll_voted(self, v):
|
||||||
if v:
|
if v:
|
||||||
vote = g.db.query(CommentVote).filter_by(user_id=v.id, comment_id=self.id).one_or_none()
|
vote = g.db.query(CommentVote.vote_type).filter_by(user_id=v.id, comment_id=self.id).one_or_none()
|
||||||
if vote: return vote.vote_type
|
if vote: return vote[0]
|
||||||
else: return None
|
return None
|
||||||
else: return None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def options(self):
|
def options(self):
|
||||||
return [x for x in self.child_comments if x.author_id == AUTOPOLLER_ID]
|
return [x for x in self.child_comments if x.author_id == AUTOPOLLER_ID]
|
||||||
|
|
||||||
|
@property
|
||||||
|
@lazy
|
||||||
|
def choices(self):
|
||||||
|
return [x for x in self.child_comments if x.author_id == AUTOCHOICE_ID]
|
||||||
|
|
||||||
def total_poll_voted(self, v):
|
def total_poll_voted(self, v):
|
||||||
if v:
|
if v:
|
||||||
for option in self.options:
|
for option in self.options:
|
||||||
if option.poll_voted(v): return True
|
if option.poll_voted(v): return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def total_choice_voted(self, v):
|
||||||
|
if v:
|
||||||
|
return g.db.query(CommentVote).filter(CommentVote.user_id == v.id, CommentVote.comment_id.in_(tuple(x.id for x in self.choices))).all()
|
||||||
|
return False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def controversial(self):
|
def controversial(self):
|
||||||
|
@ -198,12 +208,12 @@ class Comment(Base):
|
||||||
@property
|
@property
|
||||||
def replies(self):
|
def replies(self):
|
||||||
if self.replies2 != None: return [x for x in self.replies2 if not x.author.shadowbanned]
|
if self.replies2 != None: return [x for x in self.replies2 if not x.author.shadowbanned]
|
||||||
return sorted((x for x in self.child_comments if x.author and not x.author.shadowbanned and x.author_id not in (AUTOPOLLER_ID, AUTOBETTER_ID)), key=lambda x: x.realupvotes, reverse=True)
|
return sorted((x for x in self.child_comments if x.author and not x.author.shadowbanned and x.author_id not in (AUTOPOLLER_ID, AUTOBETTER_ID, AUTOCHOICE_ID)), key=lambda x: x.realupvotes, reverse=True)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def replies3(self):
|
def replies3(self):
|
||||||
if self.replies2 != None: return self.replies2
|
if self.replies2 != None: return self.replies2
|
||||||
return sorted((x for x in self.child_comments if x.author_id not in (AUTOPOLLER_ID, AUTOBETTER_ID)), key=lambda x: x.realupvotes, reverse=True)
|
return sorted((x for x in self.child_comments if x.author_id not in (AUTOPOLLER_ID, AUTOBETTER_ID, AUTOCHOICE_ID)), key=lambda x: x.realupvotes, reverse=True)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def replies2(self):
|
def replies2(self):
|
||||||
|
@ -361,15 +371,25 @@ class Comment(Base):
|
||||||
g.db.add(self.author)
|
g.db.add(self.author)
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
|
|
||||||
for o in self.options:
|
for c in self.options:
|
||||||
body += f'<div class="custom-control"><input type="checkbox" class="custom-control-input" id="{o.id}" name="option"'
|
body += f'<div class="custom-control"><input type="checkbox" class="custom-control-input" id="{c.id}" name="option"'
|
||||||
if o.poll_voted(v): body += " checked"
|
if c.poll_voted(v): body += " checked"
|
||||||
if v: body += f''' onchange="poll_vote('{o.id}', '{self.id}')"'''
|
if v: body += f''' onchange="poll_vote('{c.id}', '{self.id}')"'''
|
||||||
else: body += f''' onchange="poll_vote_no_v('{o.id}', '{self.id}')"'''
|
else: body += f''' onchange="poll_vote_no_v('{c.id}', '{self.id}')"'''
|
||||||
body += f'''><label class="custom-control-label" for="{o.id}">{o.body_html}<span class="presult-{self.id}'''
|
body += f'''><label class="custom-control-label" for="{c.id}">{c.body_html}<span class="presult-{self.id}'''
|
||||||
if not self.total_poll_voted(v): body += ' d-none'
|
if not self.total_poll_voted(v): body += ' d-none'
|
||||||
body += f'"> - <a href="/votes?link=t3_{o.id}"><span id="poll-{o.id}">{o.upvotes}</span> votes</a></span></label></div>'
|
body += f'"> - <a href="/votes?link=t3_{c.id}"><span id="poll-{c.id}">{c.upvotes}</span> votes</a></span></label></div>'
|
||||||
|
|
||||||
|
curr = self.total_choice_voted(v)
|
||||||
|
if curr:
|
||||||
|
body += f'<input class="d-none" id="current-{self.id}" value={curr[0].comment_id}>'
|
||||||
|
|
||||||
|
for c in self.choices:
|
||||||
|
body += f'''<div class="custom-control mt-3"><input name="choice" autocomplete="off" class="custom-control-input" type="radio" id="{c.id}" onchange="choice_vote('{c.id}','{self.id}')"'''
|
||||||
|
if c.poll_voted(v): body += " checked "
|
||||||
|
body += f'''><label class="custom-control-label" for="{c.id}">{c.body_html}<span class="presult-{self.id}'''
|
||||||
|
if not self.total_choice_voted(v): body += ' d-none'
|
||||||
|
body += f'"> - <a href="/votes?link=t3_{c.id}"><span id="choice-{c.id}">{c.upvotes}</span> votes</a></span></label></div>'
|
||||||
|
|
||||||
if self.author.sig_html and not self.ghost and (self.author_id == MOOSE_ID or not (v and v.sigs_disabled)):
|
if self.author.sig_html and not self.ghost and (self.author_id == MOOSE_ID or not (v and v.sigs_disabled)):
|
||||||
body += f"<hr>{self.author.sig_html}"
|
body += f"<hr>{self.author.sig_html}"
|
||||||
|
|
|
@ -13,6 +13,7 @@ from .flags import Flag
|
||||||
from .comment import Comment
|
from .comment import Comment
|
||||||
from flask import g
|
from flask import g
|
||||||
from .sub import *
|
from .sub import *
|
||||||
|
from .votes import CommentVote
|
||||||
|
|
||||||
class Submission(Base):
|
class Submission(Base):
|
||||||
__tablename__ = "submissions"
|
__tablename__ = "submissions"
|
||||||
|
@ -68,7 +69,7 @@ class Submission(Base):
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def comments2(self):
|
def comments2(self):
|
||||||
return g.db.query(Comment.author_id, Comment.created_utc, Comment.id).filter(Comment.parent_submission == self.id, Comment.author_id.notin_((AUTOPOLLER_ID,AUTOBETTER_ID))).all()
|
return g.db.query(Comment.author_id, Comment.created_utc, Comment.id).filter(Comment.parent_submission == self.id, Comment.author_id.notin_((AUTOPOLLER_ID,AUTOBETTER_ID, AUTOCHOICE_ID))).all()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
|
@ -86,6 +87,11 @@ class Submission(Base):
|
||||||
def options(self):
|
def options(self):
|
||||||
return g.db.query(Comment).filter_by(parent_submission = self.id, author_id = AUTOPOLLER_ID, level=1)
|
return g.db.query(Comment).filter_by(parent_submission = self.id, author_id = AUTOPOLLER_ID, level=1)
|
||||||
|
|
||||||
|
@property
|
||||||
|
@lazy
|
||||||
|
def choices(self):
|
||||||
|
return g.db.query(Comment).filter_by(parent_submission = self.id, author_id = AUTOCHOICE_ID, level=1)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def bet_options(self):
|
def bet_options(self):
|
||||||
|
@ -97,6 +103,11 @@ class Submission(Base):
|
||||||
if option.poll_voted(v): return True
|
if option.poll_voted(v): return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def total_choice_voted(self, v):
|
||||||
|
if v:
|
||||||
|
return g.db.query(CommentVote).filter(CommentVote.user_id == v.id, CommentVote.comment_id.in_(tuple(x.id for x in self.choices))).all()
|
||||||
|
return False
|
||||||
|
|
||||||
def total_bet_voted(self, v):
|
def total_bet_voted(self, v):
|
||||||
if "closed" in self.body.lower(): return True
|
if "closed" in self.body.lower(): return True
|
||||||
if v:
|
if v:
|
||||||
|
@ -373,15 +384,25 @@ class Submission(Base):
|
||||||
g.db.add(self.author)
|
g.db.add(self.author)
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
|
|
||||||
for o in self.options:
|
for c in self.options:
|
||||||
body += f'<div class="custom-control"><input type="checkbox" class="custom-control-input" id="{o.id}" name="option"'
|
body += f'<div class="custom-control"><input type="checkbox" class="custom-control-input" id="{c.id}" name="option"'
|
||||||
if o.poll_voted(v): body += " checked"
|
if c.poll_voted(v): body += " checked"
|
||||||
if v: body += f''' onchange="poll_vote('{o.id}', '{self.id}')"'''
|
if v: body += f''' onchange="poll_vote('{c.id}', '{self.id}')"'''
|
||||||
else: body += f''' onchange="poll_vote_no_v('{o.id}', '{self.id}')"'''
|
else: body += f''' onchange="poll_vote_no_v('{c.id}', '{self.id}')"'''
|
||||||
body += f'''><label class="custom-control-label" for="{o.id}">{o.body_html}<span class="presult-{self.id}'''
|
body += f'''><label class="custom-control-label" for="{c.id}">{c.body_html}<span class="presult-{self.id}'''
|
||||||
if not self.total_poll_voted(v): body += ' d-none'
|
if not self.total_poll_voted(v): body += ' d-none'
|
||||||
body += f'"> - <a href="/votes?link=t3_{o.id}"><span id="poll-{o.id}">{o.upvotes}</span> votes</a></span></label></div>'
|
body += f'"> - <a href="/votes?link=t3_{c.id}"><span id="poll-{c.id}">{c.upvotes}</span> votes</a></span></label></div>'
|
||||||
|
|
||||||
|
curr = self.total_choice_voted(v)
|
||||||
|
if curr:
|
||||||
|
body += f'<input class="d-none" id="current-{self.id}" value={curr[0].comment_id}>'
|
||||||
|
|
||||||
|
for c in self.choices:
|
||||||
|
body += f'''<div class="custom-control mt-3"><input name="choice" autocomplete="off" class="custom-control-input" type="radio" id="{c.id}" onchange="choice_vote('{c.id}','{self.id}')"'''
|
||||||
|
if c.poll_voted(v): body += " checked "
|
||||||
|
body += f'''><label class="custom-control-label" for="{c.id}">{c.body_html}<span class="presult-{self.id}'''
|
||||||
|
if not self.total_choice_voted(v): body += ' d-none'
|
||||||
|
body += f'"> - <a href="/votes?link=t3_{c.id}"><span id="choice-{c.id}">{c.upvotes}</span> votes</a></span></label></div>'
|
||||||
|
|
||||||
for c in self.bet_options:
|
for c in self.bet_options:
|
||||||
body += f'''<div class="custom-control mt-3"><input autocomplete="off" class="custom-control-input bet" type="radio" id="{c.id}" onchange="bet_vote('{c.id}')"'''
|
body += f'''<div class="custom-control mt-3"><input autocomplete="off" class="custom-control-input bet" type="radio" id="{c.id}" onchange="bet_vote('{c.id}')"'''
|
||||||
|
|
|
@ -149,6 +149,7 @@ if SITE == 'rdrama.net':
|
||||||
ZOZBOT_ID = 1833
|
ZOZBOT_ID = 1833
|
||||||
AUTOPOLLER_ID = 6176
|
AUTOPOLLER_ID = 6176
|
||||||
AUTOBETTER_ID = 7668
|
AUTOBETTER_ID = 7668
|
||||||
|
AUTOCHOICE_ID = 9167
|
||||||
TAX_NOTIF_ID = 995
|
TAX_NOTIF_ID = 995
|
||||||
PIZZASHILL_ID = 2424
|
PIZZASHILL_ID = 2424
|
||||||
HIL_ID = 4245
|
HIL_ID = 4245
|
||||||
|
@ -179,6 +180,7 @@ elif SITE == "pcmemes.net":
|
||||||
ZOZBOT_ID = 1833
|
ZOZBOT_ID = 1833
|
||||||
AUTOPOLLER_ID = 3369
|
AUTOPOLLER_ID = 3369
|
||||||
AUTOBETTER_ID = 1867
|
AUTOBETTER_ID = 1867
|
||||||
|
AUTOCHOICE_ID = 2072
|
||||||
TAX_NOTIF_ID = 1592
|
TAX_NOTIF_ID = 1592
|
||||||
PIZZASHILL_ID = 0
|
PIZZASHILL_ID = 0
|
||||||
HIL_ID = 0
|
HIL_ID = 0
|
||||||
|
@ -209,7 +211,8 @@ else:
|
||||||
ZOZBOT_ID = 5
|
ZOZBOT_ID = 5
|
||||||
AUTOPOLLER_ID = 6
|
AUTOPOLLER_ID = 6
|
||||||
AUTOBETTER_ID = 7
|
AUTOBETTER_ID = 7
|
||||||
TAX_NOTIF_ID = 8
|
AUTOCHOICE_ID = 8
|
||||||
|
TAX_NOTIF_ID = 9
|
||||||
PIZZASHILL_ID = 0
|
PIZZASHILL_ID = 0
|
||||||
HIL_ID = 0
|
HIL_ID = 0
|
||||||
CRAT_ID = 0
|
CRAT_ID = 0
|
||||||
|
|
|
@ -102,7 +102,7 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=None):
|
||||||
|
|
||||||
comments=comments.filter(
|
comments=comments.filter(
|
||||||
Comment.parent_submission == post.id,
|
Comment.parent_submission == post.id,
|
||||||
Comment.author_id.notin_((AUTOPOLLER_ID, AUTOBETTER_ID))
|
Comment.author_id.notin_((AUTOPOLLER_ID, AUTOBETTER_ID, AUTOCHOICE_ID))
|
||||||
).join(
|
).join(
|
||||||
votes,
|
votes,
|
||||||
votes.c.comment_id == Comment.id,
|
votes.c.comment_id == Comment.id,
|
||||||
|
@ -186,6 +186,11 @@ def api_comment(v):
|
||||||
options.append(i.group(1))
|
options.append(i.group(1))
|
||||||
body = body.replace(i.group(0), "")
|
body = body.replace(i.group(0), "")
|
||||||
|
|
||||||
|
choices = []
|
||||||
|
for i in re.finditer('\s*##([^\$\n]+)##\s*', body, re.A):
|
||||||
|
choices.append(i.group(1))
|
||||||
|
body = body.replace(i.group(0), "")
|
||||||
|
|
||||||
if request.files.get("file") and request.headers.get("cf-ipcountry") != "T1":
|
if request.files.get("file") and request.headers.get("cf-ipcountry") != "T1":
|
||||||
file=request.files["file"]
|
file=request.files["file"]
|
||||||
if file.content_type.startswith('image/'):
|
if file.content_type.startswith('image/'):
|
||||||
|
@ -353,6 +358,17 @@ def api_comment(v):
|
||||||
|
|
||||||
g.db.add(c_option)
|
g.db.add(c_option)
|
||||||
|
|
||||||
|
for choice in choices:
|
||||||
|
c_choice = Comment(author_id=AUTOCHOICE_ID,
|
||||||
|
parent_submission=parent_submission,
|
||||||
|
parent_comment_id=c.id,
|
||||||
|
level=level+1,
|
||||||
|
body_html=filter_emojis_only(choice),
|
||||||
|
upvotes=0,
|
||||||
|
is_bot=True
|
||||||
|
)
|
||||||
|
|
||||||
|
g.db.add(c_choice)
|
||||||
|
|
||||||
if request.host == 'pcmemes.net' and c.body.lower().startswith("based"):
|
if request.host == 'pcmemes.net' and c.body.lower().startswith("based"):
|
||||||
pill = re.match("based and (.{1,20}?)(-| )pilled", body, re.IGNORECASE)
|
pill = re.match("based and (.{1,20}?)(-| )pilled", body, re.IGNORECASE)
|
||||||
|
@ -548,7 +564,8 @@ def api_comment(v):
|
||||||
|
|
||||||
for x in g.db.query(Subscription.user_id).filter_by(submission_id=c.parent_submission).all(): notify_users.add(x[0])
|
for x in g.db.query(Subscription.user_id).filter_by(submission_id=c.parent_submission).all(): notify_users.add(x[0])
|
||||||
|
|
||||||
if parent.author.id not in [v.id, BASEDBOT_ID, AUTOJANNY_ID, SNAPPY_ID, LONGPOSTBOT_ID, ZOZBOT_ID, AUTOPOLLER_ID]: notify_users.add(parent.author.id)
|
if parent.author.id not in (v.id, BASEDBOT_ID, AUTOJANNY_ID, SNAPPY_ID, LONGPOSTBOT_ID, ZOZBOT_ID, AUTOPOLLER_ID, AUTOCHOICE_ID):
|
||||||
|
notify_users.add(parent.author.id)
|
||||||
|
|
||||||
for x in notify_users:
|
for x in notify_users:
|
||||||
n = Notification(comment_id=c.id, user_id=x)
|
n = Notification(comment_id=c.id, user_id=x)
|
||||||
|
@ -685,6 +702,19 @@ def edit_comment(cid, v):
|
||||||
)
|
)
|
||||||
g.db.add(c_option)
|
g.db.add(c_option)
|
||||||
|
|
||||||
|
if not c.choices:
|
||||||
|
for i in re.finditer('\s*##([^\$\n]+)##\s*', body, re.A):
|
||||||
|
body = body.replace(i.group(0), "")
|
||||||
|
c_choice = Comment(author_id=AUTOCHOICE_ID,
|
||||||
|
parent_submission=c.parent_submission,
|
||||||
|
parent_comment_id=c.id,
|
||||||
|
level=c.level+1,
|
||||||
|
body_html=filter_emojis_only(i.group(1)),
|
||||||
|
upvotes=0,
|
||||||
|
is_bot=True
|
||||||
|
)
|
||||||
|
g.db.add(c_choice)
|
||||||
|
|
||||||
body_html = sanitize(body, edit=True)
|
body_html = sanitize(body, edit=True)
|
||||||
|
|
||||||
if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html, re.A))): return {"error":"You can only type marseys!"}, 403
|
if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html, re.A))): return {"error":"You can only type marseys!"}, 403
|
||||||
|
|
|
@ -315,9 +315,9 @@ def sign_up_post(v):
|
||||||
g.db.add(new_badge)
|
g.db.add(new_badge)
|
||||||
|
|
||||||
|
|
||||||
id_1 = g.db.query(User.id).filter_by(id=8).count()
|
id_1 = g.db.query(User.id).filter_by(id=9).count()
|
||||||
users_count = g.db.query(User.id).count()
|
users_count = g.db.query(User.id).count()
|
||||||
if id_1 == 0 and users_count == 7: admin_level=3
|
if id_1 == 0 and users_count == 8: admin_level=3
|
||||||
else: admin_level=0
|
else: admin_level=0
|
||||||
|
|
||||||
new_user = User(
|
new_user = User(
|
||||||
|
|
|
@ -5,7 +5,6 @@ from files.helpers.const import *
|
||||||
from files.classes import *
|
from files.classes import *
|
||||||
from flask import *
|
from flask import *
|
||||||
from files.__main__ import app, limiter
|
from files.__main__ import app, limiter
|
||||||
from sqlalchemy.orm import joinedload
|
|
||||||
|
|
||||||
@app.get("/authorize")
|
@app.get("/authorize")
|
||||||
@auth_required
|
@auth_required
|
||||||
|
@ -190,13 +189,9 @@ def admin_app_id(v, aid):
|
||||||
|
|
||||||
aid=aid
|
aid=aid
|
||||||
|
|
||||||
oauth = g.db.query(OauthApp).options(
|
oauth = g.db.query(OauthApp).filter_by(id=aid).one_or_none()
|
||||||
joinedload(
|
|
||||||
OauthApp.author)).filter_by(
|
|
||||||
id=aid).one_or_none()
|
|
||||||
|
|
||||||
pids=oauth.idlist(page=int(request.values.get("page",1)),
|
pids=oauth.idlist(page=int(request.values.get("page",1)))
|
||||||
)
|
|
||||||
|
|
||||||
next_exists=len(pids)==101
|
next_exists=len(pids)==101
|
||||||
pids=pids[:100]
|
pids=pids[:100]
|
||||||
|
@ -216,10 +211,7 @@ def admin_app_id_comments(v, aid):
|
||||||
|
|
||||||
aid=aid
|
aid=aid
|
||||||
|
|
||||||
oauth = g.db.query(OauthApp).options(
|
oauth = g.db.query(OauthApp).filter_by(id=aid).one_or_none()
|
||||||
joinedload(
|
|
||||||
OauthApp.author)).filter_by(
|
|
||||||
id=aid).one_or_none()
|
|
||||||
|
|
||||||
cids=oauth.comments_idlist(page=int(request.values.get("page",1)),
|
cids=oauth.comments_idlist(page=int(request.values.get("page",1)),
|
||||||
)
|
)
|
||||||
|
|
|
@ -148,7 +148,7 @@ def post_id(pid, anything=None, v=None, sub=None):
|
||||||
if not (v and v.shadowbanned) and not (v and v.admin_level > 1):
|
if not (v and v.shadowbanned) and not (v and v.admin_level > 1):
|
||||||
comments = comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None)
|
comments = comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None)
|
||||||
|
|
||||||
comments=comments.filter(Comment.parent_submission == post.id, Comment.author_id.notin_((AUTOPOLLER_ID, AUTOBETTER_ID))).join(
|
comments=comments.filter(Comment.parent_submission == post.id, Comment.author_id.notin_((AUTOPOLLER_ID, AUTOBETTER_ID, AUTOCHOICE_ID))).join(
|
||||||
votes,
|
votes,
|
||||||
votes.c.comment_id == Comment.id,
|
votes.c.comment_id == Comment.id,
|
||||||
isouter=True
|
isouter=True
|
||||||
|
@ -191,7 +191,7 @@ def post_id(pid, anything=None, v=None, sub=None):
|
||||||
else:
|
else:
|
||||||
pinned = g.db.query(Comment).filter(Comment.parent_submission == post.id, Comment.is_pinned != None).all()
|
pinned = g.db.query(Comment).filter(Comment.parent_submission == post.id, Comment.is_pinned != None).all()
|
||||||
|
|
||||||
comments = g.db.query(Comment).join(User, User.id == Comment.author_id).filter(User.shadowbanned == None, Comment.parent_submission == post.id, Comment.author_id.notin_((AUTOPOLLER_ID, AUTOBETTER_ID)), Comment.level == 1, Comment.is_pinned == None)
|
comments = g.db.query(Comment).join(User, User.id == Comment.author_id).filter(User.shadowbanned == None, Comment.parent_submission == post.id, Comment.author_id.notin_((AUTOPOLLER_ID, AUTOBETTER_ID, AUTOCHOICE_ID)), Comment.level == 1, Comment.is_pinned == None)
|
||||||
|
|
||||||
if sort == "new":
|
if sort == "new":
|
||||||
comments = comments.order_by(Comment.created_utc.desc())
|
comments = comments.order_by(Comment.created_utc.desc())
|
||||||
|
@ -271,7 +271,7 @@ def viewmore(v, pid, sort, offset):
|
||||||
votes.c.vote_type,
|
votes.c.vote_type,
|
||||||
blocking.c.id,
|
blocking.c.id,
|
||||||
blocked.c.id,
|
blocked.c.id,
|
||||||
).filter(Comment.parent_submission == pid, Comment.author_id.notin_((AUTOPOLLER_ID, AUTOBETTER_ID)), Comment.is_pinned == None, Comment.id.notin_(ids))
|
).filter(Comment.parent_submission == pid, Comment.author_id.notin_((AUTOPOLLER_ID, AUTOBETTER_ID, AUTOCHOICE_ID)), Comment.is_pinned == None, Comment.id.notin_(ids))
|
||||||
|
|
||||||
if not (v and v.shadowbanned) and not (v and v.admin_level > 1):
|
if not (v and v.shadowbanned) and not (v and v.admin_level > 1):
|
||||||
comments = comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None)
|
comments = comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None)
|
||||||
|
@ -315,7 +315,7 @@ def viewmore(v, pid, sort, offset):
|
||||||
second = [c[0] for c in comments.filter(or_(Comment.slots_result != None, Comment.blackjack_result != None), func.length(Comment.body) <= 50).all()]
|
second = [c[0] for c in comments.filter(or_(Comment.slots_result != None, Comment.blackjack_result != None), func.length(Comment.body) <= 50).all()]
|
||||||
comments = first + second
|
comments = first + second
|
||||||
else:
|
else:
|
||||||
comments = g.db.query(Comment).join(User, User.id == Comment.author_id).filter(User.shadowbanned == None, Comment.parent_submission == pid, Comment.author_id.notin_((AUTOPOLLER_ID, AUTOBETTER_ID)), Comment.level == 1, Comment.is_pinned == None, Comment.id.notin_(ids))
|
comments = g.db.query(Comment).join(User, User.id == Comment.author_id).filter(User.shadowbanned == None, Comment.parent_submission == pid, Comment.author_id.notin_((AUTOPOLLER_ID, AUTOBETTER_ID, AUTOCHOICE_ID)), Comment.level == 1, Comment.is_pinned == None, Comment.id.notin_(ids))
|
||||||
|
|
||||||
if sort == "new":
|
if sort == "new":
|
||||||
comments = comments.order_by(Comment.created_utc.desc())
|
comments = comments.order_by(Comment.created_utc.desc())
|
||||||
|
@ -474,6 +474,18 @@ def edit_post(pid, v):
|
||||||
)
|
)
|
||||||
g.db.add(c)
|
g.db.add(c)
|
||||||
|
|
||||||
|
if not p.choices.count():
|
||||||
|
for i in re.finditer('\s*##([^\$\n]+)##\s*', body, re.A):
|
||||||
|
body = body.replace(i.group(0), "")
|
||||||
|
c = Comment(author_id=AUTOCHOICE_ID,
|
||||||
|
parent_submission=p.id,
|
||||||
|
level=1,
|
||||||
|
body_html=filter_emojis_only(i.group(1)),
|
||||||
|
upvotes=0,
|
||||||
|
is_bot=True
|
||||||
|
)
|
||||||
|
g.db.add(c)
|
||||||
|
|
||||||
body_html = sanitize(body, edit=True)
|
body_html = sanitize(body, edit=True)
|
||||||
|
|
||||||
bans = filter_comment_html(body_html)
|
bans = filter_comment_html(body_html)
|
||||||
|
@ -960,6 +972,11 @@ def submit_post(v, sub=None):
|
||||||
options.append(i.group(1))
|
options.append(i.group(1))
|
||||||
body = body.replace(i.group(0), "")
|
body = body.replace(i.group(0), "")
|
||||||
|
|
||||||
|
choices = []
|
||||||
|
for i in re.finditer('\s*##([^\$\n]+)##\s*', body, re.A):
|
||||||
|
choices.append(i.group(1))
|
||||||
|
body = body.replace(i.group(0), "")
|
||||||
|
|
||||||
if v.agendaposter and not v.marseyawarded: body = torture_ap(body, v.username)
|
if v.agendaposter and not v.marseyawarded: body = torture_ap(body, v.username)
|
||||||
|
|
||||||
if request.files.get("file2") and request.headers.get("cf-ipcountry") != "T1":
|
if request.files.get("file2") and request.headers.get("cf-ipcountry") != "T1":
|
||||||
|
@ -1047,7 +1064,16 @@ def submit_post(v, sub=None):
|
||||||
upvotes=0,
|
upvotes=0,
|
||||||
is_bot=True
|
is_bot=True
|
||||||
)
|
)
|
||||||
|
g.db.add(c)
|
||||||
|
|
||||||
|
for choice in choices:
|
||||||
|
c = Comment(author_id=AUTOCHOICE_ID,
|
||||||
|
parent_submission=new_post.id,
|
||||||
|
level=1,
|
||||||
|
body_html=filter_emojis_only(choice),
|
||||||
|
upvotes=0,
|
||||||
|
is_bot=True
|
||||||
|
)
|
||||||
g.db.add(c)
|
g.db.add(c)
|
||||||
|
|
||||||
vote = Vote(user_id=v.id,
|
vote = Vote(user_id=v.id,
|
||||||
|
|
|
@ -4,7 +4,6 @@ from files.helpers.const import *
|
||||||
from files.classes import *
|
from files.classes import *
|
||||||
from flask import *
|
from flask import *
|
||||||
from files.__main__ import app, limiter, cache
|
from files.__main__ import app, limiter, cache
|
||||||
from sqlalchemy.orm import joinedload
|
|
||||||
from os import environ
|
from os import environ
|
||||||
|
|
||||||
@app.get("/votes")
|
@app.get("/votes")
|
||||||
|
@ -29,30 +28,18 @@ def admin_vote_info_get(v):
|
||||||
thing_id = g.db.query(Submission.id).filter_by(upvotes=thing.upvotes, downvotes=thing.downvotes).order_by(Submission.id).first()[0]
|
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
|
ups = g.db.query(Vote).filter_by(submission_id=thing_id, vote_type=1).order_by(Vote.id).all()
|
||||||
).options(joinedload(Vote.user)
|
|
||||||
).filter_by(submission_id=thing_id, vote_type=1
|
|
||||||
).order_by(Vote.id).all()
|
|
||||||
|
|
||||||
downs = g.db.query(Vote
|
downs = g.db.query(Vote).filter_by(submission_id=thing_id, vote_type=-1).order_by(Vote.id).all()
|
||||||
).options(joinedload(Vote.user)
|
|
||||||
).filter_by(submission_id=thing_id, vote_type=-1
|
|
||||||
).order_by(Vote.id).all()
|
|
||||||
|
|
||||||
elif isinstance(thing, Comment):
|
elif isinstance(thing, Comment):
|
||||||
if thing.author.shadowbanned and not (v and v.admin_level):
|
if thing.author.shadowbanned and not (v and v.admin_level):
|
||||||
thing_id = g.db.query(Comment.id).filter_by(upvotes=thing.upvotes, downvotes=thing.downvotes).order_by(Comment.id).first()[0]
|
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
|
ups = g.db.query(CommentVote).filter_by(comment_id=thing_id, vote_type=1).order_by(CommentVote.id).all()
|
||||||
).options(joinedload(CommentVote.user)
|
|
||||||
).filter_by(comment_id=thing_id, vote_type=1
|
|
||||||
).order_by(CommentVote.id).all()
|
|
||||||
|
|
||||||
downs = g.db.query(CommentVote
|
downs = g.db.query(CommentVote).filter_by(comment_id=thing_id, vote_type=-1 ).order_by(CommentVote.id).all()
|
||||||
).options(joinedload(CommentVote.user)
|
|
||||||
).filter_by(comment_id=thing_id, vote_type=-1
|
|
||||||
).order_by(CommentVote.id).all()
|
|
||||||
|
|
||||||
else: abort(400)
|
else: abort(400)
|
||||||
|
|
||||||
|
@ -249,3 +236,35 @@ def bet(comment_id, v):
|
||||||
|
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
return "", 204
|
return "", 204
|
||||||
|
|
||||||
|
@app.post("/vote/choice/<comment_id>")
|
||||||
|
@auth_required
|
||||||
|
def api_vote_choice(comment_id, v):
|
||||||
|
|
||||||
|
comment_id = int(comment_id)
|
||||||
|
comment = get_comment(comment_id)
|
||||||
|
|
||||||
|
existing = g.db.query(CommentVote).filter_by(user_id=v.id, comment_id=comment.id).one_or_none()
|
||||||
|
|
||||||
|
if existing and existing.vote_type == 1: return "", 204
|
||||||
|
|
||||||
|
if existing:
|
||||||
|
existing.vote_type = 1
|
||||||
|
g.db.add(existing)
|
||||||
|
else:
|
||||||
|
vote = CommentVote(user_id=v.id, vote_type=1, comment_id=comment.id)
|
||||||
|
g.db.add(vote)
|
||||||
|
|
||||||
|
if comment.parent_comment: parent = comment.parent_comment
|
||||||
|
else: parent = comment.post
|
||||||
|
|
||||||
|
for vote in parent.total_choice_voted(v):
|
||||||
|
g.db.delete(vote)
|
||||||
|
|
||||||
|
try:
|
||||||
|
g.db.flush()
|
||||||
|
comment.upvotes = g.db.query(CommentVote.id).filter_by(comment_id=comment.id, vote_type=1).count()
|
||||||
|
g.db.add(comment)
|
||||||
|
g.db.commit()
|
||||||
|
except: g.db.rollback()
|
||||||
|
return "", 204
|
|
@ -908,7 +908,7 @@
|
||||||
|
|
||||||
{% if v %}
|
{% if v %}
|
||||||
<script src="/static/assets/js/marked.js?a=240"></script>
|
<script src="/static/assets/js/marked.js?a=240"></script>
|
||||||
<script src="/static/assets/js/comments_v.js?a=240"></script>
|
<script src="/static/assets/js/comments_v.js?a=241"></script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<script src="/static/assets/js/clipboard.js?a=240"></script>
|
<script src="/static/assets/js/clipboard.js?a=240"></script>
|
||||||
|
|
|
@ -272,7 +272,7 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
{% if request.path in ('/', '/logged_out', '/logged_out/') or SITE_NAME == '2Much4You' %}
|
{% if request.path in ('/', '/logged_out', '/logged_out/') or sub %}
|
||||||
{% block sidebar %}
|
{% block sidebar %}
|
||||||
{% include "sidebar_" + SITE_NAME + ".html" %}
|
{% include "sidebar_" + SITE_NAME + ".html" %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
<nav class="shadow shadow-md fixed-top">
|
<nav class="shadow shadow-md fixed-top">
|
||||||
{% if SITE_NAME == 'Drama' or subs %}
|
{% if SITE_NAME == 'Drama' or SUBS %}
|
||||||
<style>
|
<style>
|
||||||
body {padding-top: 85.88px !important}
|
body {padding-top: 85.88px !important}
|
||||||
@media (max-width: 767.98px) {
|
@media (max-width: 767.98px) {
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
<div id="srd" style="width: 100%; background-color: var(--primary); padding: 2px; text-align: center; font-weight: bold;white-space:nowrap">
|
<div id="srd" style="width: 100%; background-color: var(--primary); padding: 2px; text-align: center; font-weight: bold;white-space:nowrap">
|
||||||
<a style="color: white" class="text-small-mobile" href="https://reddit.com/r/SubredditDrama">💖🌈 welcome to rdrama.net: the official site for r/subredditdrama</a>
|
<a style="color: white" class="text-small-mobile" href="https://reddit.com/r/SubredditDrama">💖🌈 welcome to rdrama.net: the official site for r/subredditdrama</a>
|
||||||
</div>
|
</div>
|
||||||
{% elif subs %}
|
{% elif SUBS %}
|
||||||
<div id="srd" style="width: 100%; background-color: var(--primary); padding: 2px; text-align: left; font-weight: bold;white-space:nowrap">
|
<div id="srd" style="width: 100%; background-color: var(--primary); padding: 2px; text-align: left; font-weight: bold;white-space:nowrap">
|
||||||
{% for s in SUBS %}
|
{% for s in SUBS %}
|
||||||
<a {% if sub and s == sub.name %} style="color: var(--secondary)" {% else %} style="color: white"{% endif %} class="text-small-mobile ml-2" href="/s/{{s}}">/s/{{s}}</a>
|
<a {% if sub and s == sub.name %} style="color: var(--secondary)" {% else %} style="color: white"{% endif %} class="text-small-mobile ml-2" href="/s/{{s}}">/s/{{s}}</a>
|
||||||
|
|
|
@ -33,6 +33,10 @@ INSERT INTO public.users (
|
||||||
0, 'AutoBetter', '', 'hot', 'top', 'day', '62ca56', 'e4432d', '', '',
|
0, 'AutoBetter', '', 'hot', 'top', 'day', '62ca56', 'e4432d', '', '',
|
||||||
'', 'dark', '30409f', false, false, '', '', 0, false, 0,
|
'', 'dark', '30409f', false, false, '', '', 0, false, 0,
|
||||||
0, 0, '', true, 0);
|
0, 0, '', true, 0);
|
||||||
|
(8, 'AutoChoice', '', 0, 0, true, true, '', '', 0, false,
|
||||||
|
0, 'AutoChoice', '', 'hot', 'top', 'day', '62ca56', 'e4432d', '', '',
|
||||||
|
'', 'dark', '30409f', false, false, '', '', 0, false, 0,
|
||||||
|
0, 0, '', true, 0);
|
||||||
|
|
||||||
SELECT pg_catalog.setval('public.users_id_seq', 7, true);
|
SELECT pg_catalog.setval('public.users_id_seq', 7, true);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue