diff --git a/files/classes/badges.py b/files/classes/badges.py index 82879a51d..3d2d5feaa 100644 --- a/files/classes/badges.py +++ b/files/classes/badges.py @@ -41,12 +41,13 @@ class Badge(Base): ti = self.user.agendaposter_expires_utc if ti: text = self.badge.description + " until " + datetime.utcfromtimestamp(ti).strftime('%Y-%m-%d %H:%M:%S') else: text = self.badge.description + " permanently" - elif self.badge_id in (94,95,96,97,98): + elif self.badge_id in (94,95,96,97,98,109): if self.badge_id == 94: ti = self.user.progressivestack elif self.badge_id == 95: ti = self.user.bird elif self.badge_id == 96: ti = self.user.flairchanged elif self.badge_id == 97: ti = self.user.longpost - else: ti = self.user.marseyawarded + elif self.badge_id == 98: ti = self.user.marseyawarded + elif self.badge_id == 109: ti = self.user.rehab text = self.badge.description + " until " + datetime.utcfromtimestamp(ti).strftime('%Y-%m-%d %H:%M:%S') elif self.description: text = self.description elif self.badge.description: text = self.badge.description diff --git a/files/classes/blackjack.py b/files/classes/blackjack.py index afc0a240e..6859cf172 100644 --- a/files/classes/blackjack.py +++ b/files/classes/blackjack.py @@ -54,6 +54,7 @@ def format_all(player_hand, dealer_hand, deck, status, wager): class Blackjack: command_word = "!blackjack" + casino_word = "!blackjackmb" minimum_bet = 100 maximum_bet = INFINITY @@ -94,9 +95,6 @@ class Blackjack: from_comment.blackjack_result = format_all( player_hand, dealer_hand, rest_of_deck, status, wager) - self.db.add(from_comment) - self.db.commit() - def player_hit(self, from_comment): player_hand, dealer_hand, deck, status, wager = from_comment.blackjack_result.split( "_") @@ -113,9 +111,6 @@ class Blackjack: from_comment.blackjack_result = format_all( player_hand, dealer_hand, deck, status, wager) - self.db.add(from_comment) - self.db.commit() - if (player_value == 21): self.player_stayed(from_comment) @@ -143,9 +138,6 @@ class Blackjack: from_comment.blackjack_result = format_all( player_hand, dealer_hand, deck, status, wager) - self.db.add(from_comment) - self.db.commit() - self.apply_game_result(from_comment, wager, status) def apply_game_result(self, from_comment, wager, result): @@ -161,7 +153,4 @@ class Blackjack: if (reward > 0): user = from_comment.author user.coins += reward - user.winnings += reward - - self.db.add(user) - self.db.commit() \ No newline at end of file + user.winnings += reward \ No newline at end of file diff --git a/files/classes/slots.py b/files/classes/slots.py index 034b658f3..faaccb9d2 100644 --- a/files/classes/slots.py +++ b/files/classes/slots.py @@ -45,10 +45,8 @@ class Slots: from_user.coins += reward from_user.winnings += reward - self.db.add(from_user) from_comment.slots_result = f'{symbols} {text}' - self.db.add(from_comment) if self.casino_word in in_text: for word in in_text.split(): @@ -72,10 +70,8 @@ class Slots: from_user.procoins += reward from_user.winnings += reward - self.db.add(from_user) from_comment.slots_result = f'{symbols} {text}' - self.db.add(from_comment) def determine_payout(self): diff --git a/files/classes/treasure.py b/files/classes/treasure.py index 0a808650a..295cc5bed 100644 --- a/files/classes/treasure.py +++ b/files/classes/treasure.py @@ -11,7 +11,7 @@ class Treasure: self.db = g.db def check_for_treasure(self, in_text, from_comment): - has_gamble_command = '!slots' in in_text or '!blackjack' in in_text + has_gamble_command = '!slots' in in_text or '!casino' in in_text or '!blackjack' in in_text if not has_gamble_command: seed = random.randint(1, 1000) diff --git a/files/classes/user.py b/files/classes/user.py index 374e28d70..eeb01f17e 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -50,6 +50,7 @@ class User(Base): verified = Column(String) verifiedcolor = Column(String) marseyawarded = Column(Integer) + rehab = Column(Integer) longpost = Column(Integer) winnings = Column(Integer, default=0) unblockable = Column(Boolean) diff --git a/files/helpers/const.py b/files/helpers/const.py index 9ecb29fca..6b5dba5df 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -356,6 +356,14 @@ AWARDS = { "color": "text-white", "price": 500 }, + "rehab": { + "kind": "rehab", + "title": "Rehab", + "description": "Prevents the user from gambling for 24 hours in a last ditch effort to save them from themself.", + "icon": "fas fa-dice-six", + "color": "text-black", + "price": 777 + }, "progressivestack": { "kind": "progressivestack", "title": "Progressive Stack", diff --git a/files/routes/awards.py b/files/routes/awards.py index 84b4fecd0..f7075ff1b 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -403,6 +403,14 @@ def award_post(pid, v): for c in post.comments: c.ghost = True g.db.add(c) + elif kind == "rehab": + if author.rehab: author.rehab += 86400 + else: author.rehab = int(time.time()) + 86400 + if not v.has_badge(109): + badge = Badge(user_id=v.id, badge_id=109) + g.db.add(badge) + g.db.flush() + send_notification(v.id, f"@AutoJanny has given you the following profile badge:\n\n![]({badge.path})\n\n{badge.name}") if post.author.received_award_count: post.author.received_award_count += 1 else: post.author.received_award_count = 1 @@ -622,6 +630,14 @@ def award_comment(cid, v): elif kind == "ghosts": c.ghost = True g.db.add(c) + elif kind == "rehab": + if author.rehab: author.rehab += 86400 + else: author.rehab = int(time.time()) + 86400 + if not v.has_badge(109): + badge = Badge(user_id=v.id, badge_id=109) + g.db.add(badge) + g.db.flush() + send_notification(v.id, f"@AutoJanny has given you the following profile badge:\n\n![]({badge.path})\n\n{badge.name}") 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 c8c5625f4..e14d88f7a 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -5,6 +5,7 @@ from files.helpers.images import * from files.helpers.const import * from files.classes import * from files.routes.front import comment_idlist +from files.routes.static import marsey_list from pusher_push_notifications import PushNotifications from flask import * from files.__main__ import app, limiter @@ -201,7 +202,7 @@ def api_comment(v): process_image(filename) elif parent_post.id == 37833: try: - badge_def = loads(body.lower()) + badge_def = loads(body) name = badge_def["name"] badge = g.db.query(BadgeDef).filter_by(name=name).first() if not badge: @@ -213,8 +214,7 @@ def api_comment(v): process_image(filename, 200) requests.post(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/purge_cache', headers=CF_HEADERS, data={'files': [f"https://{request.host}/static/assets/images/badges/{badge.id}.webp"]}) except Exception as e: - print(e) - return {"error": "You didn't follow the format retard"}, 400 + return {"error": e}, 400 elif v.admin_level > 2 and parent_post.id == 37838: try: marsey = loads(body.lower()) @@ -229,9 +229,9 @@ def api_comment(v): copyfile(oldname, filename) process_image(filename, 200) requests.post(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/purge_cache', headers=CF_HEADERS, data={'files': [f"https://{request.host}/static/assets/images/emojis/{name}.webp"]}) + cache.delete_memoized(marsey_list) except Exception as e: - print(e) - return {"error": "You didn't follow the format retard"}, 400 + return {"error": e}, 400 body += f"\n\n![]({image})" elif file.content_type.startswith('video/'): file.save("video.mp4") @@ -566,9 +566,6 @@ def api_comment(v): v.comment_count = g.db.query(Comment.id).filter(Comment.author_id == v.id, Comment.parent_submission != None).filter_by(is_banned=False, deleted_utc=0).count() g.db.add(v) - parent_post.comment_count += 1 - g.db.add(parent_post) - c.voted = 1 if v.id == PIZZASHILL_ID: @@ -592,15 +589,20 @@ def api_comment(v): c.upvotes += 1 g.db.add(c) - slots = Slots(g) - slots.check_for_slots_command(body, v, c) + if not v.rehab: + slots = Slots(g) + slots.check_for_slots_command(body, v, c) - blackjack = Blackjack(g) - blackjack.check_for_blackjack_command(body, v, c) + blackjack = Blackjack(g) + blackjack.check_for_blackjack_command(body, v, c) treasure = Treasure(g) treasure.check_for_treasure(body, c) + if not c.slots_result and not c.blackjack_result: + parent_post.comment_count += 1 + g.db.add(parent_post) + g.db.commit() if request.headers.get("Authorization"): return c.json diff --git a/files/routes/front.py b/files/routes/front.py index f9128a50e..ac4720c59 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -94,7 +94,12 @@ def notifications(v): c.is_blocked = False c.is_blocking = False if c.parent_submission and c.parent_comment and c.parent_comment.author_id == v.id: - c.replies = [] + replies = [] + for x in c.replies: + if x.author_id == v.id: + x.voted = 1 + replies.append(x) + c.replies = replies while c.parent_comment and c.parent_comment.author_id == v.id: parent = c.parent_comment if c not in parent.replies2: @@ -105,7 +110,12 @@ def notifications(v): listing.append(c) c.replies = c.replies2 elif c.parent_submission: - c.replies = [] + replies = [] + for x in c.replies: + if x.author_id == v.id: + x.voted = 1 + replies.append(x) + c.replies = replies if c not in listing: listing.append(c) else: @@ -234,6 +244,14 @@ def front_all(v): if badge: g.db.delete(badge) g.db.commit() + if v.rehab and v.rehab < time.time(): + v.rehab = None + send_repeatable_notification(v.id, "Your rehab has finished!") + g.db.add(v) + badge = v.has_badge(109) + if badge: g.db.delete(badge) + g.db.commit() + if request.headers.get("Authorization"): return {"data": [x.json for x in posts], "next_exists": next_exists} return render_template("home.html", v=v, listing=posts, next_exists=next_exists, sort=sort, t=t, page=page) @@ -284,7 +302,7 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words=' if sort == "hot": ti = int(time.time()) + 3600 - posts = posts.order_by(-1000000*(Submission.realupvotes + 1)/(func.power(((ti - Submission.created_utc)/1000), 1.23))) + posts = posts.order_by(-1000000*(Submission.realupvotes + 1 + Submission.comment_count/5)/(func.power(((ti - Submission.created_utc)/1000), 1.23))) elif sort == "new": posts = posts.order_by(Submission.created_utc.desc()) elif sort == "old": diff --git a/files/routes/posts.py b/files/routes/posts.py index 975be862f..5235d226e 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -179,7 +179,9 @@ def post_id(pid, anything=None, v=None): elif sort == "bottom": comments = comments.order_by(Comment.upvotes - Comment.downvotes) - comments = [c[0] for c in comments.all()] + first = [c[0] for c in comments.filter(Comment.slots_result == None, Comment.blackjack_result == None).all()] + second = [c[0] for c in comments.filter(or_(Comment.slots_result != None, Comment.blackjack_result != None)).all()] + comments = first + second else: pinned = g.db.query(Comment).filter(Comment.parent_submission == post.id, Comment.is_pinned != None).all() @@ -196,7 +198,9 @@ def post_id(pid, anything=None, v=None): elif sort == "bottom": comments = comments.order_by(Comment.upvotes - Comment.downvotes) - comments = comments.all() + first = comments.filter(Comment.slots_result == None, Comment.blackjack_result == None).all() + second = comments.filter(or_(Comment.slots_result != None, Comment.blackjack_result != None)).all() + comments = first + second offset = 0 @@ -298,9 +302,10 @@ def viewmore(v, pid, sort, offset): elif sort == "bottom": comments = comments.order_by(Comment.upvotes - Comment.downvotes) - comments = comments.offset(offset) - - comments = [c[0] for c in comments.all()] + first = [c[0] for c in comments.filter(Comment.slots_result == None, Comment.blackjack_result == None).all()] + second = [c[0] for c in comments.filter(or_(Comment.slots_result != None, Comment.blackjack_result != None)).all()] + comments = first + second + comments = comments[offset:] else: 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) @@ -314,10 +319,11 @@ def viewmore(v, pid, sort, offset): comments = comments.order_by(Comment.realupvotes.desc()) elif sort == "bottom": comments = comments.order_by(Comment.upvotes - Comment.downvotes) - - comments = comments.offset(offset) - comments = comments.all() + first = comments.filter(Comment.slots_result == None, Comment.blackjack_result == None).all() + second = comments.filter(or_(Comment.slots_result != None, Comment.blackjack_result != None)).all() + comments = first + second + comments = comments[offset:] comments2 = [] count = 0 @@ -661,7 +667,7 @@ def thumbnail_thread(pid): db.add(post) db.commit() - if SITE == 'rdrama.net' and random.random() < 0.05: + if SITE == 'rdrama.net' and random.random() < 0.02: for t in ("submission","comment"): for term in ('rdrama','freeghettohoes.biz','marsey'): for i in requests.get(f'https://api.pushshift.io/reddit/{t}/search?html_decode=true&q={term}&size=10').json()["data"]: diff --git a/files/routes/users.py b/files/routes/users.py index 46f2eabb8..3f3b3ddb6 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -71,9 +71,14 @@ def upvoters(v, username): users2 = [] for user in users: users2.append((user, votes[user.id])) - users = sorted(users2, key=lambda x: x[1], reverse=True)[:25] + users = sorted(users2, key=lambda x: x[1], reverse=True) + + try: + pos = [x[0].id for x in users].index(v.id) + pos = (pos+1, users[pos][1]) + except: pos = (len(users)+1, 0) - return render_template("voters.html", v=v, users=users, name='Up', name2=f'@{username} biggest simps') + return render_template("voters.html", v=v, users=users[:25], pos=pos, name='Up', name2=f'@{username} biggest simps') @app.get("/@/downvoters") @auth_required @@ -90,9 +95,14 @@ def downvoters(v, username): users2 = [] for user in users: users2.append((user, votes[user.id])) - users = sorted(users2, key=lambda x: x[1], reverse=True)[:25] + users = sorted(users2, key=lambda x: x[1], reverse=True) + + try: + pos = [x[0].id for x in users].index(v.id) + pos = (pos+1, users[pos][1]) + except: pos = (len(users)+1, 0) - return render_template("voters.html", v=v, users=users, name='Down', name2=f'@{username} biggest haters') + return render_template("voters.html", v=v, users=users[:25], pos=pos, name='Down', name2=f'@{username} biggest haters') @app.get("/@/upvoting") @auth_required @@ -109,9 +119,14 @@ def upvoting(v, username): users2 = [] for user in users: users2.append((user, votes[user.id])) - users = sorted(users2, key=lambda x: x[1], reverse=True)[:25] + users = sorted(users2, key=lambda x: x[1], reverse=True) + + try: + pos = [x[0].id for x in users].index(v.id) + pos = (pos+1, users[pos][1]) + except: pos = (len(users)+1, 0) - return render_template("voters.html", v=v, users=users, name='Up', name2=f'Who @{username} simps for') + return render_template("voters.html", v=v, users=users[:25], pos=pos, name='Up', name2=f'Who @{username} simps for') @app.get("/@/downvoting") @auth_required @@ -128,9 +143,14 @@ def downvoting(v, username): users2 = [] for user in users: users2.append((user, votes[user.id])) - users = sorted(users2, key=lambda x: x[1], reverse=True)[:25] + users = sorted(users2, key=lambda x: x[1], reverse=True) + + try: + pos = [x[0].id for x in users].index(v.id) + pos = (pos+1, users[pos][1]) + except: pos = (len(users)+1, 0) - return render_template("voters.html", v=v, users=users, name='Down', name2=f'Who @{username} hates') + return render_template("voters.html", v=v, users=users[:25], pos=pos, name='Down', name2=f'Who @{username} hates') @app.post("/pay_rent") @limiter.limit("1/second;30/minute;200/hour;1000/day") diff --git a/files/templates/authforms.html b/files/templates/authforms.html index 14e11ae79..5ed9100eb 100644 --- a/files/templates/authforms.html +++ b/files/templates/authforms.html @@ -15,7 +15,7 @@ {% if v %} - + {% if v.agendaposter %} - + {% endif %} diff --git a/files/templates/comments.html b/files/templates/comments.html index 8dad4283e..ce612c7d0 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -878,10 +878,6 @@ object-fit: cover; } - .text-black { - color: var(--black); - } - .smolbtn { font-weight: 600; font-size: .9rem; diff --git a/files/templates/default.html b/files/templates/default.html index d8cbcc408..d5d0a88b9 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -7,7 +7,7 @@ {% if v %} - + {% if v.agendaposter %} - + {% endif %} diff --git a/files/templates/log.html b/files/templates/log.html index a1f66ae27..a310d6eee 100644 --- a/files/templates/log.html +++ b/files/templates/log.html @@ -6,7 +6,7 @@ {% block content %} {% if v %} - + {% if v.agendaposter %} - + {% endif %}
diff --git a/files/templates/login.html b/files/templates/login.html index ae2eee108..e059c63bb 100644 --- a/files/templates/login.html +++ b/files/templates/login.html @@ -18,7 +18,7 @@ {% endblock %} - + diff --git a/files/templates/login_2fa.html b/files/templates/login_2fa.html index 00d81014d..b707b734d 100644 --- a/files/templates/login_2fa.html +++ b/files/templates/login_2fa.html @@ -14,7 +14,7 @@ 2-Step Login - {{SITE_NAME}} - + diff --git a/files/templates/settings.html b/files/templates/settings.html index 3aeb96250..b8a04a4d0 100644 --- a/files/templates/settings.html +++ b/files/templates/settings.html @@ -34,7 +34,7 @@ - + {% if v.agendaposter %} - + {% else %} - + {% endif %} diff --git a/files/templates/sign_up.html b/files/templates/sign_up.html index d01540885..a6cf61b70 100644 --- a/files/templates/sign_up.html +++ b/files/templates/sign_up.html @@ -31,7 +31,7 @@ {% if ref_user %}{{ref_user.username}} invites you to {{SITE_NAME}}{% else %}Sign up - {{SITE_NAME}}{% endif %} - + diff --git a/files/templates/sign_up_failed_ref.html b/files/templates/sign_up_failed_ref.html index 253849c68..b0f90967f 100644 --- a/files/templates/sign_up_failed_ref.html +++ b/files/templates/sign_up_failed_ref.html @@ -32,7 +32,7 @@ {% if ref_user %}{{ref_user.username}} invites you to {{SITE_NAME}}{% else %}{{SITE_NAME}}{% endif %} - + diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index 7440d1834..3085c20dd 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -659,10 +659,6 @@ object-fit: cover; } - .text-black { - color: var(--black); - } - .smolbtn { font-weight: 600; font-size: .9rem; diff --git a/files/templates/submit.html b/files/templates/submit.html index aedd96363..3a5400df2 100644 --- a/files/templates/submit.html +++ b/files/templates/submit.html @@ -26,7 +26,7 @@ {% block stylesheets %} {% if v %} - + {% if v.agendaposter %} - + {% endif %} {% endblock %} diff --git a/files/templates/voters.html b/files/templates/voters.html index 4389637d3..ae02e4016 100644 --- a/files/templates/voters.html +++ b/files/templates/voters.html @@ -16,13 +16,26 @@ {% for user in users %} - + {{loop.index}} @{{user[0].username}}'s profile picture{{user[0].username}} {{user[1]}} {% endfor %} +{% if pos and (pos[0] > 25 or not pos[1]) %} + + {{pos[0]}} + @{{v.username}}'s profile picture{{v.username}} + {{pos[1]}} + +{% endif %} + {% endblock %} \ No newline at end of file