remotes/1693045480750635534/spooky-22
Aevann1 2022-01-24 03:20:29 +02:00
parent 1930cc1ec8
commit 8c3066016e
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)

View File

@ -0,0 +1,69 @@
{% extends "default.html" %}
{% block title %}
<title>Grant User Award</title>
{% endblock %}
{% block pagetype %}message{% endblock %}
{% block content %}
{% if error %}
<div class="alert alert-danger alert-dismissible fade show my-3" role="alert">
<i class="fas fa-exclamation-circle my-auto"></i>
<span>
{{error}}
</span>
<button role="button" class="close" data-bs-dismiss="alert" aria-label="Close">
<span aria-hidden="true"><i class="far fa-times"></i></span>
</button>
</div>
{% endif %}
{% if msg %}
<div class="alert alert-success alert-dismissible fade show my-3" role="alert">
<i class="fas fa-check-circle my-auto" aria-hidden="true"></i>
<span>
{{msg}}
</span>
<button role="button" class="close" data-bs-dismiss="alert" aria-label="Close">
<span aria-hidden="true"><i class="far fa-times"></i></span>
</button>
</div>
{% endif %}
<pre></pre>
<pre></pre>
<h5>User Award Grant</h5>
<form action="/admin/awards", method="post">
<input autocomplete="off" type="hidden" name="formkey" value="{{v.formkey}}">
<label for="input-username">Username</label><br>
<input autocomplete="off" id="input-username" class="form-control mb-3" type="text" name="username" required>
<div class="overflow-x-auto"><table class="table table-striped">
<thead class="bg-primary text-white">
<tr>
<th scope="col">Icon</th>
<th scope="col">Title</th>
<th scope="col">Amount</th>
</tr>
</thead>
<tbody>
{% for a in awards %}
<tr>
<td><i class="{{a['icon']}} {{a['color']}}" style="font-size: 30px"></i></td>
<td style="font-weight: bold">{{a['title']}}</td>
<td><input autocomplete="off" type="number" class="form-control" name="{{a['kind']}}" value="0" min="0" max="10" placeholder="Enter amount..." ></td>
</tr>
{% endfor %}
</table>
<input autocomplete="off" class="btn btn-primary mt-3" type="submit" value="Grant Awards">
</form>
<pre></pre>
{% if request.host != 'rdrama.net' or v.id == AEVANN_ID %}
<div><a class="btn btn-danger" role="button" onclick="post_toast('/admin/monthly')">Grant Monthly Marseybux</a></div>
{% endif %}
{% endblock %}