diff --git a/files/classes/__init__.py b/files/classes/__init__.py index 93cb4ee5a..887b1b8e1 100644 --- a/files/classes/__init__.py +++ b/files/classes/__init__.py @@ -24,4 +24,5 @@ from .follows import * from .lottery import * from .casino_game import * from .hats import * -from .marsey import * \ No newline at end of file +from .marsey import * +from .transactions import * \ No newline at end of file diff --git a/files/classes/transactions.py b/files/classes/transactions.py new file mode 100644 index 000000000..c7a162b55 --- /dev/null +++ b/files/classes/transactions.py @@ -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"" \ No newline at end of file diff --git a/files/helpers/const.py b/files/helpers/const.py index 901e5cf7c..867199d4c 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -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, diff --git a/files/routes/users.py b/files/routes/users.py index f863a5310..dfc597b28 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -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/") -@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, - ) \ No newline at end of file + return '' \ No newline at end of file diff --git a/sql/20220913-transactions.sql b/sql/20220913-transactions.sql new file mode 100644 index 000000000..188ada617 --- /dev/null +++ b/sql/20220913-transactions.sql @@ -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); \ No newline at end of file