diff --git a/files/classes/user.py b/files/classes/user.py
index 5ef53171b..ac372f1ca 100644
--- a/files/classes/user.py
+++ b/files/classes/user.py
@@ -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
diff --git a/files/helpers/stats.py b/files/helpers/stats.py
index 68d44d253..c839777d2 100644
--- a/files/helpers/stats.py
+++ b/files/helpers/stats.py
@@ -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()),
diff --git a/files/routes/awards.py b/files/routes/awards.py
index 84b9dc07b..5b61f23bf 100644
--- a/files/routes/awards.py
+++ b/files/routes/awards.py
@@ -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)
diff --git a/files/routes/hats.py b/files/routes/hats.py
index a4e017a25..f3f0b7247 100644
--- a/files/routes/hats.py
+++ b/files/routes/hats.py
@@ -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"{hat.name}
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 {hat.name}
hat")
new_hat = Hat(user_id=v.id, hat_id=hat.id)
diff --git a/files/routes/leaderboard.py b/files/routes/leaderboard.py
index bbc7ae21a..da77ed948 100644
--- a/files/routes/leaderboard.py
+++ b/files/routes/leaderboard.py
@@ -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")
diff --git a/files/templates/hats.html b/files/templates/hats.html
index f4d9d2822..03a9872e9 100644
--- a/files/templates/hats.html
+++ b/files/templates/hats.html
@@ -25,9 +25,9 @@
Casino winnings: {{u.winnings}}
Lottery winnings: {{u.total_lottery_winnings}}
= hats_total %}class="profile-owned-all-hats"{% endif %}>{{u.num_of_owned_hats}} / {{hats_total}} hats owned ({{hats_owned_percent}})
-Coins spent on awards: {{u.coins_spent}}
-Coins spent on hats: {{u.coins_spent_on_hats}}
+Currency spent on awards: {{u.currency_spent_on_awards}}
+Currency spent on hats: {{u.currency_spent_on_hats}}
Effortposts made: {{u.effortposts_made}} @@ -584,8 +584,8 @@
Casino winnings: {{u.winnings}}
Lottery winnings: {{u.total_lottery_winnings}}
= hats_total %}class="profile-owned-all-hats"{% endif %}>{{u.num_of_owned_hats}} / {{hats_total}} hats owned ({{hats_owned_percent}})
-Coins spent on awards: {{u.coins_spent}}
-Coins spent on hats: {{u.coins_spent_on_hats}}
+Currency spent on awards: {{u.currency_spent_on_awards}}
+Currency spent on hats: {{u.currency_spent_on_hats}}
Effortposts made: {{u.effortposts_made}} diff --git a/migrations/20240309-make-mbux-count-towards-spender-badges.sql b/migrations/20240309-make-mbux-count-towards-spender-badges.sql new file mode 100644 index 000000000..d3a3e5258 --- /dev/null +++ b/migrations/20240309-make-mbux-count-towards-spender-badges.sql @@ -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; diff --git a/schema.sql b/schema.sql index df4318a59..52218a360 100644 --- a/schema.sql +++ b/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 -- -