diff --git a/files/routes/admin.py b/files/routes/admin.py index 5b091951a..426560650 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -137,110 +137,57 @@ def remove_fake_admin(v, username): return {"message": "Fake admin removed!"} -@app.get("/admin/monthly") +@app.post("/admin/monthly") +@limiter.limit("1/day") @admin_level_required(6) def monthly(v): - thing = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first().id - _awards = [] - t = time.time() - for u in g.db.query(User).options(lazyload('*')).filter(User.patron > 0).all(): - grant_awards = {} + if 'pcm' in request.host or ('rdrama' in request.host and v.id in [1,12,28,29,747,995,1480]) or ('rdrama' not in request.host and 'pcm' not in request.host): + thing = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first().id + for u in g.db.query(User).options(lazyload('*')).filter(User.patron > 0).all(): + grant_awards = {} - if u.patron == 1: - grant_awards["shit"] = 1 - grant_awards["stars"] = 1 - elif u.patron == 2: - grant_awards["shit"] = 3 - grant_awards["stars"] = 3 - elif u.patron == 3: - grant_awards["shit"] = 5 - grant_awards["stars"] = 5 - grant_awards["ban"] = 1 - elif u.patron == 4: - grant_awards["shit"] = 10 - grant_awards["stars"] = 10 - grant_awards["ban"] = 3 - elif u.patron == 5 or u.patron == 8: - grant_awards["shit"] = 20 - grant_awards["stars"] = 20 - grant_awards["ban"] = 6 + if u.patron == 1: + grant_awards["shit"] = 1 + grant_awards["stars"] = 1 + elif u.patron == 2: + grant_awards["shit"] = 3 + grant_awards["stars"] = 3 + elif u.patron == 3: + grant_awards["shit"] = 5 + grant_awards["stars"] = 5 + grant_awards["ban"] = 1 + elif u.patron == 4: + grant_awards["shit"] = 10 + grant_awards["stars"] = 10 + grant_awards["ban"] = 3 + elif u.patron == 5 or u.patron == 8: + grant_awards["shit"] = 20 + grant_awards["stars"] = 20 + grant_awards["ban"] = 6 - for name in grant_awards: - for count in range(grant_awards[name]): + for name in grant_awards: + for count in range(grant_awards[name]): - thing += 1 + thing += 1 - _awards.append(AwardRelationship( - id=thing, - user_id=u.id, - kind=name - )) + award = AwardRelationship( + id=thing, + user_id=u.id, + kind=name + ) - text = "You were given the following awards:\n\n" + g.db.add(award) - for key, value in grant_awards.items(): - text += f" - **{value}** {AWARDS[key]['title']} {'Awards' if value != 1 else 'Award'}\n" + text = "You were given the following awards:\n\n" - send_notification(NOTIFICATIONS_ACCOUNT, u, text) + for key, value in grant_awards.items(): + text += f" - **{value}** {AWARDS[key]['title']} {'Awards' if value != 1 else 'Award'}\n" + + send_notification(NOTIFICATIONS_ACCOUNT, u, text) - g.db.add_all(_awards) g.db.commit() - print(time.time() - t) - return {"message": "Monthly awards granted"} - - - -@app.get("/admin/monthly2") -@admin_level_required(6) -def monthly2(v): - thing = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first().id - t = time.time() - for u in g.db.query(User).options(lazyload('*')).filter(User.patron > 0).all(): - grant_awards = {} - - if u.patron == 1: - grant_awards["shit"] = 1 - grant_awards["stars"] = 1 - elif u.patron == 2: - grant_awards["shit"] = 3 - grant_awards["stars"] = 3 - elif u.patron == 3: - grant_awards["shit"] = 5 - grant_awards["stars"] = 5 - grant_awards["ban"] = 1 - elif u.patron == 4: - grant_awards["shit"] = 10 - grant_awards["stars"] = 10 - grant_awards["ban"] = 3 - elif u.patron == 5 or u.patron == 8: - grant_awards["shit"] = 20 - grant_awards["stars"] = 20 - grant_awards["ban"] = 6 - - - for name in grant_awards: - for count in range(grant_awards[name]): - - thing += 1 - - a = AwardRelationship( - id=thing, - user_id=u.id, - kind=name - ) - g.db.add(a) - - text = "You were given the following awards:\n\n" - - for key, value in grant_awards.items(): - text += f" - **{value}** {AWARDS[key]['title']} {'Awards' if value != 1 else 'Award'}\n" - - send_notification(NOTIFICATIONS_ACCOUNT, u, text) - - g.db.commit() - print(time.time() - t) return {"message": "Monthly awards granted"} @@ -462,8 +409,6 @@ def badge_grant_post(v): if len(grant_awards): - _awards = [] - thing = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first().id for name in grant_awards: @@ -471,13 +416,13 @@ def badge_grant_post(v): thing += 1 - _awards.append(AwardRelationship( + award = AwardRelationship( id=thing, user_id=user.id, kind=name - )) + ) - g.db.add_all(_awards) + g.db.add(award) text = "You were given the following awards:\n\n" diff --git a/files/routes/awards.py b/files/routes/awards.py index c61e402c2..7befead97 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -330,7 +330,6 @@ def admin_userawards_post(v): u = get_user(request.form.get("username", '1'), graceful=False, v=v) - awards = [] notify_awards = {} latest = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first() @@ -348,13 +347,14 @@ def admin_userawards_post(v): for x in range(int(value)): thing += 1 - awards.append(AwardRelationship( + award = AwardRelationship( id=thing, user_id=u.id, kind=key - )) + ) + + g.db.add(award) - g.db.add_all(awards) text = "You were given the following awards:\n\n" for key, value in notify_awards.items(): diff --git a/files/routes/settings.py b/files/routes/settings.py index 681886179..0e6dad8bc 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -339,8 +339,6 @@ def gumroad(v): grant_awards["stars"] = 20 grant_awards["ban"] = 6 - _awards = [] - thing = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first().id for name in grant_awards: @@ -348,13 +346,13 @@ def gumroad(v): thing += 1 - _awards.append(AwardRelationship( + award = AwardRelationship( id=thing, user_id=v.id, kind=name - )) + ) - g.db.add_all(_awards) + g.db.add(award) if not v.has_badge(20+tier): new_badge = Badge(badge_id=20+tier,