From 71392c0550abc3e1c25f0b42db81e7aaea88dc66 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 11 Dec 2021 02:59:37 +0200 Subject: [PATCH 1/5] fdsfds --- files/templates/default.html | 4 ---- files/templates/header.html | 6 +++++- files/templates/settings_blocks.html | 4 ---- files/templates/settings_profile.html | 4 ---- 4 files changed, 5 insertions(+), 13 deletions(-) diff --git a/files/templates/default.html b/files/templates/default.html index c81561c22c..d45c7b586b 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -296,10 +296,6 @@ -{% if v %} -
{{v.formkey}}
-{% endif %} - diff --git a/files/templates/header.html b/files/templates/header.html index 016ad31494..77ad984cdb 100644 --- a/files/templates/header.html +++ b/files/templates/header.html @@ -223,4 +223,8 @@ padding: 2px 5px; font-weight: 700; } - \ No newline at end of file + + +{% if v %} +
{{v.formkey}}
+{% endif %} \ No newline at end of file diff --git a/files/templates/settings_blocks.html b/files/templates/settings_blocks.html index a980a3e9b3..35df3e619c 100644 --- a/files/templates/settings_blocks.html +++ b/files/templates/settings_blocks.html @@ -121,8 +121,4 @@ -{% if v %} -
{{v.formkey}}
-{% endif %} - {% endblock %} \ No newline at end of file diff --git a/files/templates/settings_profile.html b/files/templates/settings_profile.html index 5aefece6fd..a68d0bd8a7 100644 --- a/files/templates/settings_profile.html +++ b/files/templates/settings_profile.html @@ -687,8 +687,4 @@ {% include "emoji_modal.html" %} {% include "gif_modal.html" %} -{% if v %} -
{{v.formkey}}
-{% endif %} - {% endblock %} From 34657d207d2e4cc4d1d31cf6ba1a1aaf90ed6c90 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 11 Dec 2021 04:27:46 +0200 Subject: [PATCH 2/5] dfsfsd --- files/classes/comment.py | 4 ++-- files/classes/submission.py | 15 +++++++++++++-- files/helpers/const.py | 5 ++++- files/routes/comments.py | 2 +- files/routes/posts.py | 25 ++++++++++++++++++++----- files/routes/votes.py | 26 ++++++++++++++++++++++++++ files/templates/submission.html | 29 +++++++++++++++++++++++++---- seed-db.sql | 4 ++++ 8 files changed, 95 insertions(+), 15 deletions(-) diff --git a/files/classes/comment.py b/files/classes/comment.py index 4478e9052a..0c427098ab 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -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 != 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 @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 != 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 @property diff --git a/files/classes/submission.py b/files/classes/submission.py index 5d9c62593d..0fb9c1abfd 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -7,7 +7,7 @@ from flask import render_template from sqlalchemy import * from sqlalchemy.orm import relationship 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 .flags import Flag from .comment import Comment @@ -84,9 +84,20 @@ class Submission(Base): def options(self): 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): 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 return False diff --git a/files/helpers/const.py b/files/helpers/const.py index 4bf178b31f..7a3e89b630 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -136,6 +136,7 @@ if SITE == 'rdrama.net': LONGPOSTBOT_ID = 1832 ZOZBOT_ID = 1833 AUTOPOLLER_ID = 6176 + AUTOBETTER_ID = 7668 TAX_RECEIVER_ID = 747 PIZZA_SHILL_ID = 2424 IDIO_ID = 30 @@ -158,6 +159,7 @@ elif SITE == "pcmemes.net": LONGPOSTBOT_ID = 1832 ZOZBOT_ID = 1833 AUTOPOLLER_ID = 3369 + AUTOBETTER_ID = 0 TAX_RECEIVER_ID = 1592 PIZZA_SHILL_ID = 0 IDIO_ID = 0 @@ -180,7 +182,8 @@ else: LONGPOSTBOT_ID = 4 ZOZBOT_ID = 5 AUTOPOLLER_ID = 6 - TAX_RECEIVER_ID = 7 + AUTOBETTER_ID = 7 + TAX_RECEIVER_ID = 8 PIZZA_SHILL_ID = 0 IDIO_ID = 0 CARP_ID = 0 diff --git a/files/routes/comments.py b/files/routes/comments.py index e55fb5a5c0..0c58cb7698 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -96,7 +96,7 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None): comments=comments.filter( Comment.parent_submission == post.id, - Comment.author_id != AUTOPOLLER_ID + Comment.author_id.notin_((AUTOPOLLER_ID, AUTOBETTER_ID)) ).join( votes, votes.c.comment_id == Comment.id, diff --git a/files/routes/posts.py b/files/routes/posts.py index cb1c1f7f90..9d02019f3f 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -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): 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.c.comment_id == Comment.id, isouter=True @@ -170,7 +170,7 @@ def post_id(pid, anything=None, v=None): else: 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": 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): 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.c.comment_id == Comment.id, isouter=True @@ -283,7 +283,7 @@ def viewmore(v, pid, sort, offset): comments = [c[0] for c in comments.all()] 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": 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): if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'![]({i.group(1)})') + bet_options = [] + for i in re.finditer('\s*\$\$\$([^\$\n]+)\$\$\$\s*', body): + bet_options.append(i.group(1)) + body = body.replace(i.group(0), "") + options = [] for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body): options.append(i.group(1)) @@ -963,7 +968,17 @@ def submit_post(v): g.db.add(new_post) 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: c = Comment(author_id=AUTOPOLLER_ID, parent_submission=new_post.id, diff --git a/files/routes/votes.py b/files/routes/votes.py index 199f0b5a4e..614058ab76 100644 --- a/files/routes/votes.py +++ b/files/routes/votes.py @@ -226,4 +226,30 @@ def api_vote_poll(comment_id, v): g.db.add(comment) g.db.commit() except: g.db.rollback() + return "", 204 + + +@app.post("/bet/") +@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 \ No newline at end of file diff --git a/files/templates/submission.html b/files/templates/submission.html index c74c3e8af8..eadf02e104 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -13,6 +13,19 @@ {% block title %} + + {% if p.award_count("train") %} {% endblock %} \ No newline at end of file diff --git a/seed-db.sql b/seed-db.sql index 2e5252333e..2e5ee11a24 100644 --- a/seed-db.sql +++ b/seed-db.sql @@ -29,6 +29,10 @@ INSERT INTO public.users ( 0, 'AutoPoller', '', 'hot', 'top', 'day', '62ca56', 'e4432d', '', '', '', 'dark', '30409f', false, false, '', '', 0, false, 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); \ No newline at end of file From 667083f3878398e77287c3005c6c08dd48319420 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 11 Dec 2021 04:32:21 +0200 Subject: [PATCH 3/5] dfsfds --- files/routes/votes.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/files/routes/votes.py b/files/routes/votes.py index 614058ab76..dee8213687 100644 --- a/files/routes/votes.py +++ b/files/routes/votes.py @@ -246,10 +246,15 @@ def bet(comment_id, v): 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) + v.coins -= 200 + g.db.add(v) + autobetter = g.db.query(User).filter_by(id=AUTOBETTER_ID).first() + autobetter.coins += 200 + g.db.add(autobetter) + g.db.commit() return "", 204 \ No newline at end of file From c178caab06e9d4cefc29fb958d40430bd8179ef5 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 11 Dec 2021 04:32:58 +0200 Subject: [PATCH 4/5] fdsfds --- files/routes/votes.py | 1 + 1 file changed, 1 insertion(+) diff --git a/files/routes/votes.py b/files/routes/votes.py index dee8213687..f49d72ab70 100644 --- a/files/routes/votes.py +++ b/files/routes/votes.py @@ -1,5 +1,6 @@ from files.helpers.wrappers import * from files.helpers.get import * +from files.helpers.const import AUTOBETTER_ID from files.helpers.alerts import send_notification from files.classes import * from flask import * From bd99064d694d59a0862921a8afaf5086b10bfc76 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 11 Dec 2021 04:35:21 +0200 Subject: [PATCH 5/5] fsdfsd --- files/routes/posts.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/files/routes/posts.py b/files/routes/posts.py index 9d02019f3f..b9c2ea52a9 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -902,10 +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): if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'![]({i.group(1)})') - bet_options = [] - for i in re.finditer('\s*\$\$\$([^\$\n]+)\$\$\$\s*', body): - bet_options.append(i.group(1)) - body = body.replace(i.group(0), "") + if v and v.admin_level > 1: + bet_options = [] + for i in re.finditer('\s*\$\$\$([^\$\n]+)\$\$\$\s*', body): + bet_options.append(i.group(1)) + body = body.replace(i.group(0), "") options = [] for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body): @@ -969,15 +970,16 @@ def submit_post(v): g.db.add(new_post) 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 - ) + if v and v.admin_level > 1: + 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) + g.db.add(bet_option) for option in options: c = Comment(author_id=AUTOPOLLER_ID,