master
Aevann1 2021-09-18 20:04:05 +02:00
parent 92b587bfea
commit 833058c2d1
3 changed files with 48 additions and 105 deletions

View File

@ -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"

View File

@ -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():

View File

@ -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,