added a gift message to go with coin and bux transfers

master
Ubuntu 2022-05-31 22:56:34 -04:00 committed by TLSM
parent 49622b3268
commit 453d5f57a3
2 changed files with 18 additions and 2 deletions

View File

@ -403,6 +403,7 @@ def transfer_coins(v, username):
if receiver.id != v.id:
amount = request.values.get("amount", "").strip()
amount = int(amount) if amount.isdigit() else None
reason = request.values.get("reason", "").strip()
if amount is None or amount <= 0: return {"error": "Invalid amount of coins."}, 400
if v.coins < amount: return {"error": "You don't have enough coins."}, 400
@ -416,11 +417,16 @@ def transfer_coins(v, username):
receiver.coins += amount-tax
v.coins -= amount
send_repeatable_notification(receiver.id, f":marseycapitalistmanlet: @{v.username} has gifted you {amount-tax} coins!")
if reason: text = f":marseycapitalistmanlet: @{v.username} has gifted you {amount-tax} coins!\n\n> {reason}"
else: text = f":marseycapitalistmanlet: @{v.username} has gifted you {amount-tax} coins!"
send_repeatable_notification(receiver.id, text)
g.db.add(receiver)
g.db.add(v)
g.db.commit()
return {"message": f"{amount-tax} coins transferred!"}, 200
return {"message": "You can't transfer coins to yourself!"}, 400
@ -438,6 +444,8 @@ def transfer_bux(v, username):
if receiver.id != v.id:
amount = request.values.get("amount", "").strip()
amount = int(amount) if amount.isdigit() else None
reason = request.values.get("reason", "").strip()
if not amount or amount < 0: return {"error": "Invalid amount of marseybux."}, 400
if v.procoins < amount: return {"error": "You don't have enough marseybux"}, 400
@ -448,7 +456,11 @@ def transfer_bux(v, username):
receiver.procoins += amount
v.procoins -= amount
send_repeatable_notification(receiver.id, f":marseycapitalistmanlet: @{v.username} has gifted you {amount} marseybux!")
if reason: text = f":marseycapitalistmanlet: @{v.username} has gifted you {amount} bux!\n\n> {reason}"
else: text = f":marseycapitalistmanlet: @{v.username} has gifted you {amount} bux!"
send_repeatable_notification(receiver.id, text)
g.db.add(receiver)
g.db.add(v)

View File

@ -215,12 +215,14 @@
<div class="d-none mt-3 toggleable" id="coin-transfer">
<input autocomplete="off" id="coin-transfer-amount" class="form-control" name="amount" type="number" oninput="updateTax()">
<div>{{u.username}} will receive <span id="coins-transfer-taxed">0</span> coins</div>
<input autocomplete="off" id="coin-transfer-reason" type="text" class="form-control" name="reason" placeholder="Gift message! (optional)">
<button class="btn btn-primary mt-3" onclick="transferCoins()">Gift</button>
</div>
<div class="d-none mt-3 toggleable" id="bux-transfer">
<input autocomplete="off" id="bux-transfer-amount" class="form-control" name="amount" type="number" oninput="updateBux()">
<div>{{u.username}} will receive <span id="bux-transfer-taxed">0</span> marseybux</div>
<input autocomplete="off" id="bux-transfer-reason" type="text" class="form-control" name="reason" placeholder="Gift message! (optional)">
<button class="btn btn-primary mt-3" onclick="transferBux()">Gift</button>
</div>
@ -523,12 +525,14 @@
<div class="d-none mt-3 toggleable" id="coin-transfer-mobile">
<input autocomplete="off" id="coin-transfer-amount-mobile" class="form-control" name="amount" type="number" oninput="updateTax(true)">
<div>{{u.username}} will receive <span id="coins-transfer-taxed-mobile">0</span> coins</div>
<input autocomplete="off" id="coin-transfer-reason-mobile" type="text" class="form-control" name="reason" placeholder="Gift message! (optional)">
<button class="btn btn-primary mt-2 mb-3" onclick="transferCoins(true)">Gift</button>
</div>
<div class="d-none mt-3 toggleable" id="bux-transfer-mobile">
<input autocomplete="off" id="bux-transfer-amount-mobile" class="form-control" name="amount" type="number" oninput="updateBux(true)">
<div>{{u.username}} will receive <span id="bux-transfer-taxed-mobile">0</span> marseybux</div>
<input autocomplete="off" id="bux-transfer-reason-mobile" type="text" class="form-control" name="reason" placeholder="Gift message! (optional)">
<button class="btn btn-primary mt-2 mb-3" onclick="transferBux(true)">Gift</button>
</div>