From 15a02cf3cd6d67043c566cddeafee61db1f1fa67 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 10 Apr 2022 01:07:03 +0200 Subject: [PATCH] fds --- files/helpers/const.py | 2 +- files/routes/awards.py | 8 -------- files/routes/comments.py | 3 --- files/routes/login.py | 35 +++++++++++++++++++---------------- files/routes/posts.py | 17 +++++++++++------ files/routes/settings.py | 4 ---- files/templates/submit.html | 4 ++-- 7 files changed, 33 insertions(+), 40 deletions(-) diff --git a/files/helpers/const.py b/files/helpers/const.py index c1287b9f4..7b860b803 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -723,7 +723,7 @@ snappy_url_regex = re.compile('= 500000 and not v.has_badge(72): new_badge = Badge(badge_id=72, user_id=v.id) g.db.add(new_badge) g.db.flush() send_notification(v.id, f"@AutoJanny has given you the following profile badge:\n\n![]({new_badge.path})\n\n{new_badge.name}") - old_badge = v.has_badge(71) - if old_badge: g.db.delete(old_badge) elif v.coins_spent >= 250000 and not v.has_badge(71): new_badge = Badge(badge_id=71, user_id=v.id) g.db.add(new_badge) g.db.flush() send_notification(v.id, f"@AutoJanny has given you the following profile badge:\n\n![]({new_badge.path})\n\n{new_badge.name}") - old_badge = v.has_badge(70) - if old_badge: g.db.delete(old_badge) elif v.coins_spent >= 100000 and not v.has_badge(70): new_badge = Badge(badge_id=70, user_id=v.id) g.db.add(new_badge) g.db.flush() send_notification(v.id, f"@AutoJanny has given you the following profile badge:\n\n![]({new_badge.path})\n\n{new_badge.name}") - old_badge = v.has_badge(69) - if old_badge: g.db.delete(old_badge) elif v.coins_spent >= 10000 and not v.has_badge(69): new_badge = Badge(badge_id=69, user_id=v.id) g.db.add(new_badge) diff --git a/files/routes/comments.py b/files/routes/comments.py index a3acf6c33..133bd564f 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -289,9 +289,6 @@ def api_comment(v): text = f"@AutoJanny has given you the following profile badge:\n\n![]({new_badge.path})\n\n{new_badge.name}" send_notification(user.id, text) - old_badge = user.has_badge(17) - if old_badge: g.db.delete(old_badge) - elif all_by_author < 10 and not user.has_badge(17): new_badge = Badge(badge_id=17, user_id=user.id) diff --git a/files/routes/login.py b/files/routes/login.py index 1735e6d16..d0385ed95 100644 --- a/files/routes/login.py +++ b/files/routes/login.py @@ -310,22 +310,6 @@ def sign_up_post(v): ref_id = int(request.values.get("referred_by", 0)) - - if ref_id: - ref_user = g.db.query(User).filter_by(id=ref_id).one_or_none() - - if ref_user: - if ref_user.referral_count and not ref_user.has_badge(10): - new_badge = Badge(user_id=ref_user.id, badge_id=10) - g.db.add(new_badge) - if ref_user.referral_count > 9 and not ref_user.has_badge(11): - new_badge = Badge(user_id=ref_user.id, badge_id=11) - g.db.add(new_badge) - if ref_user.referral_count > 99 and not ref_user.has_badge(12): - new_badge = Badge(user_id=ref_user.id, badge_id=12) - g.db.add(new_badge) - - id_1 = g.db.query(User.id).filter_by(id=9).count() users_count = g.db.query(User.id).count() if id_1 == 0 and users_count == 8: @@ -349,6 +333,25 @@ def sign_up_post(v): g.db.add(new_user) g.db.flush() + if ref_id: + ref_user = g.db.query(User).filter_by(id=ref_id).one_or_none() + + if ref_user: + if ref_user.referral_count and not ref_user.has_badge(10): + new_badge = Badge(user_id=ref_user.id, badge_id=10) + g.db.add(new_badge) + g.db.flush() + send_notification(ref_user.id, f"@AutoJanny has given you the following profile badge:\n\n![]({new_badge.path})\n\n{new_badge.name}") + if ref_user.referral_count >= 10 and not ref_user.has_badge(11): + new_badge = Badge(user_id=ref_user.id, badge_id=11) + g.db.add(new_badge) + g.db.flush() + send_notification(ref_user.id, f"@AutoJanny has given you the following profile badge:\n\n![]({new_badge.path})\n\n{new_badge.name}") + if ref_user.referral_count >= 100 and not ref_user.has_badge(12): + new_badge = Badge(user_id=ref_user.id, badge_id=12) + g.db.add(new_badge) + g.db.flush() + send_notification(ref_user.id, f"@AutoJanny has given you the following profile badge:\n\n![]({new_badge.path})\n\n{new_badge.name}") check_for_alts(new_user.id) diff --git a/files/routes/posts.py b/files/routes/posts.py index 50a1e2d41..88630ab65 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -892,19 +892,19 @@ def submit_post(v, sub=None): url = urlunparse(new_url) - search_url = url.replace('%', '') - search_url = reddit_post_regex.sub(r'\1%', search_url) - search_url = search_url.replace('\\', '').replace('_', '\_').strip() + if url.endswith('/'): url = url[:-1] + if reddit_post_regex.fullmatch(url): + url = reddit_post_regex.sub(r'https://old.reddit.com/\1', url) + + search_url = url.replace('%', '').replace('\\', '').replace('_', '\_').strip() repost = g.db.query(Submission).filter( Submission.url.ilike(search_url), Submission.deleted_utc == 0, Submission.is_banned == False ).first() - if repost: return redirect(repost.permalink) - domain_obj = get_domain(domain) if not domain_obj: domain_obj = get_domain(domain+parsed_url.path) @@ -1067,6 +1067,11 @@ def submit_post(v, sub=None): is_bot = bool(request.headers.get("Authorization")) or (SITE == 'pcmemes.net' and v.id == SNAPPY_ID) + if request.values.get("ghost") and v.coins >= 100: + v.coins -= 100 + ghost = True + else: ghost = False + post = Submission( private=bool(request.values.get("private","")), club=club, @@ -1082,7 +1087,7 @@ def submit_post(v, sub=None): title=title[:500], title_html=title_html, sub=sub, - ghost=bool(request.values.get("ghost","")) + ghost=ghost ) g.db.add(post) diff --git a/files/routes/settings.py b/files/routes/settings.py index 43baff3b6..b353a64d5 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -432,10 +432,6 @@ def gumroad(v): existing = g.db.query(User.id).filter(User.email == v.email, User.is_activated == True, User.patron >= tier).one_or_none() if existing: return {"error": f"{patron} rewards already claimed on another account"}, 400 - - if v.patron: - badge = v.has_badge(20+v.patron) - if badge: g.db.delete(badge) v.patron = tier if v.discord_id: add_role(v, f"{tier}") diff --git a/files/templates/submit.html b/files/templates/submit.html index 338a7696c..d985d2772 100644 --- a/files/templates/submit.html +++ b/files/templates/submit.html @@ -187,8 +187,8 @@ {% endif %}
- - + +