This commit is contained in:
Aevann1 2022-01-24 03:20:29 +02:00
parent 756c9536e3
commit 1c7b154304
2 changed files with 140 additions and 1 deletions

View file

@ -587,4 +587,74 @@ def award_comment(cid, v):
g.db.commit()
if request.referrer and len(request.referrer) > 1 and request.host in request.referrer:
return redirect(request.referrer)
return redirect("/")
return redirect("/")
@app.get("/admin/awards")
@admin_level_required(2)
def admin_userawards_get(v):
if v.admin_level != 3:
return render_template("admin/awards.html", awards=list(AWARDS3.values()), v=v)
return render_template("admin/awards.html", awards=list(AWARDS.values()), v=v)
@app.post("/admin/awards")
@limiter.limit("1/second;30/minute;200/hour;1000/day")
@admin_level_required(2)
def admin_userawards_post(v):
try: u = request.values.get("username").strip()
except: abort(404)
u = get_user(u, graceful=False, v=v)
notify_awards = {}
latest = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first()
thing = latest.id
for key, value in request.values.items():
if key not in AWARDS: continue
if value:
if int(value) > 10: abort(403)
if int(value): notify_awards[key] = int(value)
for x in range(int(value)):
thing += 1
award = AwardRelationship(
id=thing,
user_id=u.id,
kind=key
)
g.db.add(award)
if v.id != u.id:
text = "You were given the following awards:\n\n"
for key, value in notify_awards.items():
text += f" - **{value}** {AWARDS[key]['title']} {'Awards' if value != 1 else 'Award'}\n"
send_repeatable_notification(u.id, text)
note = ""
for key, value in notify_awards.items():
note += f"{value} {AWARDS[key]['title']}, "
if len(note) > 256: return {"error": "You're giving too many awards at the same time!"}
ma=ModAction(
kind="grant_awards",
user_id=v.id,
target_user_id=u.id,
_note=note[:-2]
)
g.db.add(ma)
g.db.commit()
if v.admin_level != 3: return render_template("admin/awards.html", awards=list(AWARDS3.values()), v=v)
return render_template("admin/awards.html", awards=list(AWARDS.values()), v=v)