master
Aevann1 2021-12-23 16:55:44 +02:00
parent dbb52273d1
commit f8c9702f0a
6 changed files with 47 additions and 11 deletions

View File

@ -1014,7 +1014,7 @@ def api_sticky_post(post_id, v):
post = g.db.query(Submission).filter_by(id=post_id).first()
if post:
if post.stickied:
if post.stickied.startswith("t:"): abort(403)
if post.stickied.startswith("t:"): return {"error": "Can't unpin temporary pins!"}, 403
else: post.stickied = None
else:
pins = g.db.query(Submission.id).filter(Submission.stickied != None, Submission.is_banned == False).count()

View File

@ -253,6 +253,35 @@ def transfer_coins(v, username):
return {"message": f"You can't transfer {app.config['COINS_NAME']} to yourself!"}, 400
@app.post("/@<username>/transfer_bux")
@limiter.limit("1/second")
@is_not_banned
@validate_formkey
def transfer_coins(v, username):
receiver = g.db.query(User).filter_by(username=username).first()
if not receiver: return {"error": "That user doesn't exist."}, 404
if receiver.id != v.id:
amount = request.values.get("amount", "").strip()
amount = int(amount) if amount.isdigit() else None
if not amount or amount < 0: return {"error": f"Invalid amount of marseybux."}, 400
if v.procoins < amount: return {"error": f"You don't have enough marseybux"}, 400
if amount < 100: return {"error": f"You have to gift at least 100 marseybux."}, 400
receiver.procoins += amount
v.procoins -= amount
send_repeatable_notification(receiver.id, f"🤑 [@{v.username}]({v.url}) has gifted you {amount} marseybux!")
g.db.add(receiver)
g.db.add(v)
g.db.commit()
return {"message": f"{amount} marseybux transferred!"}, 200
return {"message": f"You can't transfer marseybux to yourself!"}, 400
@app.get("/leaderboard")
@auth_desired
def leaderboard(v):

View File

@ -98,7 +98,7 @@
<div class="text-left pl-2">
<div style="color: #{{v.namecolor}}" class="text-small font-weight-bold {% if v.patron %}patron{% endif %}"><span {% if v.patron %}class="patron" style="background-color:#{{v.namecolor}};"{% endif %}>{{v.username}}</span></div>
<div class="text-small-extra text-primary"><img class="mr-1 ml-1" data-bs-toggle="tooltip" data-bs-placement="bottom" height="13" src="/assets/images/emojis/marseycoin.webp" data-bs-original-title="{{'COINS_NAME' | app_config}}" aria-label="{{'COINS_NAME' | app_config}}"><span id="user-coins-amount">{{v.coins}}</span> {{'COINS_NAME' | app_config}}</div>
{% if v.procoins %}<div class="text-small-extra text-primary"><img class="mr-1 ml-1" data-bs-toggle="tooltip" data-bs-placement="bottom" height="13" src="/assets/images/emojis/marseybux.webp" data-bs-original-title="Marseybux" aria-label="Marseybux"><span>{{v.procoins}}</span> Marseybux</div>{% endif %}
{% if v.procoins %}<div class="text-small-extra text-primary"><img class="mr-1 ml-1" data-bs-toggle="tooltip" data-bs-placement="bottom" height="13" src="/assets/images/emojis/marseybux.webp" data-bs-original-title="Marseybux" aria-label="Marseybux"><span id="user-bux-amount">{{v.procoins}}</span> Marseybux</div>{% endif %}
</div>
</div>
</a>

View File

@ -190,6 +190,12 @@
<button class="btn btn-primary mt-3" onclick="transferCoins()">Gift</button>
</div>
<div class="d-none mt-3 profile-toggleable" id="bux-transfer">
<input autocomplete="off" id="bux-transfer-amount" class="form-control" name="amount" type="number" oninput="updateTax()">
<div>{{u.username}} will receive <span id="bux-transfer-taxed">0</span> marseybux</div>
<button class="btn btn-primary mt-3" onclick="transferBux()">Gift</button>
</div>
{% elif v and v.id == u.id %}
<a href="/settings/profile" class="btn btn-secondary">Edit profile</a>
<a href="/views" class="btn btn-secondary">Profile views</a>
@ -470,6 +476,13 @@
<div>{{u.username}} will receive <span id="coins-transfer-taxed-mobile">0</span> {{'COINS_NAME' | app_config}}</div>
<button class="btn btn-primary mt-3" onclick="transferCoins(true)">Gift</button>
</div>
<div class="d-none mt-3 profile-toggleable-mobile" id="bux-transfer-mobile">
<input autocomplete="off" id="bux-transfer-amount-mobile" class="form-control" name="amount" type="number" oninput="updateTax()">
<div>{{u.username}} will receive <span id="bux-transfer-taxed-mobile">0</span> marseybux</div>
<button class="btn btn-primary mt-3" onclick="transferBux(true)">Gift</button>
</div>
{% if v.admin_level > 1 %}
<button id="grant" class="{% if u.paid_dues %}d-none{% endif %} btn btn-success" onclick="post_toast2('/@{{u.username}}/club_allow','grant','bar')">Grant club access</button>
@ -677,7 +690,7 @@
{% if v %}
<div id='tax' class="d-none">{% if v.patron or u.patron %}0{% else %}0.03{% endif %}</div>
<script src="/assets/js/userpage_v.js?v=190"></script>
<script src="/assets/js/userpage_v.js?v=191"></script>
<div id="username" class="d-none">{{u.username}}</div>
{% endif %}

View File

@ -110,7 +110,7 @@
{% if v %}
<div id='tax' class="d-none">{% if v.patron or u.patron %}0{% else %}0.03{% endif %}</div>
<script src="/assets/js/userpage_v.js?v=190"></script>
<script src="/assets/js/userpage_v.js?v=191"></script>
<div id="username" class="d-none">{{u.username}}</div>
{% endif %}

View File

@ -35,12 +35,6 @@
<div id="uid" class="d-none">{{u.id}}</div>
{% endif %}
{% if v %}
<div id='tax' class="d-none">{% if v.patron or u.patron %}0{% else %}0.03{% endif %}</div>
<script src="/assets/js/userpage_v.js?v=190"></script>
<div id="username" class="d-none">{{u.username}}</div>
{% endif %}
<script src="/assets/js/userpage.js?v=190"></script>
{% endblock %}
@ -51,7 +45,7 @@
{% if v %}
<div id='tax' class="d-none">{% if v.patron or u.patron %}0{% else %}0.03{% endif %}</div>
<script src="/assets/js/userpage_v.js?v=190"></script>
<script src="/assets/js/userpage_v.js?v=191"></script>
<div id="username" class="d-none">{{u.username}}</div>
{% endif %}