From 255bc5ca6b9266455895e563c8d098b8d313f21e Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Mon, 17 Jan 2022 22:29:06 +0200 Subject: [PATCH] bvv --- files/assets/js/award_modal.js | 70 +++++++++++++++++++++++++++++++- files/helpers/const.py | 11 +++-- files/routes/awards.py | 2 +- files/routes/front.py | 8 ++-- files/templates/award_modal.html | 29 +++++++++---- 5 files changed, 101 insertions(+), 19 deletions(-) diff --git a/files/assets/js/award_modal.js b/files/assets/js/award_modal.js index b924612dd..da71fb2ea 100644 --- a/files/assets/js/award_modal.js +++ b/files/assets/js/award_modal.js @@ -81,7 +81,10 @@ function awardModal(link) { } function bruh(kind) { - document.getElementById('giveaward').disabled=false; + document.getElementById('buy1').disabled=false; + document.getElementById('buy2').disabled=false; + let ownednum = Number(document.getElementById(`${kind}-owned`).textContent); + document.getElementById('giveaward').disabled = (ownednum == 0); document.getElementById('kind').value=kind; try {document.getElementsByClassName('picked')[0].classList.toggle('picked');} catch(e) {console.log(e)} document.getElementById(kind).classList.toggle('picked') @@ -93,4 +96,69 @@ function bruh(kind) { document.getElementById('notelabel').innerHTML = "Note (optional):"; document.getElementById('note').placeholder = "Note to include in award notification"; } +} + +function bruh2(kind) { + console.log(kind) + let buy1 = document.getElementById('buy1') + if (kind == "grass") buy1.disabled=true; + else buy1.disabled=false; + let buy2 = document.getElementById('buy1') + if (kind == "benefactor") buy2.disabled=true; + else buy2.disabled=false; + document.getElementById('giveaward').disabled=true; + document.getElementById('kind').value=kind; + let picked = document.getElementsByClassName('picked')[0] + if (picked) picked.classList.remove('picked') + document.getElementById(kind).classList.toggle('picked') + if (kind == "flairlock") { + document.getElementById('notelabel').innerHTML = "New flair:"; + document.getElementById('note').placeholder = "Insert new flair here, or leave empty to add 1 day to the duration of the current flair"; + } + else { + document.getElementById('notelabel').innerHTML = "Note (optional):"; + document.getElementById('note').placeholder = "Note to include in award notification"; + } +} + +function buy(mb) { + document.getElementById('toast-post-error-text').innerText = "Error, please try again later." + const kind = document.getElementById('kind').value; + const xhr = new XMLHttpRequest(); + url = `/buy/${kind}` + if (mb) url += "?mb=true" + xhr.open("POST", url, true); + xhr.setRequestHeader('xhr', 'xhr'); + var form = new FormData() + form.append("formkey", formkey()); + + if(typeof data === 'object' && data !== null) { + for(let k of Object.keys(data)) { + form.append(k, data[k]); + } + } + + + form.append("formkey", formkey()); + xhr.withCredentials=true; + + xhr.onload = function() { + let data + try {data = JSON.parse(xhr.response)} + catch(e) {console.log(e)} + if (xhr.status >= 200 && xhr.status < 300 && data && data["message"]) { + document.getElementById('toast-post-success-text2').innerText = data["message"]; + new bootstrap.Toast(document.getElementById('toast-post-success2')).show(); + document.getElementById('giveaward').disabled=false; + let owned = document.getElementById(`${kind}-owned`) + let ownednum = Number(owned.textContent); + owned.textContent = ownednum + 1 + } else { + if (data && data["error"]) document.getElementById('toast-post-error-text2').innerText = data["error"]; + new bootstrap.Toast(document.getElementById('toast-post-error2')).show(); + } + }; + + xhr.send(form); + } \ No newline at end of file diff --git a/files/helpers/const.py b/files/helpers/const.py index 148f7f6d2..cbfa61e79 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -149,6 +149,7 @@ if SITE == 'rdrama.net': JOAN_ID = 28 MOOSE_ID = 1904 AEVANN_ID = 1 + Q_ID = 1480 LAWLZ_ID = 3833 LLM_ID = 253 DAD_ID = 2513 @@ -176,6 +177,7 @@ elif SITE == "pcmemes.net": JOAN_ID = 0 MOOSE_ID = 0 AEVANN_ID = 1 + Q_ID = 0 LAWLZ_ID = 0 LLM_ID = 0 DAD_ID = 0 @@ -203,6 +205,7 @@ else: JOAN_ID = 0 MOOSE_ID = 0 AEVANN_ID = 0 + Q_ID = 0 LAWLZ_ID = 0 LLM_ID = 0 DAD_ID = 0 @@ -288,8 +291,8 @@ BADGES = { 'description': 'Contributed at least $100' }, 26: { - 'name': 'Rightoid Agendaposter', - 'description': 'Forced to use the agendaposter theme' + 'name': 'Rightoid', + 'description': 'Forced to use the rightoid theme' }, 27: { 'name': 'Lolcow', @@ -656,8 +659,8 @@ AWARDS = { }, "agendaposter": { "kind": "agendaposter", - "title": "Rightoid Agendaposter", - "description": "Forces the agendaposter theme on the recipient for 24 hours.", + "title": "Rightoid", + "description": "Forces the rightoid theme on the recipient for 24 hours.", "icon": "fas fa-snooze", "color": "text-purple", "price": 2500 diff --git a/files/routes/awards.py b/files/routes/awards.py index 483ee4901..6a4ed52d2 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -84,7 +84,7 @@ def shop(v): @auth_required def buy(v, award): if award == 'benefactor' and not request.values.get("mb"): - return {"error": "You can only buy this award with marseybux."}, 403 + return {"error": "You can only buy the Benefactor award with marseybux."}, 403 AWARDS = deepcopy(AWARDS2) diff --git a/files/routes/front.py b/files/routes/front.py index 13e27abe7..369290f8c 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -219,8 +219,8 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words=' else: cutoff = now - 86400 posts = posts.filter(Submission.created_utc >= cutoff) - if sort != "hot": posts = posts.filter_by(is_banned=False, private=False, deleted_utc = 0) - else: posts = posts.filter_by(is_banned=False, stickied=None, private=False, deleted_utc = 0) + if sort == "hot" or v.id == Q_ID: posts = posts.filter_by(is_banned=False, stickied=None, private=False, deleted_utc = 0) + else: posts = posts.filter_by(is_banned=False, private=False, deleted_utc = 0) if v and v.admin_level == 0: blocking = [x[0] for x in g.db.query( @@ -247,7 +247,7 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words=' if not (v and v.shadowbanned): posts = posts.join(User, User.id == Submission.author_id).filter(User.shadowbanned == None) - if sort == "hot": + if sort == "hot" or v.id == Q_ID: ti = int(time.time()) + 3600 posts = posts.order_by(-1000000*(Submission.realupvotes + 1 + Submission.comment_count/5)/(func.power(((ti - Submission.created_utc)/1000), 1.23))) elif sort == "new": @@ -272,7 +272,7 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words=' posts = posts[:size] - if sort == "hot" and page == 1: + if (sort == "hot" or v.id == Q_ID) and page == 1: pins = g.db.query(Submission).filter(Submission.stickied != None, Submission.is_banned == False) if v and v.admin_level == 0: blocking = [x[0] for x in g.db.query(UserBlock.target_id).filter_by(user_id=v.id).all()] diff --git a/files/templates/award_modal.html b/files/templates/award_modal.html index 2b4b5aa41..4221f1c8f 100644 --- a/files/templates/award_modal.html +++ b/files/templates/award_modal.html @@ -1,4 +1,4 @@ - + + + + \ No newline at end of file