From 7a9a78c027ee53ff0d1c89f45c9c081c92d377e6 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Mon, 17 Jan 2022 13:47:30 +0200 Subject: [PATCH] bbb --- files/classes/submission.py | 2 +- files/helpers/const.py | 9 ++++++--- files/helpers/sanitize.py | 6 +++--- files/routes/admin.py | 10 +++++----- files/routes/comments.py | 10 +++++++++- files/routes/posts.py | 3 ++- files/templates/submission_listing.html | 8 +++----- 7 files changed, 29 insertions(+), 19 deletions(-) diff --git a/files/classes/submission.py b/files/classes/submission.py index 4b5a1e8d3..4326a55e1 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -68,7 +68,7 @@ class Submission(Base): @property @lazy def comments(self): - return g.db.query(Comment.author_id, Comment.created_utc, Comment.id).filter_by(parent_submission=self.id) + return g.db.query(Comment.author_id, Comment.created_utc, Comment.id).filter(Submission.parent_submission == self.id, Submission.author_id.notin_((AUTOPOLLER_ID,AUTOBETTER_ID))) @property @lazy diff --git a/files/helpers/const.py b/files/helpers/const.py index 5976f5e6f..1d7d67e8c 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -141,7 +141,8 @@ if SITE == 'rdrama.net': AUTOPOLLER_ID = 6176 AUTOBETTER_ID = 7668 TAX_RECEIVER_ID = 995 - AUTO_UPVOTE_IDS = (2424,4245) + PIZZASHILL_ID = 2424 + HIL_ID = 4245 CRAT_ID = 747 IDIO_ID = 30 CARP_ID = 995 @@ -167,7 +168,8 @@ elif SITE == "pcmemes.net": AUTOPOLLER_ID = 3369 AUTOBETTER_ID = 1867 TAX_RECEIVER_ID = 1592 - AUTO_UPVOTE_IDS = () + PIZZASHILL_ID = 0 + HIL_ID = 0 CRAT_ID = 0 IDIO_ID = 0 CARP_ID = 0 @@ -193,7 +195,8 @@ else: AUTOPOLLER_ID = 6 AUTOBETTER_ID = 7 TAX_RECEIVER_ID = 8 - AUTO_UPVOTE_IDS = () + PIZZASHILL_ID = 0 + HIL_ID = 0 CRAT_ID = 0 IDIO_ID = 0 CARP_ID = 0 diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 62bf6c4ff..bb01f318e 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -113,14 +113,14 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False): else: sanitized = re.sub('(^|\s|\n|

)\/?((r|u)\/\w{3,25})', r'\1\2', sanitized) - for i in re.finditer('(^|\s|\n|

)@((\w|-){1,25})', sanitized): + for i in re.finditer('(^|\s|\n|

)@((\w|-){1,25})($|\s|\n|<\p>)', sanitized): u = get_user(i.group(2), graceful=True) if u and (not g.v.any_block_exists(u) or g.v.admin_level > 1): if noimages: - sanitized = sanitized.replace(i.group(0), f'{i.group(1)}@{u.username}') + sanitized = sanitized.replace(i.group(0), f'{i.group(1)}@{u.username}{i.group(4)}') else: - sanitized = sanitized.replace(i.group(0), f'''{i.group(1)}@{u.username}'s profile picture@{u.username}''') + sanitized = sanitized.replace(i.group(0), f'''{i.group(1)}@{u.username}'s profile picture@{u.username}{i.group(4)}''') for i in re.finditer('https://i\.imgur\.com/(([^_]*?)\.(jpg|png|jpeg))', sanitized): diff --git a/files/routes/admin.py b/files/routes/admin.py index 65f8167cc..a35f71f97 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -67,6 +67,11 @@ def distribute(v, comment): for option in post.bet_options: pool += option.upvotes pool *= 200 + autobetter = g.db.query(User).filter_by(id=AUTOBETTER_ID).one_or_none() + autobetter.coins -= pool + if autobetter.coins < 0: autobetter.coins = 0 + g.db.add(autobetter) + votes = g.db.query(CommentVote).filter_by(comment_id=comment) coinsperperson = int(pool / votes.count()) @@ -76,11 +81,6 @@ def distribute(v, comment): u.coins += coinsperperson add_notif(cid, u.id) - autobetter = g.db.query(User).filter_by(id=AUTOBETTER_ID).one_or_none() - autobetter.coins -= pool - if autobetter.coins < 0: return {"error": "Not enough coins in bool"}, 400 - g.db.add(autobetter) - cid = notif_comment(f"You lost the 200 coins you bet on [{post.permalink}]({post.permalink}) :marseylaugh:") cids = [x.id for x in post.bet_options] cids.remove(comment) diff --git a/files/routes/comments.py b/files/routes/comments.py index e4bbbf80b..5c05d86ac 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -513,7 +513,7 @@ def api_comment(v): c.voted = 1 - if v.id in AUTO_UPVOTE_IDS: + if v.id == PIZZASHILL_ID: autovote = CommentVote(user_id=CARP_ID, comment_id=c.id, vote_type=1) g.db.add(autovote) autovote = CommentVote(user_id=AEVANN_ID, comment_id=c.id, vote_type=1) @@ -525,6 +525,14 @@ def api_comment(v): g.db.add(v) c.upvotes += 3 g.db.add(c) + elif v.id == HIL_ID: + autovote = CommentVote(user_id=CARP_ID, comment_id=c.id, vote_type=1) + g.db.add(autovote) + v.coins += 1 + v.truecoins += 1 + g.db.add(v) + c.upvotes += 1 + g.db.add(c) g.db.commit() diff --git a/files/routes/posts.py b/files/routes/posts.py index 8f4277781..28b6700d8 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -1065,6 +1065,7 @@ def submit_post(v): title = url_match.group(5) if "Snapshots:\n\n" not in body: body += "Snapshots:\n\n" + if f'**[{title}]({href})**:\n\n' in body: continue body += f'**[{title}]({href})**:\n\n' if href.startswith('https://old.reddit.com/'): body += f'* [unddit.com](https://unddit.com/{href.replace("https://old.reddit.com/", "")})\n' @@ -1107,7 +1108,7 @@ def submit_post(v): send_discord_message(f"https://{site}{new_post.permalink}") cache.delete_memoized(changeloglist) - if v.id in AUTO_UPVOTE_IDS: + if v.id in (PIZZASHILL_ID, HIL_ID): autovote = Vote(user_id=CARP_ID, submission_id=new_post.id, vote_type=1) g.db.add(autovote) autovote = Vote(user_id=AEVANN_ID, submission_id=new_post.id, vote_type=1) diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index 0734877a3..b92c476c9 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -63,11 +63,9 @@ {% for p in listing %} {% set ups=p.upvotes %}