remotes/1693045480750635534/spooky-22
Aevann1 2021-10-07 06:03:54 +02:00
parent 97c98e9c29
commit 409f77d021
6 changed files with 63 additions and 45 deletions

View File

@ -10,6 +10,7 @@ from files.__main__ import Base
from .flags import CommentFlag
from os import environ
import time
from files.helpers.const import AUTOPOLLER_ACCOUNT
site = environ.get("DOMAIN").strip()
@ -169,7 +170,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], 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 != AUTOPOLLER_ACCOUNT], key=lambda x: x.score, reverse=True)
return r
@replies.setter
@ -187,7 +188,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], 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 != AUTOPOLLER_ACCOUNT], key=lambda x: x.score, reverse=True)
return r
@property

View File

@ -195,7 +195,20 @@ class Submission(Base):
if self.is_banned and not (v and (v.admin_level >= 3 or self.author_id == v.id)): template = "submission_banned.html"
else: template = "submission.html"
self.tree_comments(comment=comment)
comments = self.__dict__.get('preloaded_comments', [])
if comments:
pinned_comment = []
index = {}
for c in comments:
if c.is_pinned and c.parent_fullname==self.fullname:
pinned_comment += [c]
continue
if c.parent_fullname in index: index[c.parent_fullname].append(c)
else: index[c.parent_fullname] = [c]
for c in comments: c.__dict__["replies"] = index.get(c.fullname, [])
if comment: self.__dict__["replies"] = [comment]
else: self.__dict__["replies"] = pinned_comment + index.get(self.fullname, [])
return render_template(template,
v=v,
@ -215,27 +228,6 @@ class Submission(Base):
if domain.startswith("www."): domain = domain.split("www.")[1]
return domain.replace("old.reddit.com", "reddit.com")
def tree_comments(self, comment=None, v=None):
comments = self.__dict__.get('preloaded_comments', [])
if not comments: return
pinned_comment=[]
index = {}
for c in comments:
if c.is_pinned and c.parent_fullname==self.fullname:
pinned_comment += [c]
continue
if c.parent_fullname in index: index[c.parent_fullname].append(c)
else: index[c.parent_fullname] = [c]
for c in comments: c.__dict__["replies"] = index.get(c.fullname, [])
if comment: self.__dict__["replies"] = [comment]
else: self.__dict__["replies"] = pinned_comment + index.get(self.fullname, [])
@property
@lazy

View File

@ -9,7 +9,6 @@ from files.routes.front import comment_idlist
from pusher_push_notifications import PushNotifications
from flask import *
from files.__main__ import app, limiter
from urllib.parse import ParseResult, urlunparse, urlparse
site = environ.get("DOMAIN").strip()
@ -90,7 +89,8 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None):
comments = comments.filter(Comment.author_id.notin_(shadowbanned))
comments=comments.filter(
Comment.parent_submission == post.id
Comment.parent_submission == post.id,
Comment.author_id != AUTOPOLLER_ACCOUNT
).join(
votes,
votes.c.comment_id == Comment.id,
@ -152,6 +152,12 @@ def api_comment(v):
for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', body, re.MULTILINE):
if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'![]({i.group(1)})')
body = re.sub('([^\n])\n([^\n])', r'\1\n\n\2', body)
options = []
for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body):
options.append(i.group(1))
body = body.replace(i.group(0), "")
body_md = CustomRenderer().render(mistletoe.Document(body))
body_html = sanitize(body_md)
@ -263,6 +269,17 @@ def api_comment(v):
g.db.add(c)
g.db.flush()
for option in options:
c_option = Comment(author_id=AUTOPOLLER_ACCOUNT,
parent_submission=parent_submission,
parent_comment_id=c.id,
level=level+1,
body=option
)
g.db.add(c_option)
if 'pcmemes.net' in request.host and c.body.lower().startswith("based"):
pill = re.match("based and (.{1,20}?)(-| )pilled", body, re.IGNORECASE)

View File

@ -763,7 +763,6 @@ def submit_post(v):
)
g.db.add(c)
g.db.flush()
vote = Vote(user_id=v.id,
vote_type=1,
@ -772,8 +771,6 @@ def submit_post(v):
g.db.add(vote)
g.db.flush()
g.db.refresh(new_post)
if request.files.get('file') and request.headers.get("cf-ipcountry") != "T1":
file = request.files['file']

View File

@ -66,6 +66,26 @@
{% include "expanded_image_modal.html" %}
<script>
function poll_vote(cid) {
{% if v %}
var type = document.getElementById(cid).checked;
var scoretext = document.getElementById('poll-' + cid);
var score = Number(scoretext.textContent);
if (type == true) scoretext.textContent = score + 1;
else scoretext.textContent = score - 1;
post('/vote/poll/' + cid + '?vote=' + type);
{% else %}
var myToast = new bootstrap.Toast(document.getElementById('toast-post-error'));
myToast.show();
document.getElementById('toast-post-error-text').innerText = "Only logged-in users can vote!";
{% endif %}
}
</script>
{% macro single_comment(c, level=1) %}
{% if p and not (v and v.id==c.author_id) and (not v or v.highlightcomments) %}
@ -245,6 +265,13 @@
<div id="comment-text-{{c.id}}" class="comment-text mb-0">
{{c.realbody(v) | safe}}
{% for c in c.options %}
<div class="custom-control">
<input type="checkbox" class="custom-control-input" id="{{c.id}}" name="option" {% if c.poll_voted(v) %}checked{% endif %} onchange="poll_vote('{{c.id}}')">
<label class="custom-control-label" for="{{c.id}}">{{c.body}} - <a href="/votes?link=t3_{{c.id}}"><span id="poll-{{c.id}}">{{c.upvotes}}</span> votes</a></label>
</div>
{% endfor %}
{% if not c.parent_submission and c.author_id!=NOTIFICATIONS_ACCOUNT and c.author_id!=AUTOJANNY_ACCOUNT and c.author_id!=v.id %}
<a class="btn btn-primary" href="javascript:void(0)" onclick="document.getElementById('reply-m-{{c.id}}').classList.toggle('d-none')">Reply</a>
<pre></pre>

View File

@ -15,22 +15,6 @@
<script src="https://cdn.jsdelivr.net/npm/clipboard@2.0.8/dist/clipboard.min.js"></script>
<script src="/assets/js/new_comments_count.js?v=10"></script>
<script>
function poll_vote(cid) {
{% if v %}
var type = document.getElementById(cid).checked;
var scoretext = document.getElementById('poll-' + cid);
var score = Number(scoretext.textContent);
if (type == true) scoretext.textContent = score + 1;
else scoretext.textContent = score - 1;
post('/vote/poll/' + cid + '?vote=' + type);
{% else %}
var myToast = new bootstrap.Toast(document.getElementById('toast-post-error'));
myToast.show();
document.getElementById('toast-post-error-text').innerText = "Only logged-in users can vote!";
{% endif %}
}
</script>
{% if v and v.id == p.author_id %}
<script>