From b7e4f27f65cb714d64d82d8c8defa3a2e7632f96 Mon Sep 17 00:00:00 2001 From: Aevann Date: Wed, 1 Feb 2023 21:04:15 +0200 Subject: [PATCH] use transactions table in rdrama --- env_template | 2 - files/helpers/config/const.py | 4 -- files/helpers/config/modaction_types.py | 5 -- files/helpers/cron.py | 53 ------------------- files/routes/settings.py | 37 ------------- files/routes/users.py | 10 ++-- files/templates/settings/security.html | 6 +-- ...01-use-transactions-table-in-rdramasql.sql | 1 + 8 files changed, 6 insertions(+), 112 deletions(-) create mode 100644 migrations/20230201-use-transactions-table-in-rdramasql.sql diff --git a/env_template b/env_template index 8e5a6e90b..756e3fa6b 100644 --- a/env_template +++ b/env_template @@ -13,9 +13,7 @@ export TURNSTILE_SECRET="blahblahblah" export YOUTUBE_KEY="blahblahblah" export VAPID_PUBLIC_KEY="blahblahblah" export VAPID_PRIVATE_KEY="blahblahblah" -export GUMROAD_TOKEN="blahblahblah" export GUMROAD_LINK="blahblahblah" -export GUMROAD_ID="blahblahblah" export CF_KEY="blahblahblah" export CF_ZONE="blahblahblah" export DEBIAN_FRONTEND="noninteractive" diff --git a/files/helpers/config/const.py b/files/helpers/config/const.py index 7d01351e5..4f81b69ab 100644 --- a/files/helpers/config/const.py +++ b/files/helpers/config/const.py @@ -42,9 +42,7 @@ TURNSTILE_SECRET = environ.get("TURNSTILE_SECRET").strip() YOUTUBE_KEY = environ.get("YOUTUBE_KEY").strip() VAPID_PUBLIC_KEY = environ.get("VAPID_PUBLIC_KEY").strip() VAPID_PRIVATE_KEY = environ.get("VAPID_PRIVATE_KEY").strip() -GUMROAD_TOKEN = environ.get("GUMROAD_TOKEN").strip() GUMROAD_LINK = environ.get("GUMROAD_LINK").strip() -GUMROAD_ID = environ.get("GUMROAD_ID").strip() CF_KEY = environ.get("CF_KEY").strip() CF_ZONE = environ.get("CF_ZONE").strip() GLOBAL = environ.get("GLOBAL", "").strip() @@ -615,7 +613,6 @@ HOLE_COST = 0 HOLE_INACTIVITY_DELETION = False PRIVILEGED_USER_BOTS = () -GUMROAD_MESSY = () AUTOJANNY_ID = 1 SNAPPY_ID = 2 @@ -713,7 +710,6 @@ if SITE == 'rdrama.net': HOLE_INACTIVITY_DELETION = True PRIVILEGED_USER_BOTS = (12125,16049) - GUMROAD_MESSY = (1379) AUTOJANNY_ID = 1046 SNAPPY_ID = 261 diff --git a/files/helpers/config/modaction_types.py b/files/helpers/config/modaction_types.py index 09cf48891..e877c3e78 100644 --- a/files/helpers/config/modaction_types.py +++ b/files/helpers/config/modaction_types.py @@ -186,11 +186,6 @@ MODACTION_TYPES = { "icon": 'fa-file-signature', "color": 'bg-success' }, - 'monthly': { - "str": 'distributed monthly marseybux', - "icon": 'fa-sack-dollar', - "color": 'bg-success' - }, 'move_hole': { "str": 'changed hole of {self.target_link}', "icon": 'fa-manhole', diff --git a/files/helpers/cron.py b/files/helpers/cron.py index aa6368793..989759c51 100644 --- a/files/helpers/cron.py +++ b/files/helpers/cron.py @@ -42,9 +42,6 @@ def cron(every_5m, every_1h, every_1d, every_1mo): site_stats = stats.stats(SITE_NAME) cache.set(f'{SITE}_stats', site_stats) - if every_1mo and not KOFI_LINK: - _give_monthly_marseybux_task() - g.db.commit() g.db.close() del g.db @@ -109,53 +106,3 @@ def _sub_inactive_purge_task(): g.db.delete(x) return True - - -def _give_monthly_marseybux_task(): - month = datetime.datetime.now() + datetime.timedelta(days=5) - month = month.strftime('%B') - - data = {'access_token': GUMROAD_TOKEN} - - emails = [x['email'] for x in requests.get(f'https://api.gumroad.com/v2/products/{GUMROAD_ID}/subscribers', data=data, timeout=5).json()["subscribers"]] - - def give_marseybux(u): - marseybux_reward = marseybux_li[u.patron] - u.pay_account('marseybux', marseybux_reward) - send_repeatable_notification(u.id, f"@AutoJanny has given you {marseybux_reward} Marseybux for the month of {month}! You can use them to buy awards or hats in the [shop](/shop) or gamble them in the [casino](/casino).") - - for badge in g.db.query(Badge).filter(Badge.badge_id > 20, Badge.badge_id < 28).all(): - g.db.delete(badge) - - for u in g.db.query(User).filter(User.patron > 0, User.patron_utc == 0).all(): - g.db.add(u) - if u.admin_level or u.id == GUMROAD_MESSY: - give_marseybux(u) - badge_grant(badge_id=20+u.patron, user=u, notify=False) - elif u.email and u.is_activated and u.email.lower() in emails: - data = {'access_token': GUMROAD_TOKEN, 'email': u.email} - try: - response = requests.get('https://api.gumroad.com/v2/sales', data=data, timeout=5).json()["sales"] - except: - print(f'Marseybux monthly granting failed for @{u.username}', flush=True) - u.patron = 0 - continue - - if len(response) == 0: - u.patron = 0 - continue - response = [x for x in response if x['variants_and_quantity']][0] - tier = tiers[response["variants_and_quantity"]] - u.patron = tier - badge_grant(badge_id=20+tier, user=u, notify=False) - give_marseybux(u) - else: - u.patron = 0 - - ma = ModAction( - kind="monthly", - user_id=AUTOJANNY_ID, - ) - g.db.add(ma) - - return True diff --git a/files/routes/settings.py b/files/routes/settings.py index d099a5e12..ff76cabf5 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -400,43 +400,6 @@ def namecolor(v): def themecolor(v): return set_color(v, "themecolor", request.values.get("themecolor")) -@app.post("/settings/gumroad") -@limiter.limit(DEFAULT_RATELIMIT_SLOWER) -@limiter.limit(DEFAULT_RATELIMIT_SLOWER, key_func=get_ID) -@auth_required -def settings_gumroad(v): - if GUMROAD_TOKEN == DEFAULT_CONFIG_VALUE: abort(404) - if not (v.email and v.is_activated): - abort(400, f"You must have a verified email to verify {patron} status and claim your rewards!") - - data = {'access_token': GUMROAD_TOKEN, 'email': v.email} - response = requests.get('https://api.gumroad.com/v2/sales', data=data, timeout=5).json()["sales"] - - if len(response) == 0: abort(404, "Email not found") - - response = [x for x in response if x['variants_and_quantity']] - response = response[0] - tier = tiers[response["variants_and_quantity"]] - if v.patron == tier: abort(400, f"{patron} rewards already claimed!") - - marseybux = marseybux_li[tier] - marseybux_li[v.patron] - if marseybux < 0: abort(400, f"{patron} rewards already claimed!") - - existing = g.db.query(User.id).filter(User.email == v.email, User.is_activated == True, User.patron >= tier).first() - if existing: abort(400, f"{patron} rewards already claimed on another account") - - v.patron = tier - - v.pay_account('marseybux', marseybux) - send_repeatable_notification(v.id, f"You have received {marseybux} Marseybux! You can use them to buy awards or hats in the [shop](/shop) or gamble them in the [casino](/casino).") - - g.db.add(v) - - badge_grant(badge_id=20+tier, user=v) - - - return {"message": f"{patron} rewards claimed!"} - @app.post("/settings/titlecolor") @limiter.limit(DEFAULT_RATELIMIT_SLOWER) @limiter.limit(DEFAULT_RATELIMIT_SLOWER, key_func=get_ID) diff --git a/files/routes/users.py b/files/routes/users.py index 71bb1fee8..f08e1b6ad 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -1361,21 +1361,19 @@ def gumroad(): g.db.add(transaction) user = g.db.query(User).filter_by(email=email, is_activated=True).order_by(User.truescore.desc()).first() - # if user: - # claim_rewards(user) + if user: + claim_rewards(user) return '' -@app.post("/settings/kofi") +@app.post("/settings/claim_rewards") @limiter.limit(DEFAULT_RATELIMIT_SLOWER) @limiter.limit(DEFAULT_RATELIMIT_SLOWER, key_func=get_ID) @auth_required -def settings_kofi(v:User): - if not KOFI_TOKEN: abort(404) - +def claim_rewards(v:User): if not (v.email and v.is_activated): abort(400, f"You must have a verified email to verify {patron} status and claim your rewards!") diff --git a/files/templates/settings/security.html b/files/templates/settings/security.html index 6ae65e214..2feddf50b 100644 --- a/files/templates/settings/security.html +++ b/files/templates/settings/security.html @@ -35,11 +35,7 @@