Merge branch 'frost' of https://github.com/Aevann1/rDrama into frost

master
Aevann1 2022-09-13 18:03:15 +00:00
commit 906c8b5138
14 changed files with 96 additions and 27 deletions

View File

@ -88,9 +88,11 @@ if not path.isfile(f'/site_settings.json'):
def before_request(): def before_request():
g.agent = request.headers.get("User-Agent") g.agent = request.headers.get("User-Agent")
if not g.agent: return 'Please use a "User-Agent" header!', 403 if not g.agent and request.path != '/kofi':
return 'Please use a "User-Agent" header!', 403
ua = g.agent.lower() ua = g.agent or ''
ua = ua.lower()
with open('/site_settings.json', 'r', encoding='utf_8') as f: with open('/site_settings.json', 'r', encoding='utf_8') as f:
app.config['SETTINGS'] = json.load(f) app.config['SETTINGS'] = json.load(f)
@ -98,7 +100,7 @@ def before_request():
if request.host != app.config["SERVER_NAME"]: return {"error":"Unauthorized host provided."}, 401 if request.host != app.config["SERVER_NAME"]: return {"error":"Unauthorized host provided."}, 401
if request.headers.get("CF-Worker"): return {"error":"Cloudflare workers are not allowed to access this website."}, 401 if request.headers.get("CF-Worker"): return {"error":"Cloudflare workers are not allowed to access this website."}, 401
if not app.config['SETTINGS']['Bots'] and request.headers.get("Authorization"): abort(503) if not app.config['SETTINGS']['Bots'] and request.headers.get("Authorization"): abort(403)
g.db = db_session() g.db = db_session()
g.webview = '; wv) ' in ua g.webview = '; wv) ' in ua

View File

@ -31,7 +31,7 @@ function transferCoins(mobile=false) {
this.disabled = true; this.disabled = true;
let amount = parseInt(document.getElementById("coin-transfer-amount").value); let amount = parseInt(document.getElementById(mobile ? "coin-transfer-amount-mobile" : "coin-transfer-amount").value);
let transferred = amount - Math.ceil(amount*TRANSFER_TAX); let transferred = amount - Math.ceil(amount*TRANSFER_TAX);
let username = document.getElementById('username').innerHTML; let username = document.getElementById('username').innerHTML;
@ -59,7 +59,7 @@ function transferBux(mobile=false) {
this.disabled = true; this.disabled = true;
let amount = parseInt(document.getElementById("bux-transfer-amount").value); let amount = parseInt(document.getElementById(mobile ? "bux-transfer-amount-mobile" : "bux-transfer-amount").value);
let username = document.getElementById('username').innerHTML let username = document.getElementById('username').innerHTML
post_toast_callback(`/@${username}/transfer_bux`, post_toast_callback(`/@${username}/transfer_bux`,

View File

@ -51,6 +51,8 @@ class Badge(Base):
@lazy @lazy
def until(self): def until(self):
if self.badge_id == 28 and self.user.agendaposter != 1: return self.user.agendaposter if self.badge_id == 28 and self.user.agendaposter != 1: return self.user.agendaposter
if self.badge_id == 170 and self.user.marsify != 1: return self.user.marsify
if self.badge_id == 94: return self.user.progressivestack if self.badge_id == 94: return self.user.progressivestack
if self.badge_id == 95: return self.user.bird if self.badge_id == 95: return self.user.bird
if self.badge_id == 96: return self.user.flairchanged if self.badge_id == 96: return self.user.flairchanged
@ -60,7 +62,6 @@ class Badge(Base):
if self.badge_id == 167: return self.user.owoify if self.badge_id == 167: return self.user.owoify
if self.badge_id == 168: return self.user.bite if self.badge_id == 168: return self.user.bite
if self.badge_id == 169: return self.user.earlylife if self.badge_id == 169: return self.user.earlylife
if self.badge_id == 170: return self.user.marsify
if self.badge_id == 171: return self.user.rainbow if self.badge_id == 171: return self.user.rainbow
return None return None
@ -70,7 +71,7 @@ class Badge(Base):
def text(self): def text(self):
if self.until: if self.until:
text = self.badge.description + " until" text = self.badge.description + " until"
elif self.badge_id == 28: elif self.badge_id in (28, 170):
text = self.badge.description + " permanently" text = self.badge.description + " permanently"
elif self.description: elif self.description:
text = self.description text = self.description

View File

@ -6,7 +6,7 @@ if KOFI_TOKEN:
class Transaction(Base): class Transaction(Base):
__tablename__ = "kofi" __tablename__ = "transactions"
id = Column(String, primary_key=True) id = Column(String, primary_key=True)
created_utc = Column(Integer) created_utc = Column(Integer)
type = Column(String) type = Column(String)

View File

@ -1048,6 +1048,7 @@ GIPHY_KEY = environ.get('GIPHY_KEY').strip()
MASTER_KEY = environ.get("MASTER_KEY") MASTER_KEY = environ.get("MASTER_KEY")
FP = environ.get("FP") FP = environ.get("FP")
KOFI_TOKEN = environ.get("KOFI_TOKEN") KOFI_TOKEN = environ.get("KOFI_TOKEN")
KOFI_LINK = environ.get("KOFI_LINK")
tiers={ tiers={
"(Paypig)": 1, "(Paypig)": 1,

View File

@ -58,4 +58,4 @@ def inject_constants():
"CASINO_ENABLED":CASINO_ENABLED, "GUMROAD_LINK":GUMROAD_LINK, "CASINO_ENABLED":CASINO_ENABLED, "GUMROAD_LINK":GUMROAD_LINK,
"DEFAULT_THEME":DEFAULT_THEME, "DESCRIPTION":DESCRIPTION, "DEFAULT_THEME":DEFAULT_THEME, "DESCRIPTION":DESCRIPTION,
"has_sidebar":has_sidebar, "has_logo":has_logo, "has_app":has_app, "has_sidebar":has_sidebar, "has_logo":has_logo, "has_app":has_app,
"FP":FP, "NOTIF_MODACTION_JL_MIN":NOTIF_MODACTION_JL_MIN, "cache":cache, "ONLINE_STR":ONLINE_STR, "patron":patron, "approved_embed_hosts":approved_embed_hosts, "dues":dues, "SIDEBAR_THREAD":SIDEBAR_THREAD, "BANNER_THREAD":BANNER_THREAD, "BADGE_THREAD":BADGE_THREAD, "SNAPPY_THREAD":SNAPPY_THREAD} "FP":FP, "NOTIF_MODACTION_JL_MIN":NOTIF_MODACTION_JL_MIN, "cache":cache, "ONLINE_STR":ONLINE_STR, "patron":patron, "approved_embed_hosts":approved_embed_hosts, "dues":dues, "SIDEBAR_THREAD":SIDEBAR_THREAD, "BANNER_THREAD":BANNER_THREAD, "BADGE_THREAD":BADGE_THREAD, "SNAPPY_THREAD":SNAPPY_THREAD, "KOFI_TOKEN":KOFI_TOKEN, "KOFI_LINK":KOFI_LINK}

View File

@ -5,6 +5,7 @@ from files.__main__ import app, limiter
from files.helpers.const import * from files.helpers.const import *
from files.helpers.actions import * from files.helpers.actions import *
from files.helpers.media import * from files.helpers.media import *
from files.helpers.get import *
from files.helpers.wrappers import * from files.helpers.wrappers import *
from files.routes.static import marsey_list from files.routes.static import marsey_list
@ -147,11 +148,6 @@ def approve_marsey(v, name):
data=f'{{"files": ["https://{SITE}/e/{marsey.name}.webp"]}}', timeout=5) data=f'{{"files": ["https://{SITE}/e/{marsey.name}.webp"]}}', timeout=5)
cache.delete_memoized(marsey_list) cache.delete_memoized(marsey_list)
if v.id != marsey.submitter_id:
msg = f"@{v.username} has approved a marsey you submitted: :{marsey.name}:"
send_repeatable_notification(marsey.submitter_id, msg)
marsey.submitter_id = None
move(f"/asset_submissions/marseys/{name}.webp", f"files/assets/images/emojis/{marsey.name}.webp") move(f"/asset_submissions/marseys/{name}.webp", f"files/assets/images/emojis/{marsey.name}.webp")
@ -160,6 +156,18 @@ def approve_marsey(v, name):
new_path = f'/asset_submissions/marseys/original/{name}.{i.format.lower()}' new_path = f'/asset_submissions/marseys/original/{name}.{i.format.lower()}'
rename(highquality, new_path) rename(highquality, new_path)
if v.id != author.id:
author.coins += 250
g.db.add(author)
msg = f"@{v.username} has approved a marsey you made: :{marsey.name}:\nYou have receieved 250 coins as a reward!"
send_repeatable_notification(author.id, msg)
if v.id not in (author.id, marsey.submitter_id):
msg = f"@{v.username} has approved a marsey you submitted: :{marsey.name}:"
send_repeatable_notification(marsey.submitter_id, msg)
marsey.submitter_id = None
return {"message": f"'{marsey.name}' approved!"} return {"message": f"'{marsey.name}' approved!"}

View File

@ -103,6 +103,7 @@ def settings_profile_post(v):
elif request.values.get("marsify", v.marsify) != v.marsify and v.marsify <= 1: elif request.values.get("marsify", v.marsify) != v.marsify and v.marsify <= 1:
updated = True updated = True
v.marsify = int(request.values.get("marsify") == 'true') v.marsify = int(request.values.get("marsify") == 'true')
if v.marsify: badge_grant(user=v, badge_id=170)
elif request.values.get("bio") == "": elif request.values.get("bio") == "":
v.bio = None v.bio = None
@ -343,7 +344,7 @@ def themecolor(v):
@auth_required @auth_required
def gumroad(v): def gumroad(v):
if not (v.email and v.is_activated): if not (v.email and v.is_activated):
return {"error": f"You must have a verified email to verify {patron} status and claim your rewards"}, 400 return {"error": f"You must have a verified email to verify {patron} status and claim your rewards!"}, 400
data = {'access_token': GUMROAD_TOKEN, 'email': v.email} data = {'access_token': GUMROAD_TOKEN, 'email': v.email}
response = requests.get('https://api.gumroad.com/v2/sales', data=data, timeout=5).json()["sales"] response = requests.get('https://api.gumroad.com/v2/sales', data=data, timeout=5).json()["sales"]

View File

@ -18,7 +18,7 @@ from collections import Counter
import gevent import gevent
from sys import stdout from sys import stdout
import os import os
import json
def leaderboard_thread(): def leaderboard_thread():
db = db_session() db = db_session()
@ -1385,14 +1385,15 @@ def bid_list(v, bid):
@app.post("/kofi") @app.post("/kofi")
def kofi(): def kofi():
verification_token = request.values.get('verification_token') data = json.loads(request.values['data'])
verification_token = data['verification_token']
if verification_token != KOFI_TOKEN: abort(400) if verification_token != KOFI_TOKEN: abort(400)
id = request.values.get('kofi_transaction_id') id = data['kofi_transaction_id']
created_utc = time.mktime(time.strptime(request.values.get('timestamp'), "%Y-%m-%dT%H:%M:%SZ")) created_utc = int(time.mktime(time.strptime(data['timestamp'].split('.')[0], "%Y-%m-%dT%H:%M:%S")))
type = request.values.get('type') type = data['type']
amount = int(request.values.get('amount')) amount = int(float(data['amount']))
email = request.values.get('email') email = data['email']
transaction = Transaction( transaction = Transaction(
id=id, id=id,
@ -1403,5 +1404,44 @@ def kofi():
) )
g.db.add(transaction) g.db.add(transaction)
return '' return ''
kofi_tiers={
5: 1,
10: 2,
20: 3,
50: 4
}
@app.post("/settings/kofi")
@auth_required
def settings_kofi(v):
if not (v.email and v.is_activated):
return {"error": f"You must have a verified email to verify {patron} status and claim your rewards!"}, 400
transaction = g.db.query(Transaction).filter_by(email=v.email).one_or_none()
if not transaction:
return {"error": "Email not found"}, 404
tier = kofi_tiers[transaction.amount]
if v.patron == tier: return {"error": f"{patron} rewards already claimed"}, 400
procoins = procoins_li[tier] - procoins_li[v.patron]
if procoins < 0: return {"error": f"{patron} rewards already claimed"}, 400
existing = g.db.query(User.id).filter(User.email == v.email, User.is_activated == True, User.patron >= tier).first()
if existing: return {"error": f"{patron} rewards already claimed on another account"}, 400
v.patron = tier
if v.discord_id: add_role(v, f"{tier}")
v.procoins += procoins
send_repeatable_notification(v.id, f"You have received {procoins} Marseybux! You can use them to buy awards in the [shop](/shop).")
g.db.add(v)
badge_grant(badge_id=20+tier, user=v)
return {"message": f"{patron} rewards claimed!"}

View File

@ -18,6 +18,7 @@
<table class="table table-striped mb-5"> <table class="table table-striped mb-5">
<thead class="bg-primary text-white"> <thead class="bg-primary text-white">
<tr> <tr>
<th>#</th>
<th>User</th> <th>User</th>
<th onclick="sort_table(1)">User Truescore</th> <th onclick="sort_table(1)">User Truescore</th>
<th onclick="sort_table(2)">Vote Time</th> <th onclick="sort_table(2)">Vote Time</th>
@ -26,6 +27,7 @@
{% for vote in ups %} {% for vote in ups %}
<tr> <tr>
<td>{{loop.index}}</td>
<td> <td>
{% with user=vote.user %} {% with user=vote.user %}
{% include "user_in_table.html" %} {% include "user_in_table.html" %}

View File

@ -45,8 +45,12 @@
<div class="footer"> <div class="footer">
<div class="d-flex"> <div class="d-flex">
{% if FEATURES['PROCOINS'] %} {% if FEATURES['PROCOINS'] %}
{% if KOFI_TOKEN %}
<a class="btn btn-success" role="button" onclick="post_toast(this,'/settings/kofi')">Claim {{patron}} rewards</a>
{% else %}
<a class="btn btn-success" role="button" onclick="post_toast(this,'/settings/gumroad')">Claim {{patron}} rewards</a> <a class="btn btn-success" role="button" onclick="post_toast(this,'/settings/gumroad')">Claim {{patron}} rewards</a>
{% endif %} {% endif %}
{% endif %}
{% if v.email %} {% if v.email %}
<input autocomplete="off" class="btn btn-primary ml-auto" type="submit" onclick="disable(this)" value="Update email"> <input autocomplete="off" class="btn btn-primary ml-auto" type="submit" onclick="disable(this)" value="Update email">
{% else %} {% else %}
@ -54,7 +58,13 @@
{% endif %} {% endif %}
</div> </div>
{% if FEATURES['PROCOINS'] %} {% if FEATURES['PROCOINS'] %}
<span class="text-small text-muted pl-1">Must be same email as gumroad</span> <span class="text-small text-muted pl-1">Must be same email as the one you used to donate on
{% if KOFI_TOKEN %}
<a class="text-primary" href="{{KOFI_LINK}}">Kofi</a>
{% else %}
<a class="text-primary" href="{{GUMROAD_LINK}}">Gumroad</a>
{% endif %}
</span>
{% endif %} {% endif %}
</div> </div>
</form> </form>

View File

@ -28,7 +28,7 @@ set CACHE_VER = {
'js/search.js': 4000, 'js/search.js': 4000,
'js/submit.js': 4000, 'js/submit.js': 4000,
'js/userpage.js': 4000, 'js/userpage.js': 4000,
'js/userpage_v.js': 4001, 'js/userpage_v.js': 4002,
'js/lozad.js': 4000, 'js/lozad.js': 4000,
'js/sort_table.js': 4001, 'js/sort_table.js': 4001,
} }

View File

@ -30,6 +30,7 @@
<table class="table table-striped mb-5"> <table class="table table-striped mb-5">
<thead class="bg-primary text-white"> <thead class="bg-primary text-white">
<tr> <tr>
<th>#</th>
<th>User</th> <th>User</th>
<th onclick="sort_table(1)">User Truescore</th> <th onclick="sort_table(1)">User Truescore</th>
<th onclick="sort_table(2)">Vote Time</th> <th onclick="sort_table(2)">Vote Time</th>
@ -38,6 +39,7 @@
{% for vote in ups %} {% for vote in ups %}
<tr> <tr>
<td>{{loop.index}}</td>
<td> <td>
{% with user=vote.user %} {% with user=vote.user %}
{% include "user_in_table.html" %} {% include "user_in_table.html" %}
@ -55,6 +57,7 @@
<table class="table table-striped mb-5"> <table class="table table-striped mb-5">
<thead class="bg-primary text-white"> <thead class="bg-primary text-white">
<tr> <tr>
<th>#</th>
<th>User</th> <th>User</th>
<th onclick="sort_table(1)">User Truescore</th> <th onclick="sort_table(1)">User Truescore</th>
<th onclick="sort_table(2)">Vote Time</th> <th onclick="sort_table(2)">Vote Time</th>
@ -63,6 +66,7 @@
{% for vote in downs %} {% for vote in downs %}
<tr> <tr>
<td>{{loop.index}}</td>
<td> <td>
{% with user=vote.user %} {% with user=vote.user %}
{% include "user_in_table.html" %} {% include "user_in_table.html" %}

View File

@ -1,5 +1,5 @@
CREATE TABLE public.transactions ( CREATE TABLE public.transactions (
id integer PRIMARY KEY, id character varying(36) PRIMARY KEY,
created_utc integer NOT NULL, created_utc integer NOT NULL,
type character varying(12) NOT NULL, type character varying(12) NOT NULL,
amount integer NOT NULL, amount integer NOT NULL,