forked from MarseyWorld/MarseyWorld
make mbux count towards spender badges
parent
999205c638
commit
b8bbcef284
|
@ -84,8 +84,8 @@ class User(Base):
|
|||
created_utc = Column(Integer)
|
||||
admin_level = Column(Integer, default=DEFAULT_ADMIN_LEVEL)
|
||||
last_active = Column(Integer)
|
||||
coins_spent = Column(Integer, default=0)
|
||||
coins_spent_on_hats = Column(Integer, default=0)
|
||||
currency_spent_on_awards = Column(Integer, default=0)
|
||||
currency_spent_on_hats = Column(Integer, default=0)
|
||||
lootboxes_bought = Column(Integer, default=0)
|
||||
chud = Column(Integer, default=0)
|
||||
queen = Column(Integer, default=0)
|
||||
|
@ -251,7 +251,6 @@ class User(Base):
|
|||
|
||||
def charge_account(self, currency, amount, reason=None, **kwargs):
|
||||
succeeded = False
|
||||
charged_coins = 0
|
||||
|
||||
should_check_balance = kwargs.get('should_check_balance', True)
|
||||
|
||||
|
@ -264,7 +263,6 @@ class User(Base):
|
|||
if not should_check_balance or account_balance >= amount:
|
||||
user_query.update({ User.coins: User.coins - amount })
|
||||
succeeded = True
|
||||
charged_coins = amount
|
||||
logs = [['coins', amount]]
|
||||
elif currency == 'marseybux':
|
||||
account_balance = self.marseybux
|
||||
|
@ -281,14 +279,13 @@ class User(Base):
|
|||
subtracted_mbux = self.marseybux
|
||||
subtracted_coins = amount - subtracted_mbux
|
||||
if subtracted_coins > self.coins:
|
||||
return (False, 0)
|
||||
return False
|
||||
|
||||
user_query.update({
|
||||
User.marseybux: User.marseybux - subtracted_mbux,
|
||||
User.coins: User.coins - subtracted_coins,
|
||||
})
|
||||
succeeded = True
|
||||
charged_coins = subtracted_coins
|
||||
logs = [['coins', subtracted_coins], ['marseybux', subtracted_mbux]]
|
||||
|
||||
if succeeded:
|
||||
|
@ -308,7 +305,7 @@ class User(Base):
|
|||
else:
|
||||
currency_log.balance = self.marseybux
|
||||
|
||||
return (succeeded, charged_coins)
|
||||
return succeeded
|
||||
|
||||
@property
|
||||
@lazy
|
||||
|
|
|
@ -98,8 +98,8 @@ def stats():
|
|||
"Users with a private profile": "{:,}".format(g.db.query(User).filter_by(is_private=True).count()),
|
||||
"Users with a verified email": "{:,}".format(g.db.query(User).filter_by(email_verified=True).count()),
|
||||
"Coins in circulation": "{:,}".format(g.db.query(func.sum(User.coins)).scalar()),
|
||||
"Total award sales": "{:,}".format(g.db.query(func.sum(User.coins_spent)).scalar()),
|
||||
"Total hat sales": "{:,}".format(g.db.query(func.sum(User.coins_spent_on_hats)).scalar()),
|
||||
"Total currency spent on awards": "{:,}".format(g.db.query(func.sum(User.currency_spent_on_awards)).scalar()),
|
||||
"Total currency spent on hats": "{:,}".format(g.db.query(func.sum(User.currency_spent_on_hats)).scalar()),
|
||||
"Signups last 24h": "{:,}".format(g.db.query(User).filter(User.created_utc > day).count()),
|
||||
"Total posts": "{:,}".format(g.db.query(Post).count()),
|
||||
"Posting users": "{:,}".format(g.db.query(Post.author_id).distinct().count()),
|
||||
|
|
|
@ -49,7 +49,7 @@ def shop(v):
|
|||
val["baseprice"] = int(val["baseprice"] / 0.75)
|
||||
val["price"] = int(val["price"] * v.award_discount)
|
||||
|
||||
sales = g.db.query(func.sum(User.coins_spent)).scalar()
|
||||
sales = g.db.query(func.sum(User.currency_spent_on_awards)).scalar()
|
||||
return render_template("shop.html", awards=list(AWARDS.values()), v=v, sales=sales)
|
||||
|
||||
|
||||
|
@ -65,19 +65,19 @@ def buy_award(v, kind, AWARDS):
|
|||
currency = 'coins/marseybux'
|
||||
|
||||
charged = v.charge_account(currency, price, f"{AWARDS[kind]['title']} award cost")
|
||||
if not charged[0]:
|
||||
if not charged:
|
||||
abort(400, f"Not enough {currency}!")
|
||||
|
||||
v.coins_spent += charged[1]
|
||||
if v.coins_spent >= 1000000:
|
||||
v.currency_spent_on_awards += price
|
||||
if v.currency_spent_on_awards >= 1000000:
|
||||
badge_grant(badge_id=73, user=v)
|
||||
elif v.coins_spent >= 500000:
|
||||
elif v.currency_spent_on_awards >= 500000:
|
||||
badge_grant(badge_id=72, user=v)
|
||||
elif v.coins_spent >= 250000:
|
||||
elif v.currency_spent_on_awards >= 250000:
|
||||
badge_grant(badge_id=71, user=v)
|
||||
elif v.coins_spent >= 100000:
|
||||
elif v.currency_spent_on_awards >= 100000:
|
||||
badge_grant(badge_id=70, user=v)
|
||||
elif v.coins_spent >= 10000:
|
||||
elif v.currency_spent_on_awards >= 10000:
|
||||
badge_grant(badge_id=69, user=v)
|
||||
g.db.add(v)
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ def hats(v):
|
|||
not_owned = g.db.query(HatDef, User).join(HatDef.author).filter(HatDef.submitter_id == None, HatDef.id.notin_(owned_hat_ids)).order_by(HatDef.price == 0, HatDef.price, HatDef.name).all()
|
||||
hats = owned + not_owned
|
||||
|
||||
sales = g.db.query(func.sum(User.coins_spent_on_hats)).scalar()
|
||||
sales = g.db.query(func.sum(User.currency_spent_on_hats)).scalar()
|
||||
num_of_hats = g.db.query(HatDef).filter(HatDef.submitter_id == None).count()
|
||||
return render_template("hats.html", owned_hat_ids=owned_hat_ids, hats=hats, v=v, sales=sales, num_of_hats=num_of_hats)
|
||||
|
||||
|
@ -45,10 +45,10 @@ def buy_hat(v, hat_id):
|
|||
abort(403, "This hat is not for sale!")
|
||||
|
||||
charged = v.charge_account('coins/marseybux', hat.price, f"<code>{hat.name}</code> hat cost")
|
||||
if not charged[0]:
|
||||
if not charged:
|
||||
abort(400, "Not enough coins/marseybux!")
|
||||
|
||||
v.coins_spent_on_hats += charged[1]
|
||||
v.currency_spent_on_hats += hat.price
|
||||
hat.author.pay_account('coins', hat.price * 0.1, f"Royalties for <code>{hat.name}</code> hat")
|
||||
|
||||
new_hat = Hat(user_id=v.id, hat_id=hat.id)
|
||||
|
|
|
@ -22,12 +22,12 @@ def leaderboard_marseybux(v):
|
|||
leaderboard = Leaderboard("Marseybux", "marseybux", "marseybux", "Marseybux", None, Leaderboard.get_simple_lb, User.marseybux, v, lambda u:u.marseybux, g.db.query(User))
|
||||
return render_template("leaderboard.html", v=v, leaderboard=leaderboard)
|
||||
|
||||
@app.get("/leaderboard/spent")
|
||||
@app.get("/leaderboard/currency_spent_on_awards")
|
||||
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
||||
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
||||
@auth_required
|
||||
def leaderboard_spent(v):
|
||||
leaderboard = Leaderboard("Coins spent on awards", "coins spent on awards", "spent", "Coins", None, Leaderboard.get_simple_lb, User.coins_spent, v, lambda u:u.coins_spent, g.db.query(User))
|
||||
def leaderboard_currency_spent_on_awards(v):
|
||||
leaderboard = Leaderboard("Currency spent on awards", "currency spent on awards", "currency-spent-on-awards", "Currency", None, Leaderboard.get_simple_lb, User.currency_spent_on_awards, v, lambda u:u.currency_spent_on_awards, g.db.query(User))
|
||||
return render_template("leaderboard.html", v=v, leaderboard=leaderboard)
|
||||
|
||||
@app.get("/leaderboard/truescore")
|
||||
|
|
|
@ -25,9 +25,9 @@
|
|||
<ul id="shop-stats" class="my-1 my-md-2">
|
||||
<li class="mt-2">Number of hats you bought: {{v.num_of_owned_hats}}</li>
|
||||
<li>Number of hats you designed: {{v.num_of_designed_hats}}</li>
|
||||
<li>Coins you spent on hats: {{"{:,}".format(v.coins_spent_on_hats)}}</li>
|
||||
<li>Number of hats: {{num_of_hats}}</li>
|
||||
<li>Total hat sales: {{"{:,}".format(sales)}}</li>
|
||||
<li>Currency you spent on hats: {{"{:,}".format(v.currency_spent_on_hats)}}</li>
|
||||
<li>Total currency spent on hats: {{"{:,}".format(sales)}}</li>
|
||||
<li>Your current coins: {{"{:,}".format(v.coins)}}</li>
|
||||
{% if FEATURES['MARSEYBUX'] %}
|
||||
<li>Your current marseybux: {{"{:,}".format(v.marseybux)}}</li>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<div class="mt-2" id="leaderboard-contents" style="text-align: center; margin-bottom: 1.5rem; font-size: 1.2rem">
|
||||
<a {% if request.path in ["/leaderboard", "/leaderboard/coins"] %}class="font-weight-bolder"{% endif %} href="/leaderboard/coins">Coins</a> •
|
||||
<a {% if request.path == "/leaderboard/marseybux" %}class="font-weight-bolder"{% endif %} href="/leaderboard/marseybux">Marseybux</a> •
|
||||
<a {% if request.path == "/leaderboard/spent" %}class="font-weight-bolder"{% endif %} href="/leaderboard/spent">Coins spent on awards</a> •
|
||||
<a {% if request.path == "/leaderboard/currency_spent_on_awards" %}class="font-weight-bolder"{% endif %} href="/leaderboard/currency_spent_on_awards">Currency spent on awards</a> •
|
||||
<a {% if request.path == "/leaderboard/truescore" %}class="font-weight-bolder"{% endif %} href="/leaderboard/truescore">Truescore</a> •
|
||||
<a {% if request.path == "/leaderboard/followers" %}class="font-weight-bolder"{% endif %} href="/leaderboard/followers">Followers</a> •
|
||||
<a {% if request.path == "/leaderboard/posts" %}class="font-weight-bolder"{% endif %} href="/leaderboard/posts">Posts</a> •
|
||||
|
|
|
@ -26,8 +26,8 @@
|
|||
<li>Number of lootboxes you bought: {{v.lootboxes_bought}}</li>
|
||||
{% endif %}
|
||||
<li>Number of awards you bought: {{v.num_of_bought_awards}}</li>
|
||||
<li>Coins you spent on awards: {{"{:,}".format(v.coins_spent)}}</li>
|
||||
<li>Total award sales: {{"{:,}".format(sales)}}</li>
|
||||
<li>Currency you spent on awards: {{"{:,}".format(v.currency_spent_on_awards)}}</li>
|
||||
<li>Total currency spent on awards: {{"{:,}".format(sales)}}</li>
|
||||
<li>Your current coins: {{"{:,}".format(v.coins)}}</li>
|
||||
{% if FEATURES['MARSEYBUX'] %}
|
||||
<li>Your current marseybux: {{"{:,}".format(v.marseybux)}}</li>
|
||||
|
|
|
@ -270,8 +270,8 @@
|
|||
<p id="profile--info--casino-winnings">Casino winnings: {{u.winnings}}</p>
|
||||
<p id="profile--info--lottery-winnings">Lottery winnings: {{u.total_lottery_winnings}}</p>
|
||||
<p id="profile--info--hats-owned" {% if u.num_of_owned_hats >= hats_total %}class="profile-owned-all-hats"{% endif %}>{{u.num_of_owned_hats}} / {{hats_total}} hats owned ({{hats_owned_percent}})</p>
|
||||
<p id="profile--info--spent">Coins spent on awards: {{u.coins_spent}}</p>
|
||||
<p id="profile--info--spent">Coins spent on hats: {{u.coins_spent_on_hats}}</p>
|
||||
<p id="profile--info--spent">Currency spent on awards: {{u.currency_spent_on_awards}}</p>
|
||||
<p id="profile--info--spent">Currency spent on hats: {{u.currency_spent_on_hats}}</p>
|
||||
|
||||
<p id="profile--info--effortposts">
|
||||
Effortposts made: <a href='/search/posts?q=author:{{u.username}}+effortpost:true'><b>{{u.effortposts_made}}</b></a>
|
||||
|
@ -584,8 +584,8 @@
|
|||
<p id="profile-mobile--info--casino-winnings">Casino winnings: {{u.winnings}}</p>
|
||||
<p id="profile-mobile--info--lottery-winnings">Lottery winnings: {{u.total_lottery_winnings}}</p>
|
||||
<p id="profile-mobile--info--hats-owned" {% if u.num_of_owned_hats >= hats_total %}class="profile-owned-all-hats"{% endif %}>{{u.num_of_owned_hats}} / {{hats_total}} hats owned ({{hats_owned_percent}})</p>
|
||||
<p id="profile-mobile--info--spent">Coins spent on awards: {{u.coins_spent}}</p>
|
||||
<p id="profile-mobile--info--spent">Coins spent on hats: {{u.coins_spent_on_hats}}</p>
|
||||
<p id="profile-mobile--info--spent">Currency spent on awards: {{u.currency_spent_on_awards}}</p>
|
||||
<p id="profile-mobile--info--spent">Currency spent on hats: {{u.currency_spent_on_hats}}</p>
|
||||
|
||||
<p id="profile-mobile--info--effortposts">
|
||||
Effortposts made: <a href='/search/posts?q=author:{{u.username}}+effortpost:true'><b>{{u.effortposts_made}}</b></a>
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
alter table users rename column coins_spent to currency_spent_on_awards;
|
||||
alter table users rename column coins_spent_on_hats to currency_spent_on_hats;
|
||||
|
||||
drop index users_coins_spent_on_hats_idx;
|
||||
create index users_currency_spent_on_awards_idx ON public.users USING btree (currency_spent_on_awards desc);
|
||||
|
||||
update badge_defs set description='Spent 10,000 currency on awards' where id=69;
|
||||
update badge_defs set description='Spent 100,000 currency on awards' where id=70;
|
||||
update badge_defs set description='Spent 250,000 currency on awards' where id=71;
|
||||
update badge_defs set description='Spent 500,000 currency on awards' where id=72;
|
11
schema.sql
11
schema.sql
|
@ -125,7 +125,7 @@ CREATE TABLE public.users (
|
|||
received_award_count integer DEFAULT 0 NOT NULL,
|
||||
truescore integer DEFAULT 0 NOT NULL,
|
||||
frontsize integer DEFAULT 25 NOT NULL,
|
||||
coins_spent integer DEFAULT 0 NOT NULL,
|
||||
currency_spent_on_awards integer DEFAULT 0 NOT NULL,
|
||||
marseybux integer DEFAULT 0 NOT NULL,
|
||||
verifiedcolor character varying(6),
|
||||
hieroglyphs integer,
|
||||
|
@ -159,7 +159,7 @@ CREATE TABLE public.users (
|
|||
owoify integer,
|
||||
marsify integer,
|
||||
is_muted boolean DEFAULT false NOT NULL,
|
||||
coins_spent_on_hats integer DEFAULT 0 NOT NULL,
|
||||
currency_spent_on_hats integer DEFAULT 0 NOT NULL,
|
||||
rainbow integer,
|
||||
spider integer,
|
||||
profanityreplacer integer DEFAULT 1 NOT NULL,
|
||||
|
@ -2391,12 +2391,6 @@ CREATE INDEX users_bite_idx ON public.users USING btree (bite);
|
|||
CREATE INDEX users_chud_idx ON public.users USING btree (chud);
|
||||
|
||||
|
||||
--
|
||||
-- Name: users_coins_spent_on_hats_idx; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX users_coins_spent_on_hats_idx ON public.users USING btree (coins_spent_on_hats);
|
||||
|
||||
|
||||
--
|
||||
-- Name: users_created_utc_index; Type: INDEX; Schema: public; Owner: -
|
||||
|
@ -3313,4 +3307,3 @@ ALTER TABLE ONLY public.comments
|
|||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
|
|
Loading…
Reference in New Issue