add bulk buying for awards

master
Aevann 2024-04-12 13:08:03 +02:00
parent ab8af17af8
commit 57a79b2cb2
3 changed files with 436 additions and 426 deletions

View File

@ -182,7 +182,8 @@ function giveaward(t) {
{
"kind": kind,
"note": document.getElementById(note_id).value,
"emoji_behavior": document.getElementById("emoji_behavior").value
"emoji_behavior": document.getElementById("emoji_behavior").value,
"award_quantity": document.getElementById("award_quantity").value,
},
() => {
let owned = document.getElementById(`${kind}-owned`)

View File

@ -180,6 +180,12 @@ def award_thing(v, thing_type, id):
if obj.is_longpost and kind in {"ectoplasm", "candycorn", "candycane", "stab", "glowie", "tilt", "queen", "chud", "marsify", "Furry", "Edgy", "Femboy", "Furry Founder", "Edgy Founder", "Femboy Founder"}:
abort(403, f'Long posts are protected from the {award_title} award!')
award_quantity = int(request.values.get("award_quantity", "1").strip())
if award_quantity < 1 or award_quantity > 30:
award_quantity = 1
for x in range(award_quantity):
g.db.flush()
award = g.db.query(AwardRelationship).filter(
AwardRelationship.kind == kind,
AwardRelationship.user_id == v.id,
@ -665,7 +671,8 @@ def award_thing(v, thing_type, id):
if emoji_behavior == "horizontal":
award.kind = "emoji-hz"
return {"message": f"{award_title} award given to {thing_type} successfully!"}
plural = '' if award_quantity == 1 else 's'
return {"message": f"{award_title} award{plural} given to {thing_type} successfully!"}
@app.post("/trick_or_treat")
@limiter.limit("1/hour", key_func=lambda:f'{SITE}-{session.get("lo_user")}')

View File

@ -97,6 +97,8 @@
<button type="button" id="buyandgiveaward" class="awardbtn btn btn-primary fl-r d-none" data-nonce="{{g.nonce}}" data-areyousure="giveaward(this)" data-onclick="areyousure(this)" data-dismiss="modal">Give Award</button>
<input autocomplete="off" type="number" step="any" min="1" max="30" inputmode="numeric" id="award_quantity" class="form-control d-inline-block mr-1 fl-r text-center" style="width:40px" value="1" required>
<span id="award_price" class="fl-r mt-2 mr-3 text-small-sm"></span>
</div>
</div>