diff --git a/files/routes/awards.py b/files/routes/awards.py index 3021cdee19..3571f1aa63 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -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("/") \ No newline at end of file + 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) \ No newline at end of file diff --git a/files/templates/admin/awards.html b/files/templates/admin/awards.html new file mode 100644 index 0000000000..ec9862d93d --- /dev/null +++ b/files/templates/admin/awards.html @@ -0,0 +1,69 @@ +{% extends "default.html" %} + +{% block title %} +Grant User Award +{% endblock %} + +{% block pagetype %}message{% endblock %} + +{% block content %} + + {% if error %} + + {% endif %} + {% if msg %} + + {% endif %} + +

+	

+	
User Award Grant
+ +
+ +
+ + +
+ + + + + + + + + {% for a in awards %} + + + + + + {% endfor %} +
IconTitleAmount
{{a['title']}}
+ + + + + +

+	{% if request.host != 'rdrama.net' or v.id == AEVANN_ID %}
+		
Grant Monthly Marseybux
+ {% endif %} +{% endblock %} \ No newline at end of file