kofi integration
parent
bab57fd48b
commit
2fa71a252b
|
@ -88,9 +88,11 @@ if not path.isfile(f'/site_settings.json'):
|
|||
def before_request():
|
||||
|
||||
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:
|
||||
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.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.webview = '; wv) ' in ua
|
||||
|
|
|
@ -6,7 +6,7 @@ if KOFI_TOKEN:
|
|||
|
||||
class Transaction(Base):
|
||||
|
||||
__tablename__ = "kofi"
|
||||
__tablename__ = "transactions"
|
||||
id = Column(String, primary_key=True)
|
||||
created_utc = Column(Integer)
|
||||
type = Column(String)
|
||||
|
|
|
@ -1048,6 +1048,7 @@ GIPHY_KEY = environ.get('GIPHY_KEY').strip()
|
|||
MASTER_KEY = environ.get("MASTER_KEY")
|
||||
FP = environ.get("FP")
|
||||
KOFI_TOKEN = environ.get("KOFI_TOKEN")
|
||||
KOFI_LINK = environ.get("KOFI_LINK")
|
||||
|
||||
tiers={
|
||||
"(Paypig)": 1,
|
||||
|
|
|
@ -58,4 +58,4 @@ def inject_constants():
|
|||
"CASINO_ENABLED":CASINO_ENABLED, "GUMROAD_LINK":GUMROAD_LINK,
|
||||
"DEFAULT_THEME":DEFAULT_THEME, "DESCRIPTION":DESCRIPTION,
|
||||
"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}
|
||||
|
|
|
@ -343,7 +343,7 @@ def themecolor(v):
|
|||
@auth_required
|
||||
def gumroad(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
|
||||
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}
|
||||
response = requests.get('https://api.gumroad.com/v2/sales', data=data, timeout=5).json()["sales"]
|
||||
|
|
|
@ -18,7 +18,7 @@ from collections import Counter
|
|||
import gevent
|
||||
from sys import stdout
|
||||
import os
|
||||
|
||||
import json
|
||||
|
||||
def leaderboard_thread():
|
||||
db = db_session()
|
||||
|
@ -1385,14 +1385,15 @@ def bid_list(v, bid):
|
|||
|
||||
@app.post("/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)
|
||||
|
||||
id = request.values.get('kofi_transaction_id')
|
||||
created_utc = time.mktime(time.strptime(request.values.get('timestamp'), "%Y-%m-%dT%H:%M:%SZ"))
|
||||
type = request.values.get('type')
|
||||
amount = int(request.values.get('amount'))
|
||||
email = request.values.get('email')
|
||||
id = data['kofi_transaction_id']
|
||||
created_utc = int(time.mktime(time.strptime(data['timestamp'].split('.')[0], "%Y-%m-%dT%H:%M:%S")))
|
||||
type = data['type']
|
||||
amount = int(float(data['amount']))
|
||||
email = data['email']
|
||||
|
||||
transaction = Transaction(
|
||||
id=id,
|
||||
|
@ -1403,5 +1404,44 @@ def kofi():
|
|||
)
|
||||
|
||||
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!"}
|
|
@ -45,7 +45,11 @@
|
|||
<div class="footer">
|
||||
<div class="d-flex">
|
||||
{% if FEATURES['PROCOINS'] %}
|
||||
<a class="btn btn-success" role="button" onclick="post_toast(this,'/settings/gumroad')">Claim {{patron}} rewards</a>
|
||||
{% 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>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if v.email %}
|
||||
<input autocomplete="off" class="btn btn-primary ml-auto" type="submit" onclick="disable(this)" value="Update email">
|
||||
|
@ -54,7 +58,13 @@
|
|||
{% endif %}
|
||||
</div>
|
||||
{% 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 %}
|
||||
</div>
|
||||
</form>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
CREATE TABLE public.transactions (
|
||||
id integer PRIMARY KEY,
|
||||
id character varying(36) PRIMARY KEY,
|
||||
created_utc integer NOT NULL,
|
||||
type character varying(12) NOT NULL,
|
||||
amount integer NOT NULL,
|
||||
|
|
Loading…
Reference in New Issue