From fd8bb4c54cbda2fb2e3f9f41cdffa070fcc50caa Mon Sep 17 00:00:00 2001 From: atrc445 Date: Tue, 21 Sep 2021 20:06:41 +0200 Subject: [PATCH] add dramacoin tax --- docker-compose.yml | 5 ++- files/__main__.py | 4 +- files/routes/users.py | 15 +++++-- files/templates/default.html | 2 +- files/templates/formatting.html | 2 +- files/templates/login.html | 2 +- files/templates/settings.html | 2 +- files/templates/settings2.html | 2 +- files/templates/sign_up.html | 2 +- files/templates/sign_up_failed_ref.html | 2 +- files/templates/submit.html | 2 +- files/templates/userpage.html | 32 +++++++++++--- seed-db.sql | 56 +++++++------------------ 13 files changed, 67 insertions(+), 61 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index cd0c3ca1b..638dc9edf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,6 +9,7 @@ services: environment: - DATABASE_URL=postgresql://postgres@postgres:5432/postgres - MASTER_KEY=${MASTER_KEY:-KTVciAUQFpFh2WdJ/oiHJlxl6FvzRZp8kYzAAv3l2OA=} + - REDIS_URL=redis://redis - DOMAIN=localhost - SITE_NAME=Drama - GIPHY_KEY=3435tdfsdudebussylmaoxxt43 @@ -63,5 +64,5 @@ services: - "./seed-db.sql:/docker-entrypoint-initdb.d/01-schema.sql" environment: - POSTGRES_HOST_AUTH_METHOD=trust - ports: - - "5432:5432" \ No newline at end of file + #ports: + #- "5432:5432" \ No newline at end of file diff --git a/files/__main__.py b/files/__main__.py index b4cd5a8bc..8201be3f1 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -59,9 +59,9 @@ app.config["RATELIMIT_DEFAULTS_EXEMPT_WHEN"]=lambda:False app.config["RATELIMIT_HEADERS_ENABLED"]=True app.config["CACHE_TYPE"] = "filesystem" app.config["CACHE_DIR"] = "cache" -app.config["RATELIMIT_STORAGE_URL"] = "redis://127.0.0.1" +app.config["RATELIMIT_STORAGE_URL"] = environ.get("REDIS_URL", "redis://127.0.0.1") -r=redis.Redis(host="127.0.0.1", decode_responses=True, ssl_cert_reqs=None) +r=redis.Redis(host=environ.get("REDIS_URL", "redis://127.0.0.1"), decode_responses=True, ssl_cert_reqs=None) cache = Cache(app) Markdown(app) diff --git a/files/routes/users.py b/files/routes/users.py index 50282e9d9..44920614f 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -1,6 +1,7 @@ import qrcode import io import time +import math from files.classes.user import ViewerRelationship from files.helpers.alerts import * from files.helpers.sanitize import * @@ -113,7 +114,8 @@ def get_coins(v, username): @is_not_banned @validate_formkey def transfer_coins(v, username): - receiver = get_user(username) + receiver = g.db.query(User).filter_by(username=username).first() + tax_receiver = g.db.query(User).filter_by(id=1).first() if receiver is None: return {"error": "That user doesn't exist."}, 404 @@ -125,9 +127,12 @@ def transfer_coins(v, username): if v.coins < amount: return {"error": f"You don't have enough {app.config['COINS_NAME']}"}, 400 if amount < 100: return {"error": f"You have to gift at least 100 {app.config['COINS_NAME']}."}, 400 - v.coins -= amount - receiver.coins += amount + tax = math.ceil(amount*0.01) + v.coins -= amount-tax + receiver.coins += amount-tax + tax_receiver.coins += tax g.db.add(receiver) + g.db.add(tax_receiver) g.db.add(v) transfer_message = f"🤑 [@{v.username}]({v.url}) has gifted you {amount} {app.config['COINS_NAME']}!" @@ -135,7 +140,9 @@ def transfer_coins(v, username): g.db.commit() - return {"message": f"{app.config['COINS_NAME']} transferred!"} + return {"message": f"{amount-tax} {app.config['COINS_NAME']} transferred!"}, 200 + + return {"message": f"You can't transfer {app.config['COINS_NAME']} to yourself!"}, 400 @app.get("/leaderboard") diff --git a/files/templates/default.html b/files/templates/default.html index 3a9ef1f99..1889cef82 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -1378,7 +1378,7 @@ {% include "expanded_image_modal.html" %} - + {% if request.path=='/' and g.system and g.timestamp>session.get('tooltip_last_dismissed',0)+60*60*24 and (not g.system.endswith('/chrome') and not g.system.endswith('/other')) and not g.system.endswith('/webview') %} diff --git a/files/templates/formatting.html b/files/templates/formatting.html index d80031ced..76b9b5f73 100644 --- a/files/templates/formatting.html +++ b/files/templates/formatting.html @@ -192,6 +192,6 @@ Allowed styles: {% include "expanded_image_modal.html" %} - + {% endblock %} diff --git a/files/templates/login.html b/files/templates/login.html index 1d6d2f40a..b71e71b2f 100644 --- a/files/templates/login.html +++ b/files/templates/login.html @@ -130,7 +130,7 @@ - +
 
diff --git a/files/templates/settings.html b/files/templates/settings.html
index 9af4c9f8e..2b676839b 100644
--- a/files/templates/settings.html
+++ b/files/templates/settings.html
@@ -239,7 +239,7 @@
 	
 
 
-
+
 
 {% block onload %}{% endblock %}
 
diff --git a/files/templates/settings2.html b/files/templates/settings2.html
index 417111a47..855d92054 100644
--- a/files/templates/settings2.html
+++ b/files/templates/settings2.html
@@ -205,7 +205,7 @@
 
 
 
-
+
 
 	{% block scripts %}
 	{% endblock %}
diff --git a/files/templates/sign_up.html b/files/templates/sign_up.html
index b41f96f7e..e463d6aec 100644
--- a/files/templates/sign_up.html
+++ b/files/templates/sign_up.html
@@ -235,7 +235,7 @@
 
 
 
-
+
 
 
 
diff --git a/files/templates/sign_up_failed_ref.html b/files/templates/sign_up_failed_ref.html
index a9a5996c5..2b8a70a5c 100644
--- a/files/templates/sign_up_failed_ref.html
+++ b/files/templates/sign_up_failed_ref.html
@@ -124,7 +124,7 @@
 
 
 
-
+
 
 
 
diff --git a/files/templates/submit.html b/files/templates/submit.html
index 86d3eebd9..5e8738098 100644
--- a/files/templates/submit.html
+++ b/files/templates/submit.html
@@ -431,7 +431,7 @@
 	
 		
 
-		
+