From 16077fa457cb3b90e2018d1a08ae1220b6d3e953 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 22 Aug 2021 17:36:28 +0200 Subject: [PATCH] fggf --- files/routes/settings.py | 75 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/files/routes/settings.py b/files/routes/settings.py index cd0ec3967..f3d98459a 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -11,12 +11,21 @@ import youtube_dl from .front import frontlist import os from .posts import filter_title +from files.helpers.discord import add_role valid_username_regex = re.compile("^[a-zA-Z0-9_\-]{3,25}$") valid_password_regex = re.compile("^.{8,100}$") YOUTUBE_KEY = environ.get("YOUTUBE_KEY", "").strip() COINS_NAME = environ.get("COINS_NAME").strip() +GUMROAD_TOKEN = environ.get("GUMROAD_TOKEN").strip() + +tiers={ + "(Paypig)": 1, + "(Renthog)": 2, + "(Landchad)": 3, + "(Terminally online turboautist)": 4 + } @app.post("/settings/removebackground") @auth_required @@ -196,6 +205,72 @@ def themecolor(v): g.db.add(v) return redirect("/settings/profile") +@app.post("/settings/gumroad") +@auth_required +@validate_formkey +def gumroad(v): + if not (v.email and v.is_activated): + return render_template("settings_profile.html", + v=v, + error="You must have to a verified email to verify patron status") + + data = { + 'access_token': GUMROAD_TOKEN, + 'email': v.email + } + response = requests.get('https://api.gumroad.com/v2/sales', data=data).json()["sales"] + + if len(response) == 0: + return render_template("settings_profile.html", + v=v, + error="Email not found") + + response = response[0] + tier = tiers[response["variants_and_quantity"]] + if v.patron == tier: + return render_template("settings_profile.html", + v=v, + error="Patron status already verified") + v.patron = tier + + grant_awards = {} + if tier == 1: + if v.discord_id: add_role(v, "paypig") + grant_awards["shit"] = 1 + elif tier == 2: + if v.discord_id: add_role(v, "renthog") + grant_awards["shit"] = 3 + elif tier == 3: + if v.discord_id: add_role(v, "landchad") + grant_awards["shit"] = 5 + grant_awards["ban"] = 1 + elif tier == 4: + if v.discord_id: add_role(v, "turboautist") + grant_awards["shit"] = 10 + grant_awards["ban"] = 3 + + _awards = [] + + thing = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first().id + + for name in grant_awards: + for count in range(grant_awards[name]): + + thing += 1 + + _awards.append(AwardRelationship( + id=thing, + user_id=user.id, + kind=name + )) + + g.db.bulk_save_objects(_awards) + + g.db.add(v) + return render_template("settings_profile.html", + v=v, + msg="Patron status verified!") + @app.post("/settings/titlecolor") @auth_required @validate_formkey