Kirk Trombley 3 жил өмнө
parent
commit
8f3f4ba083

+ 29 - 2
commands/commands/rollcoin.py

@@ -3,7 +3,7 @@ from typing import Optional
 import random
 
 from rollbot import as_command, initialize_data, RollbotFailure
-from rollbot.injection import Data, Sender, Config, Const, Arg, Reply
+from rollbot.injection import Data, Sender, Config, Const, Arg, Reply, OriginAdmin
 
 # View
 #   !wallet - shows your number of rollcoins, NFTs (Non-Functional Tamagotchis), and market balance
@@ -36,7 +36,7 @@ class RollcoinState:
 @initialize_data
 @dataclass
 class RollcoinWallet:
-    balance: float = 1
+    balance: float = 10
     holdings: float = 0
     cost_basis: float = 0
     nfts: list[str] = field(default_factory=list)
@@ -224,3 +224,30 @@ async def cash(
 
     yield f"{response}\n{await wallet_store.load(sender_id)}", reply
     yield f"Market status: {messages[state.market_state]}"
+
+
+# ADMIN COMMANDS
+
+@as_command
+async def deflate(
+    origin_admin: OriginAdmin,
+    power: Arg(0, convert=int, missing_msg="Must provide power to deflate by", fail_msg="Power to deflate by must be an integer"),
+    wallet_store: Data(RollcoinWallet),
+    state_store: Data(RollcoinState),
+):
+    if not origin_admin:
+        RollbotFailure.PERMISSIONS.raise_exc("Only admins can deflate the currency")
+
+    factor = 10 ** power
+
+    state = await state_store.load(GLOBAL_STATE_KEY)
+    state.treasury /= factor
+    await state_store.save(GLOBAL_STATE_KEY, state)
+    
+    async for (wallet_id, wallet) in wallet_store.all():
+        wallet.balance /= factor
+        wallet.holdings /= factor
+        wallet.cost_basis /= factor
+        await wallet_store.save(wallet_id, wallet)
+    
+    return f"Economy deflated by a factor of 10^{power}"