add dramacoin tax
parent
d666bfaa95
commit
fd8bb4c54c
|
@ -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"
|
||||
#ports:
|
||||
#- "5432:5432"
|
|
@ -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)
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -1378,7 +1378,7 @@
|
|||
|
||||
{% include "expanded_image_modal.html" %}
|
||||
|
||||
<script src="/assets/js/general26.js"></script>
|
||||
<script src="/assets/js/general27.js"></script>
|
||||
|
||||
|
||||
{% 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') %}
|
||||
|
|
|
@ -192,6 +192,6 @@ Allowed styles:
|
|||
|
||||
{% include "expanded_image_modal.html" %}
|
||||
|
||||
<script src="/assets/js/general26.js"></script>
|
||||
<script src="/assets/js/general27.js"></script>
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -130,7 +130,7 @@
|
|||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
|
||||
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||
<script src="/assets/js/general26.js"></script>
|
||||
<script src="/assets/js/general27.js"></script>
|
||||
|
||||
<pre>
|
||||
|
||||
|
|
|
@ -239,7 +239,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/assets/js/general26.js"></script>
|
||||
<script src="/assets/js/general27.js"></script>
|
||||
|
||||
{% block onload %}{% endblock %}
|
||||
|
||||
|
|
|
@ -205,7 +205,7 @@
|
|||
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||
|
||||
<script src="/assets/js/general26.js"></script>
|
||||
<script src="/assets/js/general27.js"></script>
|
||||
|
||||
{% block scripts %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -235,7 +235,7 @@
|
|||
|
||||
<!-- {{'SITE_NAME' | app_config}} JS -->
|
||||
|
||||
<script src="/assets/js/general26.js"></script>
|
||||
<script src="/assets/js/general27.js"></script>
|
||||
|
||||
<pre>
|
||||
|
||||
|
|
|
@ -124,7 +124,7 @@
|
|||
|
||||
<!-- {{'SITE_NAME' | app_config}} JS -->
|
||||
|
||||
<script src="/assets/js/general26.js"></script>
|
||||
<script src="/assets/js/general27.js"></script>
|
||||
|
||||
<pre>
|
||||
|
||||
|
|
|
@ -431,7 +431,7 @@
|
|||
|
||||
<!-- {{'SITE_NAME' | app_config}} JS -->
|
||||
|
||||
<script src="/assets/js/general26.js"></script>
|
||||
<script src="/assets/js/general27.js"></script>
|
||||
|
||||
|
||||
<script>
|
||||
|
|
|
@ -44,6 +44,8 @@
|
|||
{% block desktopUserBanner %}
|
||||
<!-- Desktop -->
|
||||
<script>
|
||||
const TRANSFER_TAX = 0.01;
|
||||
|
||||
window.addEventListener( 'load', function() {
|
||||
var userid = document.getElementById("userid").value;
|
||||
if (userid != "nosong")
|
||||
|
@ -61,14 +63,32 @@
|
|||
let t = event.target;
|
||||
t.disabled = true;
|
||||
|
||||
post_toast("/@{{u.username}}/transfer_coins",
|
||||
false,
|
||||
{"amount": document.getElementById(mobile ? "coins-transfer-amount-mobile" : "coins-transfer-amount").value}
|
||||
let amount = parseInt(document.getElementById("coins-transfer-amount").value);
|
||||
let transferred = amount - Math.ceil(amount*TRANSFER_TAX);
|
||||
|
||||
post_toast_callback("/@{{u.username}}/transfer_coins",
|
||||
{"amount": document.getElementById(mobile ? "coins-transfer-amount-mobile" : "coins-transfer-amount").value},
|
||||
(xhr) => {
|
||||
if(xhr.status == 200) {
|
||||
document.getElementById("user-coins-amount").innerText = parseInt(document.getElementById("user-coins-amount").innerText) - transferred;
|
||||
document.getElementById("profile-coins-amount-mobile").innerText = parseInt(document.getElementById("profile-coins-amount-mobile").innerText) + transferred;
|
||||
document.getElementById("profile-coins-amount").innerText = parseInt(document.getElementById("profile-coins-amount").innerText) + transferred;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
setTimeout(_ => t.disabled = false, 2000);
|
||||
}
|
||||
|
||||
function updateTax(mobile=false) {
|
||||
let suf = mobile ? "-mobile" : "";
|
||||
let amount = parseInt(document.getElementById("coins-transfer-amount" + suf).value);
|
||||
if(isNaN(amount) || amount < 0) {
|
||||
amount = 0;
|
||||
}
|
||||
document.getElementById("coins-transfer-taxed" + suf).innerText = amount - Math.ceil(amount*TRANSFER_TAX);
|
||||
}
|
||||
|
||||
function toggleElement(group, id) {
|
||||
for(let el of document.getElementsByClassName(group)) {
|
||||
if(el.id != id) {
|
||||
|
@ -234,7 +254,8 @@
|
|||
</form>
|
||||
|
||||
<div class="d-none mt-3 profile-toggleable" id="coin-transfer">
|
||||
<input id="coins-transfer-amount" class="form-control" name="amount" type="number">
|
||||
<input autocomplete="off" id="coins-transfer-amount" class="form-control" name="amount" type="number" oninput="updateTax()">
|
||||
<div>{{u.username}} will receive <span id="coins-transfer-taxed">0</span> {{'COINS_NAME' | app_config}}</div>
|
||||
<button class="btn btn-primary mt-3" onclick="transferCoins()">Gift</button>
|
||||
</div>
|
||||
|
||||
|
@ -504,7 +525,8 @@
|
|||
</form>
|
||||
|
||||
<div class="d-none mt-3 profile-toggleable-mobile" id="coin-transfer-mobile">
|
||||
<input id="coins-transfer-amount-mobile" class="form-control" name="amount" type="number">
|
||||
<input autocomplete="off" id="coins-transfer-amount-mobile" class="form-control" name="amount" type="number" oninput="updateTax(true)">
|
||||
<div>{{u.username}} will receive <span id="coins-transfer-taxed-mobile">0</span> {{'COINS_NAME' | app_config}}</div>
|
||||
<button class="btn btn-primary mt-3" onclick="transferCoins(true)">Gift</button>
|
||||
</div>
|
||||
|
||||
|
|
56
seed-db.sql
56
seed-db.sql
|
@ -24,56 +24,32 @@ INSERT INTO public.badge_defs VALUES (26, 'Agendaposter', 'Forced to use the age
|
|||
INSERT INTO public.badge_defs VALUES (17, 'Marsey Artisan', 'Contributed a Marsey emoji ✨', 'marseybadge-1.webp', 3, NULL);
|
||||
INSERT INTO public.badge_defs VALUES (16, 'Marsey Master', 'Contributed 10 (or more!!!!) Marsey emojis ✨', 'marseybadge-2.webp', 3, NULL);
|
||||
|
||||
INSERT INTO public.users (
|
||||
id, username, passhash, created_utc, admin_level, over_18, is_activated, bio, bio_html, login_nonce, is_private,
|
||||
unban_utc, original_username, customtitle, defaultsorting, defaulttime, namecolor, titlecolor, profileurl, bannerurl,
|
||||
customtitleplain, themecolor, changelogsub, oldreddit, css, profilecss, coins, agendaposter, suicide_utc,
|
||||
post_count, comment_count, background, verified
|
||||
) VALUES (1, 'Drama', '', 0, 0, true, true, '', '', 0, false,
|
||||
0, 'Drama', '', 'hot', 'day', 'ff66ac', 'ff66ac', '', '',
|
||||
'', 'ff66ac', false, false, '', '', 0, false, 0,
|
||||
0, 0, '', true);
|
||||
|
||||
insert into public.award_relationships(id,user_id,kind) values(1,1,'shit');
|
||||
|
||||
INSERT INTO public.users (
|
||||
id, username, passhash, created_utc, admin_level, over_18, is_activated, bio, bio_html, login_nonce, is_private,
|
||||
unban_utc, original_username, customtitle, defaultsorting, defaulttime, namecolor, titlecolor, profileurl, bannerurl,
|
||||
customtitleplain, themecolor, changelogsub, oldreddit, css, profilecss, coins, agendaposter, suicide_utc,
|
||||
customtitleplain, theme, themecolor, changelogsub, oldreddit, css, profilecss, coins, agendaposter, suicide_utc,
|
||||
post_count, comment_count, background, verified
|
||||
) VALUES (2, 'AutoJanny', '', 0, 0, true, true, '', '', 0, false,
|
||||
) VALUES (1, 'Drama', '', 0, 0, true, true, '', '', 0, false,
|
||||
0, 'Drama', '', 'hot', 'day', 'ff66ac', 'ff66ac', '', '',
|
||||
'', 'dark', 'ff66ac', false, false, '', '', 0, false, 0,
|
||||
0, 0, '', true),
|
||||
(2, 'AutoJanny', '', 0, 0, true, true, '', '', 0, false,
|
||||
0, 'AutoJanny', '', 'hot', 'day', 'ff66ac', 'ff66ac', '', '',
|
||||
'', 'ff66ac', false, false, '', '', 0, false, 0,
|
||||
0, 0, '', true);
|
||||
|
||||
INSERT INTO public.users (
|
||||
id, username, passhash, created_utc, admin_level, over_18, is_activated, bio, bio_html, login_nonce, is_private,
|
||||
unban_utc, original_username, customtitle, defaultsorting, defaulttime, namecolor, titlecolor, profileurl, bannerurl,
|
||||
customtitleplain, themecolor, changelogsub, oldreddit, css, profilecss, coins, agendaposter, suicide_utc,
|
||||
post_count, comment_count, background, verified
|
||||
) VALUES (3, 'Snappy', '', 0, 0, true, true, '', '', 0, false,
|
||||
'', 'dark', 'ff66ac', false, false, '', '', 0, false, 0,
|
||||
0, 0, '', true),
|
||||
(3, 'Snappy', '', 0, 0, true, true, '', '', 0, false,
|
||||
0, 'Snappy', '', 'hot', 'day', '62ca56', 'e4432d', '', '',
|
||||
'', '30409f', false, false, '', '', 0, false, 0,
|
||||
0, 0, '', true);
|
||||
|
||||
INSERT INTO public.users (
|
||||
id, username, passhash, created_utc, admin_level, over_18, is_activated, bio, bio_html, login_nonce, is_private,
|
||||
unban_utc, original_username, customtitle, defaultsorting, defaulttime, namecolor, titlecolor, profileurl, bannerurl,
|
||||
customtitleplain, themecolor, changelogsub, oldreddit, css, profilecss, coins, agendaposter, suicide_utc,
|
||||
post_count, comment_count, background, verified
|
||||
) VALUES (4, 'longpostbot', '', 0, 0, true, true, '', '', 0, false,
|
||||
'', 'dark', '30409f', false, false, '', '', 0, false, 0,
|
||||
0, 0, '', true),
|
||||
(4, 'longpostbot', '', 0, 0, true, true, '', '', 0, false,
|
||||
0, 'longpostbot', '', 'hot', 'day', '62ca56', 'e4432d', '', '',
|
||||
'', '30409f', false, false, '', '', 0, false, 0,
|
||||
0, 0, '', true);
|
||||
|
||||
INSERT INTO public.users (
|
||||
id, username, passhash, created_utc, admin_level, over_18, is_activated, bio, bio_html, login_nonce, is_private,
|
||||
unban_utc, original_username, customtitle, defaultsorting, defaulttime, namecolor, titlecolor, profileurl, bannerurl,
|
||||
customtitleplain, themecolor, changelogsub, oldreddit, css, profilecss, coins, agendaposter, suicide_utc,
|
||||
post_count, comment_count, background, verified
|
||||
) VALUES (5, 'zozbot', '', 0, 0, true, true, '', '', 0, false,
|
||||
'', 'dark', '30409f', false, false, '', '', 0, false, 0,
|
||||
0, 0, '', true),
|
||||
(5, 'zozbot', '', 0, 0, true, true, '', '', 0, false,
|
||||
0, 'zozbot', '', 'hot', 'day', '62ca56', 'e4432d', '', '',
|
||||
'', '30409f', false, false, '', '', 0, false, 0,
|
||||
'', 'dark', '30409f', false, false, '', '', 0, false, 0,
|
||||
0, 0, '', true);
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue