forked from rDrama/rDrama
1
0
Fork 0

kofi integration (testing on devrama)

master
Aevann1 2022-09-13 17:22:18 +02:00
parent eb50e7a791
commit e69827e6e0
5 changed files with 49 additions and 19 deletions

View File

@ -24,4 +24,5 @@ from .follows import *
from .lottery import *
from .casino_game import *
from .hats import *
from .marsey import *
from .marsey import *
from .transactions import *

View File

@ -0,0 +1,17 @@
from files.helpers.const import KOFI_TOKEN
if KOFI_TOKEN:
from sqlalchemy import *
from files.__main__ import Base
class Transaction(Base):
__tablename__ = "kofi"
id = Column(String, primary_key=True)
created_utc = Column(Integer)
type = Column(String)
amount = Column(Integer)
email = Column(String)
def __repr__(self):
return f"<Transaction(id={self.id})>"

View File

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

View File

@ -2,7 +2,8 @@ import qrcode
import io
import time
import math
from files.classes.views import ViewerRelationship
from files.classes.views import *
from files.classes.transactions import *
from files.helpers.alerts import *
from files.helpers.sanitize import *
from files.helpers.const import *
@ -1382,24 +1383,25 @@ def bid_list(v, bid):
)
@app.get("/blockers/<uid>")
@auth_required
def blockers_list(v, uid):
@app.post("/kofi")
def kofi():
verification_token = request.values.get('verification_token')
if verification_token != KOFI_TOKEN: abort(400)
try: uid = int(uid)
except: 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')
try: page = int(request.values.get("page", 1))
except: page = 1
transaction = Transaction(
id=id,
created_utc=created_utc,
type=type,
amount=amount,
email=email
)
users = g.db.query(User).join(User.blocking).filter(UserBlock.target_id==uid).offset(25 * (page - 1)).limit(26).all()
g.db.add(transaction)
next_exists = (len(users) > 25)
users = users[:25]
return render_template("user_cards.html",
v=v,
users=users,
next_exists=next_exists,
page=page,
)
return ''

View File

@ -0,0 +1,9 @@
CREATE TABLE public.transactions (
id integer PRIMARY KEY,
created_utc integer NOT NULL,
type character varying(12) NOT NULL,
amount integer NOT NULL,
email character varying(255) NOT NULL
);
CREATE INDEX transactions_email_idx ON public.transactions USING btree (email);