diff --git a/files/helpers/actions.py b/files/helpers/actions.py index 518f28729..77af955f9 100644 --- a/files/helpers/actions.py +++ b/files/helpers/actions.py @@ -449,3 +449,22 @@ def execute_lawlz_actions(v:User, p:Submission): g.db.add(ma_1) g.db.add(ma_2) g.db.add(ma_3) + +def execute_pizza_autovote(v:User, target:Union[Submission, Comment]): + if v.id != PIZZASHILL_ID: return + if SITE_NAME != 'rDrama': return + votes = len(PIZZA_VOTERS) + for uid in PIZZA_VOTERS: + if isinstance(target, Submission): + autovote = Vote(user_id=uid, submission_id=target.id, vote_type=1) + elif isinstance(target, Comment): + autovote = CommentVote(user_id=uid, comment_id=target.id, vote_type=1) + else: + raise TypeError("Expected Submission or Comment") + autovote.created_utc += 1 + g.db.add(autovote) + v.coins += votes + v.truecoins += votes + g.db.add(v) + target.upvotes += votes + g.db.add(target) diff --git a/files/routes/comments.py b/files/routes/comments.py index 20d573a05..c13437f37 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -344,16 +344,7 @@ def comment(v): c.voted = 1 - if v.id == PIZZASHILL_ID: - for uid in PIZZA_VOTERS: - autovote = CommentVote(user_id=uid, comment_id=c.id, vote_type=1) - autovote.created_utc += 1 - g.db.add(autovote) - v.coins += 3 - v.truecoins += 3 - g.db.add(v) - c.upvotes += 3 - g.db.add(c) + execute_pizza_autovote(v, c) if v.marseyawarded and parent_post.id not in ADMIGGERS and marseyaward_body_regex.search(body_html): abort(403, "You can only type marseys!") diff --git a/files/routes/posts.py b/files/routes/posts.py index 24f61841e..a3cde9eb4 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -916,17 +916,7 @@ def submit_post(v, sub=None): v.post_count = g.db.query(Submission).filter_by(author_id=v.id, deleted_utc=0).count() g.db.add(v) - if v.id == PIZZASHILL_ID: - for uid in PIZZA_VOTERS: - autovote = Vote(user_id=uid, submission_id=post.id, vote_type=1) - autovote.created_utc += 1 - g.db.add(autovote) - v.coins += 3 - v.truecoins += 3 - g.db.add(v) - post.upvotes += 3 - g.db.add(post) - + execute_pizza_autovote(v, post) execute_lawlz_actions(v, post) cache.delete_memoized(frontlist)