dfsfsd
This commit is contained in:
parent
c35f72f31e
commit
79d18747c1
8 changed files with 95 additions and 15 deletions
|
@ -187,7 +187,7 @@ class Comment(Base):
|
||||||
def replies(self):
|
def replies(self):
|
||||||
r = self.__dict__.get("replies", None)
|
r = self.__dict__.get("replies", None)
|
||||||
if r: r = [x for x in r if not x.author.shadowbanned]
|
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 != AUTOPOLLER_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.notin_((AUTOPOLLER_ID, AUTOBETTER_ID))], key=lambda x: x.score, reverse=True)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
@replies.setter
|
@replies.setter
|
||||||
|
@ -205,7 +205,7 @@ class Comment(Base):
|
||||||
@property
|
@property
|
||||||
def replies3(self):
|
def replies3(self):
|
||||||
r = self.__dict__.get("replies", None)
|
r = self.__dict__.get("replies", None)
|
||||||
if not r and r != []: r = sorted([x for x in self.child_comments if x.author_id != AUTOPOLLER_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.notin_((AUTOPOLLER_ID, AUTOBETTER_ID))], key=lambda x: x.score, reverse=True)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -7,7 +7,7 @@ from flask import render_template
|
||||||
from sqlalchemy import *
|
from sqlalchemy import *
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
from files.__main__ import Base
|
from files.__main__ import Base
|
||||||
from files.helpers.const import AUTOPOLLER_ID, censor_slurs, TROLLTITLES
|
from files.helpers.const import AUTOPOLLER_ID, AUTOBETTER_ID, censor_slurs, TROLLTITLES
|
||||||
from files.helpers.lazy import lazy
|
from files.helpers.lazy import lazy
|
||||||
from .flags import Flag
|
from .flags import Flag
|
||||||
from .comment import Comment
|
from .comment import Comment
|
||||||
|
@ -84,9 +84,20 @@ 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 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())
|
||||||
|
|
||||||
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 + self.bet_options:
|
||||||
|
if option.poll_voted(v): return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def total_bet_voted(self, v):
|
||||||
|
if v:
|
||||||
|
for option in self.bet_options:
|
||||||
if option.poll_voted(v): return True
|
if option.poll_voted(v): return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
@ -136,6 +136,7 @@ if SITE == 'rdrama.net':
|
||||||
LONGPOSTBOT_ID = 1832
|
LONGPOSTBOT_ID = 1832
|
||||||
ZOZBOT_ID = 1833
|
ZOZBOT_ID = 1833
|
||||||
AUTOPOLLER_ID = 6176
|
AUTOPOLLER_ID = 6176
|
||||||
|
AUTOBETTER_ID = 7668
|
||||||
TAX_RECEIVER_ID = 747
|
TAX_RECEIVER_ID = 747
|
||||||
PIZZA_SHILL_ID = 2424
|
PIZZA_SHILL_ID = 2424
|
||||||
IDIO_ID = 30
|
IDIO_ID = 30
|
||||||
|
@ -158,6 +159,7 @@ elif SITE == "pcmemes.net":
|
||||||
LONGPOSTBOT_ID = 1832
|
LONGPOSTBOT_ID = 1832
|
||||||
ZOZBOT_ID = 1833
|
ZOZBOT_ID = 1833
|
||||||
AUTOPOLLER_ID = 3369
|
AUTOPOLLER_ID = 3369
|
||||||
|
AUTOBETTER_ID = 0
|
||||||
TAX_RECEIVER_ID = 1592
|
TAX_RECEIVER_ID = 1592
|
||||||
PIZZA_SHILL_ID = 0
|
PIZZA_SHILL_ID = 0
|
||||||
IDIO_ID = 0
|
IDIO_ID = 0
|
||||||
|
@ -180,7 +182,8 @@ else:
|
||||||
LONGPOSTBOT_ID = 4
|
LONGPOSTBOT_ID = 4
|
||||||
ZOZBOT_ID = 5
|
ZOZBOT_ID = 5
|
||||||
AUTOPOLLER_ID = 6
|
AUTOPOLLER_ID = 6
|
||||||
TAX_RECEIVER_ID = 7
|
AUTOBETTER_ID = 7
|
||||||
|
TAX_RECEIVER_ID = 8
|
||||||
PIZZA_SHILL_ID = 0
|
PIZZA_SHILL_ID = 0
|
||||||
IDIO_ID = 0
|
IDIO_ID = 0
|
||||||
CARP_ID = 0
|
CARP_ID = 0
|
||||||
|
|
|
@ -96,7 +96,7 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None):
|
||||||
|
|
||||||
comments=comments.filter(
|
comments=comments.filter(
|
||||||
Comment.parent_submission == post.id,
|
Comment.parent_submission == post.id,
|
||||||
Comment.author_id != AUTOPOLLER_ID
|
Comment.author_id.notin_((AUTOPOLLER_ID, AUTOBETTER_ID))
|
||||||
).join(
|
).join(
|
||||||
votes,
|
votes,
|
||||||
votes.c.comment_id == Comment.id,
|
votes.c.comment_id == Comment.id,
|
||||||
|
|
|
@ -129,7 +129,7 @@ def post_id(pid, anything=None, v=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 != AUTOPOLLER_ID).join(
|
comments=comments.filter(Comment.parent_submission == post.id, Comment.author_id.notin_((AUTOPOLLER_ID, AUTOBETTER_ID))).join(
|
||||||
votes,
|
votes,
|
||||||
votes.c.comment_id == Comment.id,
|
votes.c.comment_id == Comment.id,
|
||||||
isouter=True
|
isouter=True
|
||||||
|
@ -170,7 +170,7 @@ def post_id(pid, anything=None, v=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 != AUTOPOLLER_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)), 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())
|
||||||
|
@ -244,7 +244,7 @@ def viewmore(v, pid, sort, offset):
|
||||||
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 == pid, Comment.author_id != AUTOPOLLER_ID, Comment.is_pinned == None).join(
|
comments=comments.filter(Comment.parent_submission == pid, Comment.author_id.notin_((AUTOPOLLER_ID, AUTOBETTER_ID)), Comment.is_pinned == None).join(
|
||||||
votes,
|
votes,
|
||||||
votes.c.comment_id == Comment.id,
|
votes.c.comment_id == Comment.id,
|
||||||
isouter=True
|
isouter=True
|
||||||
|
@ -283,7 +283,7 @@ def viewmore(v, pid, sort, offset):
|
||||||
|
|
||||||
comments = [c[0] for c in comments.all()]
|
comments = [c[0] for c in comments.all()]
|
||||||
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 != AUTOPOLLER_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 == pid, Comment.author_id.notin_((AUTOPOLLER_ID, AUTOBETTER_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())
|
||||||
|
@ -902,6 +902,11 @@ def submit_post(v):
|
||||||
for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', body, re.MULTILINE):
|
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'})')
|
if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'})')
|
||||||
|
|
||||||
|
bet_options = []
|
||||||
|
for i in re.finditer('\s*\$\$\$([^\$\n]+)\$\$\$\s*', body):
|
||||||
|
bet_options.append(i.group(1))
|
||||||
|
body = body.replace(i.group(0), "")
|
||||||
|
|
||||||
options = []
|
options = []
|
||||||
for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body):
|
for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body):
|
||||||
options.append(i.group(1))
|
options.append(i.group(1))
|
||||||
|
@ -964,6 +969,16 @@ def submit_post(v):
|
||||||
g.db.add(new_post)
|
g.db.add(new_post)
|
||||||
g.db.flush()
|
g.db.flush()
|
||||||
|
|
||||||
|
for option in bet_options:
|
||||||
|
bet_option = Comment(author_id=AUTOBETTER_ID,
|
||||||
|
parent_submission=new_post.id,
|
||||||
|
level=1,
|
||||||
|
body_html=filter_emojis_only(option),
|
||||||
|
upvotes=0
|
||||||
|
)
|
||||||
|
|
||||||
|
g.db.add(bet_option)
|
||||||
|
|
||||||
for option in options:
|
for option in options:
|
||||||
c = Comment(author_id=AUTOPOLLER_ID,
|
c = Comment(author_id=AUTOPOLLER_ID,
|
||||||
parent_submission=new_post.id,
|
parent_submission=new_post.id,
|
||||||
|
|
|
@ -227,3 +227,29 @@ def api_vote_poll(comment_id, v):
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
except: g.db.rollback()
|
except: g.db.rollback()
|
||||||
return "", 204
|
return "", 204
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/bet/<comment_id>")
|
||||||
|
@limiter.limit("1/second")
|
||||||
|
@auth_required
|
||||||
|
@validate_formkey
|
||||||
|
def bet(comment_id, v):
|
||||||
|
|
||||||
|
if v.coins < 200: return {"error": "You don't have 200 coins!"}
|
||||||
|
|
||||||
|
vote = request.values.get("vote")
|
||||||
|
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).first()
|
||||||
|
if existing: return "", 204
|
||||||
|
|
||||||
|
vote = CommentVote(user_id=v.id, vote_type=1, comment_id=comment.id)
|
||||||
|
g.db.add(vote)
|
||||||
|
v.coins -= 200
|
||||||
|
g.db.add(v)
|
||||||
|
comment.upvotes += 1
|
||||||
|
g.db.add(comment)
|
||||||
|
|
||||||
|
g.db.commit()
|
||||||
|
return "", 204
|
|
@ -13,6 +13,19 @@
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function bet_vote(cid) {
|
||||||
|
for(let el of document.getElementsByClassName('bet')) {
|
||||||
|
el.disabled = true;
|
||||||
|
}
|
||||||
|
var scoretext = document.getElementById('bet-' + cid);
|
||||||
|
var score = Number(scoretext.textContent);
|
||||||
|
scoretext.textContent = score + 1;
|
||||||
|
post('/bet/' + cid);
|
||||||
|
document.getElementById("user-coins-amount").innerText = parseInt(document.getElementById("user-coins-amount").innerText) - 200;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
{% if p.award_count("train") %}
|
{% if p.award_count("train") %}
|
||||||
<style>
|
<style>
|
||||||
@keyframes train {
|
@keyframes train {
|
||||||
|
@ -419,13 +432,15 @@
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
{% for c in p.bet_options %}
|
||||||
|
<span {% if c.poll_voted(v) %}class="bet_voted"{% endif %}><input {% if c.poll_voted(v) %}checked{% endif %} class="bet" {% if not (v and v.coins > 200) or p.total_bet_voted(v) %}disabled{% endif %} type="radio" id="{{c.id}}" onchange="bet_vote('{{c.id}}')"></span>
|
||||||
|
<label for="{{c.id}}">{{c.body_html | safe}} - <a href="/votes?link=t3_{{c.id}}"><span id="bet-{{c.id}}">{{c.upvotes}}</span> bets</a>{% if not p.total_bet_voted(v) %} (cost of entry: 200 coins){% endif %}</label><br>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
{% if p.is_banned and p.ban_reason %}
|
{% if p.is_banned and p.ban_reason %}
|
||||||
<div class="text-removed mb-0">removed by @{{p.ban_reason}}</div>
|
<div class="text-removed mb-0">removed by @{{p.ban_reason}}</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
@ -830,4 +845,10 @@
|
||||||
})()
|
})()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.bet_voted {
|
||||||
|
border-radius: 40%;
|
||||||
|
background: var(--primary);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -29,6 +29,10 @@ INSERT INTO public.users (
|
||||||
0, 'AutoPoller', '', 'hot', 'top', 'day', '62ca56', 'e4432d', '', '',
|
0, 'AutoPoller', '', '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);
|
||||||
|
(7, 'AutoBetter', '', 0, 0, true, true, '', '', 0, false,
|
||||||
|
0, 'AutoBetter', '', 'hot', 'top', 'day', '62ca56', 'e4432d', '', '',
|
||||||
|
'', 'dark', '30409f', false, false, '', '', 0, false, 0,
|
||||||
|
0, 0, '', true, 0);
|
||||||
|
|
||||||
|
|
||||||
SELECT pg_catalog.setval('public.users_id_seq', 6, true);
|
SELECT pg_catalog.setval('public.users_id_seq', 6, true);
|
Loading…
Add table
Add a link
Reference in a new issue