forked from rDrama/rDrama
1
0
Fork 0

change award modal

master
Aevann 2023-10-10 19:53:46 +03:00
parent 6474b8b468
commit 7759229178
5 changed files with 48 additions and 75 deletions

View File

@ -102,19 +102,6 @@ function pick(kind, price, coins, marseybux) {
coins = parseInt(coins) coins = parseInt(coins)
marseybux = parseInt(marseybux) marseybux = parseInt(marseybux)
const buy = document.getElementById('buy')
if (kind == "grass" && coins < price)
buy.disabled = true;
else if (kind == "benefactor" && marseybux < price)
buy.disabled = true;
else if (coins+marseybux < price)
buy.disabled = true;
else
buy.disabled = false;
let ownednum = Number(document.getElementById(`${kind}-owned`).textContent);
document.getElementById('giveaward').disabled = (ownednum == 0);
document.getElementById('kind').value=kind; document.getElementById('kind').value=kind;
if (document.getElementsByClassName('picked').length > 0) { if (document.getElementsByClassName('picked').length > 0) {
document.getElementsByClassName('picked')[0].classList.toggle('picked'); document.getElementsByClassName('picked')[0].classList.toggle('picked');
@ -162,33 +149,18 @@ function pick(kind, price, coins, marseybux) {
document.getElementById('note').maxLength = 200; document.getElementById('note').maxLength = 200;
} }
document.getElementById('award_price_block').classList.remove('d-none'); const ownednum = Number(document.getElementById(`${kind}-owned`).textContent);
document.getElementById('award_price').textContent = price;
}
function buy() {
const kind = document.getElementById('kind').value;
url = `/buy/${kind}`
const xhr = createXhrWithFormKey(url);
xhr[0].onload = function() {
let data
try {data = JSON.parse(xhr[0].response)}
catch(e) {console.error(e)}
success = xhr[0].status >= 200 && xhr[0].status < 300;
showToast(success, getMessageFromJsonData(success, data));
if (success) {
if (kind != "lootbox")
{
document.getElementById('giveaward').disabled=false;
let owned = document.getElementById(`${kind}-owned`)
let ownednum = Number(owned.textContent) + 1;
owned.textContent = ownednum
}
}
};
xhr[0].send(xhr[1]);
if (ownednum) {
document.getElementById('award_price').textContent = `${ownednum} owned`;
document.getElementById('giveaward').classList.remove('d-none');
document.getElementById('buyandgiveaward').classList.add('d-none');
}
else {
document.getElementById('award_price').textContent = `Price: ${price} coins/marseybux`;
document.getElementById('giveaward').classList.add('d-none');
document.getElementById('buyandgiveaward').classList.remove('d-none');
}
} }
function giveaward(t) { function giveaward(t) {
@ -204,10 +176,10 @@ function giveaward(t) {
}, },
() => { () => {
let owned = document.getElementById(`${kind}-owned`) let owned = document.getElementById(`${kind}-owned`)
let ownednum = Number(owned.textContent) - 1; let ownednum = Number(owned.textContent);
owned.textContent = ownednum if (ownednum) {
if (ownednum == 0) owned.textContent = ownednum - 1
document.getElementById('giveaward').disabled=true; }
} }
); );
} }

View File

@ -189,6 +189,7 @@ document.addEventListener("click", function (e) {
return return
} }
document.getElementById('giveaward').dataset.action = element.dataset.url document.getElementById('giveaward').dataset.action = element.dataset.url
document.getElementById('buyandgiveaward').dataset.action = element.dataset.url
const effect_author_tab = document.getElementById('effect-author-tab') const effect_author_tab = document.getElementById('effect-author-tab')
const effect_content_tab = document.getElementById('effect-content-tab') const effect_content_tab = document.getElementById('effect-content-tab')

View File

@ -119,7 +119,7 @@ if (!location.pathname.endsWith('/submit') && !location.pathname.endsWith('/chat
const formDOM = targetDOM.parentElement; const formDOM = targetDOM.parentElement;
if (formDOM.id == 'note_section') { if (formDOM.id == 'note_section') {
document.getElementById('giveaward').click(); document.querySelector('.awardbtn:not(.d-none)').click();
return return
} }

View File

@ -52,31 +52,13 @@ def shop(v):
return render_template("shop.html", awards=list(AWARDS.values()), v=v, sales=sales) return render_template("shop.html", awards=list(AWARDS.values()), v=v, sales=sales)
@app.post("/buy/<award>") def buy_award(v, kind):
@limiter.limit('1/second', scope=rpath) og_price = AWARDS[kind]["price"]
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit("100/minute;200/hour;1000/day", deduct_when=lambda response: response.status_code < 400)
@limiter.limit("100/minute;200/hour;1000/day", deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
@auth_required
def buy(v, award):
if award == 'ghost':
abort(403, "You can't buy this award!")
AWARDS = deepcopy(AWARDS_ENABLED)
if v.house:
AWARDS[v.house] = HOUSE_AWARDS[v.house]
if award not in AWARDS: abort(400)
og_price = AWARDS[award]["price"]
award_title = AWARDS[award]['title']
price = int(og_price * v.award_discount) price = int(og_price * v.award_discount)
if kind == "grass":
if award == "grass":
currency = 'coins' currency = 'coins'
elif award == "benefactor": elif kind == "benefactor":
currency = 'marseybux' currency = 'marseybux'
else: else:
currency = 'combined' currency = 'combined'
@ -98,8 +80,7 @@ def buy(v, award):
badge_grant(badge_id=69, user=v) badge_grant(badge_id=69, user=v)
g.db.add(v) g.db.add(v)
if kind == "lootbox":
if award == "lootbox":
lootbox_items = [] lootbox_items = []
for _ in range(LOOTBOX_ITEM_COUNT): # five items per lootbox for _ in range(LOOTBOX_ITEM_COUNT): # five items per lootbox
if IS_FISTMAS(): if IS_FISTMAS():
@ -124,7 +105,7 @@ def buy(v, award):
return {"message": lootbox_msg} return {"message": lootbox_msg}
else: else:
award_object = AwardRelationship(user_id=v.id, kind=award, price_paid=price) award_object = AwardRelationship(user_id=v.id, kind=kind, price_paid=price)
g.db.add(award_object) g.db.add(award_object)
g.db.add(v) g.db.add(v)
@ -132,6 +113,26 @@ def buy(v, award):
if CARP_ID and v.id != CARP_ID and og_price >= 5000: if CARP_ID and v.id != CARP_ID and og_price >= 5000:
send_repeatable_notification(CARP_ID, f"@{v.username} has bought a `{award_title}` award!") send_repeatable_notification(CARP_ID, f"@{v.username} has bought a `{award_title}` award!")
return award_object
@app.post("/buy/<kind>")
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit("100/minute;200/hour;1000/day", deduct_when=lambda response: response.status_code < 400)
@limiter.limit("100/minute;200/hour;1000/day", deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
@auth_required
def buy(v, kind):
AWARDS = deepcopy(AWARDS_ENABLED)
if v.house:
AWARDS[v.house] = HOUSE_AWARDS[v.house]
if kind not in AWARDS: abort(400)
award_title = AWARDS[kind]['title']
buy_award(v, kind)
return {"message": f"{award_title} award bought!"} return {"message": f"{award_title} award bought!"}
@ -167,7 +168,8 @@ def award_thing(v, thing_type, id):
AwardRelationship.comment_id == None AwardRelationship.comment_id == None
).first() ).first()
if not award: abort(404, "You don't have that award") if not award:
award = buy_award(v, kind)
if thing_type == 'post': award.post_id = thing.id if thing_type == 'post': award.post_id = thing.id
else: award.comment_id = thing.id else: award.comment_id = thing.id

View File

@ -77,13 +77,11 @@
</div> </div>
</div> </div>
<input autocomplete="off" id="giveaward" class="awardbtn btn btn-primary fl-r" type="submit" data-nonce="{{g.nonce}}" data-onclick="giveaward(this)" value="Give Award" data-bs-dismiss="modal" disabled> <input autocomplete="off" id="giveaward" class="awardbtn btn btn-primary fl-r" type="submit" data-nonce="{{g.nonce}}" data-onclick="giveaward(this)" value="Give Award" data-bs-dismiss="modal">
<button type="button" id="buy" class="awardbtn btn btn-primary mr-3 fl-r" disabled data-areyousure="buy()" data-nonce="{{g.nonce}}" data-onclick="areyousure(this)">Buy</button> <input autocomplete="off" id="buyandgiveaward" class="awardbtn btn btn-primary fl-r d-none" type="submit" data-nonce="{{g.nonce}}" data-areyousure="giveaward(this)" data-onclick="areyousure(this)" value="Give Award" data-dismiss="modal">
<div id="award_price_block" class="fl-r mt-2 mr-3 d-none text-small-sm"> <span id="award_price" class="fl-r mt-2 mr-3 text-small-sm"></span>
Price: <span id="award_price"></span> coins/marseybux
</div>
</div> </div>
</div> </div>
</div> </div>