From 8532719783e1ad84a9ab43cbf6cb8788f7c56862 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 12 Dec 2021 19:06:48 +0200 Subject: [PATCH] fdsfds --- files/classes/user.py | 7 +++++++ files/helpers/const.py | 16 ++++++++++++++++ files/routes/admin.py | 4 ++-- files/routes/awards.py | 27 +++++++++++++++++++++++++++ files/routes/comments.py | 4 ++-- files/routes/posts.py | 2 +- files/routes/votes.py | 16 ++++++++-------- 7 files changed, 63 insertions(+), 13 deletions(-) diff --git a/files/classes/user.py b/files/classes/user.py index 645dbce37..928fd52f1 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -281,9 +281,15 @@ class User(Base): if not self.is_suspended: return None return g.db.query(User).filter_by(id=self.is_banned).first() + @lazy def has_badge(self, badge_id): return g.db.query(Badge).filter_by(user_id=self.id, badge_id=badge_id).first() + @property + @lazy + def grinch(self): + return self.has_badge(91) + def hash_password(self, password): return generate_password_hash( password, method='pbkdf2:sha512', salt_length=8) @@ -418,6 +424,7 @@ class User(Base): @property @lazy def profile_url(self): + if self.grinch: return f"https://{site}/assets/images/grinch.webp?v=1" if self.agendaposter: return f"https://{site}/assets/images/defaultpictures/agendaposter/{random.randint(1, 50)}.webp?v=1" if self.profileurl: return self.profileurl if "rama" in site: return f"https://{site}/assets/images/defaultpictures/{random.randint(1, 150)}.webp?v=1" diff --git a/files/helpers/const.py b/files/helpers/const.py index a40d4dd74..9b1eae29d 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -456,6 +456,14 @@ AWARDS = { "color": "", "price": 1000 }, + "grinch": { + "kind": "grinch", + "title": "Grinch", + "description": "???", + "icon": "fas fa-angry", + "color": "text-green-500", + "price": 1000 + }, "haunt": { "kind": "haunt", "title": "Haunt", @@ -716,6 +724,14 @@ AWARDS2 = { "color": "", "price": 1000 }, + "grinch": { + "kind": "grinch", + "title": "Grinch", + "description": "???", + "icon": "fas fa-angry", + "color": "text-green-500", + "price": 1000 + }, "shit": { "kind": "shit", "title": "Shit", diff --git a/files/routes/admin.py b/files/routes/admin.py index 51ffcc047..843324f44 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -883,7 +883,7 @@ def ban_post(post_id, v): cache.delete_memoized(frontlist) - v.coins += 1 + v.coins += 2 g.db.add(v) g.db.commit() @@ -917,7 +917,7 @@ def unban_post(post_id, v): cache.delete_memoized(frontlist) - v.coins -= 1 + v.coins -= 2 g.db.add(v) g.db.commit() diff --git a/files/routes/awards.py b/files/routes/awards.py index f6f8a4801..276f3d740 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -102,6 +102,15 @@ def shop(v): "owned": 0, "price": 1000 }, + "grinch": { + "kind": "grinch", + "title": "Grinch", + "description": "???", + "icon": "fas fa-angry", + "color": "text-green-500", + "owned": 0, + "price": 1000 + }, "shit": { "kind": "shit", "title": "Shit", @@ -348,6 +357,14 @@ def buy(v, award): "color": "", "price": 1000 }, + "grinch": { + "kind": "grinch", + "title": "Grinch", + "description": "???", + "icon": "fas fa-angry", + "color": "text-green-500", + "price": 1000 + }, "shit": { "kind": "shit", "title": "Shit", @@ -718,6 +735,11 @@ def award_post(pid, v): if not author.has_badge(90): new_badge = Badge(badge_id=90, user_id=author.id) g.db.add(new_badge) + elif kind == "grinch": + send_notification(CARP_ID, f"@{v.username} used {kind} award!") + if not author.has_badge(91): + new_badge = Badge(badge_id=91, user_id=author.id) + g.db.add(new_badge) if post.author.received_award_count: post.author.received_award_count += 1 else: post.author.received_award_count = 1 @@ -880,6 +902,11 @@ def award_comment(cid, v): if not author.has_badge(90): new_badge = Badge(badge_id=90, user_id=author.id) g.db.add(new_badge) + elif kind == "grinch": + send_notification(CARP_ID, f"@{v.username} used {kind} award!") + if not author.has_badge(91): + new_badge = Badge(badge_id=91, user_id=author.id) + g.db.add(new_badge) if c.author.received_award_count: c.author.received_award_count += 1 else: c.author.received_award_count = 1 diff --git a/files/routes/comments.py b/files/routes/comments.py index 0957bb6c7..c41a7c895 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -407,7 +407,7 @@ def api_comment(v): if v.id == PIZZA_SHILL_ID: cratvote = CommentVote(user_id=TAX_RECEIVER_ID, comment_id=c.id, vote_type=1) g.db.add(cratvote) - v.coins += 1 + v.coins += 2 v.truecoins += 1 g.db.add(v) c.upvotes += 1 @@ -433,7 +433,7 @@ def api_comment(v): longpostbot = g.db.query(User).filter_by(id = LONGPOSTBOT_ID).first() longpostbot.comment_count += 1 - longpostbot.coins += 1 + longpostbot.coins += 2 g.db.add(longpostbot) g.db.flush() diff --git a/files/routes/posts.py b/files/routes/posts.py index b3ff39d04..0db0943f0 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -1178,7 +1178,7 @@ def submit_post(v): snappy = g.db.query(User).filter_by(id = SNAPPY_ID).first() snappy.comment_count += 1 - snappy.coins += 1 + snappy.coins += 2 g.db.add(snappy) g.db.flush() diff --git a/files/routes/votes.py b/files/routes/votes.py index f49d72ab7..7340d9d8a 100644 --- a/files/routes/votes.py +++ b/files/routes/votes.py @@ -69,7 +69,7 @@ def admin_vote_info_get(v): @validate_formkey def api_vote_post(post_id, new, v): - if v.is_banned and not v.unban_utc: return {"error": "forbidden."}, 403 + if v.is_banned and not v.unban_utc or new == "-1": return {"error": "forbidden."}, 403 if new not in ["-1", "0", "1"]: abort(400) @@ -85,13 +85,13 @@ def api_vote_post(post_id, new, v): if existing: if existing.vote_type == 0 and new != 0: - post.author.coins += 1 + post.author.coins += 2 post.author.truecoins += 1 g.db.add(post.author) existing.vote_type = new g.db.add(existing) elif existing.vote_type != 0 and new == 0: - post.author.coins -= 1 + post.author.coins -= 2 post.author.truecoins -= 1 g.db.add(post.author) g.db.delete(existing) @@ -99,7 +99,7 @@ def api_vote_post(post_id, new, v): existing.vote_type = new g.db.add(existing) elif new != 0: - post.author.coins += 1 + post.author.coins += 2 post.author.truecoins += 1 g.db.add(post.author) real = (bool(v.profileurl) or bool(v.customtitle) or v.namecolor != defaultcolor) and not v.agendaposter and not v.shadowbanned @@ -132,7 +132,7 @@ def api_vote_post(post_id, new, v): @validate_formkey def api_vote_comment(comment_id, new, v): - if v.is_banned and not v.unban_utc: return {"error": "forbidden."}, 403 + if v.is_banned and not v.unban_utc or new == "-1": return {"error": "forbidden."}, 403 if new not in ["-1", "0", "1"]: abort(400) @@ -153,13 +153,13 @@ def api_vote_comment(comment_id, new, v): if existing: if existing.vote_type == 0 and new != 0: - comment.author.coins += 1 + comment.author.coins += 2 comment.author.truecoins += 1 g.db.add(comment.author) existing.vote_type = new g.db.add(existing) elif existing.vote_type != 0 and new == 0: - comment.author.coins -= 1 + comment.author.coins -= 2 comment.author.truecoins -= 1 g.db.add(comment.author) g.db.delete(existing) @@ -167,7 +167,7 @@ def api_vote_comment(comment_id, new, v): existing.vote_type = new g.db.add(existing) elif new != 0: - comment.author.coins += 1 + comment.author.coins += 2 comment.author.truecoins += 1 g.db.add(comment.author) real = (bool(v.profileurl) or bool(v.customtitle) or v.namecolor != defaultcolor) and not v.agendaposter and not v.shadowbanned