Эх сурвалжийг харах

Implement brrr and tax, add TODO markers to command list

Kirk Trombley 3 жил өмнө
parent
commit
76e5b1d9b5

+ 57 - 12
commands/commands/rollcoin.py

@@ -5,24 +5,26 @@ import random
 from rollbot import as_command, initialize_data, RollbotFailure
 from rollbot.injection import Data, Sender, Config, Const, Arg, Reply, OriginAdmin
 
+# * = TODO
 # View
 #   !wallet - shows your number of rollcoins, NFTs (Non-Functional Tamagotchis), and market balance
 #   !blockchain - shows the contents of all wallets and the rollcoins in the treasury
 # Generate
-#   !mine - provides a sudoku that can be solved for rollcoins, which also adds to the treasury
-#   !appraise - rollbot will purchase a post, based indirectly on number of likes received
+#   * !mine - provides a sudoku that can be solved for rollcoins, which also adds to the treasury
+#   * !appraise - rollbot will purchase a post, based indirectly on number of likes received
 # Spend
 #   !tip - transfer rollcoins from one person to another
-#   !gacha - insert a rollcoin (which enters the treasury), receive a random NFT
-#   !donate - split an amount and donate it to everyone
+#   * !gacha - insert a rollcoin (which enters the treasury), receive a random NFT
+#   * !donate - split an amount and donate it to everyone
 # Market
 #   !bet - put some amount of rollcoins into the market, some portion of which will be put in the treasury, evolves market
 #   !cash - take some amount of rollcoins from the market, up to investment + the number of coins in the treasury, evolves market
 # Admin
-#   !deflate - deflate all coins by a power of 10
-#   !brrr - print some number of coins into the treasury
-#   !mine !clear - clear the current mining puzzle
-#   !market !force - force the market to transition to a given state
+#   !deflate - deflate all coins by a power of 10 (negative to inflate economy)
+#   !brrr - print some number of coins into the treasury (negative to delete coins)
+#   !tax - take some number of coins from a wallet and put it in the treasury (uses wallet id, negative to give coins)
+#   * !mine !clear - clear the current mining puzzle
+#   * !market - force the market to transition to a given state
 
 
 @initialize_data
@@ -36,7 +38,7 @@ class RollcoinState:
 @initialize_data
 @dataclass
 class RollcoinWallet:
-    balance: float = 10
+    balance: float = 0
     holdings: float = 0
     cost_basis: float = 0
     nfts: list[str] = field(default_factory=list)
@@ -68,8 +70,8 @@ def convert_amount(amount):
 GLOBAL_STATE_KEY = "ROLLCOIN_GLOBAL_STATE"
 
 # injection values
-State = Data(RollcoinState).For(Const(GLOBAL_STATE_KEY), treasury=100, mining_puzzle=None, market_state=0)
-SenderWallet = Data(RollcoinWallet).For(Sender)
+State = Data(RollcoinState).For(Const(GLOBAL_STATE_KEY), treasury=0, mining_puzzle=None, market_state=0)
+SenderWallet = Data(RollcoinWallet).For(Sender, balance=10) # new wallets start with 10 coins
 WalletLookup = Config("rollcoin.wallet_names")
 MarketTransitions = Config("rollcoin.market.transitions")
 MarketMultipliers = Config("rollcoin.market.multipliers")
@@ -250,4 +252,47 @@ async def deflate(
         wallet.cost_basis /= factor
         await wallet_store.save(wallet_id, wallet)
     
-    return f"Economy deflated by a factor of 10^{power}"
+    return f"Economy deflated by a factor of 10^{power}"
+
+
+@as_command
+async def brrr(
+    origin_admin: OriginAdmin,
+    coins: Arg(0, convert=float, missing_msg="Must provide coins to mint", fail_msg="Coins to mint by must be a number"),
+    state_store: Data(RollcoinState),
+):
+    if not origin_admin:
+        RollbotFailure.PERMISSIONS.raise_exc("Only admins can mint coins")
+
+    if coins <= 0:
+        RollbotFailure.INVALID_ARGUMENTS.raise_exc("Can only mint a positive number of coins")
+
+    state = await state_store.load(GLOBAL_STATE_KEY)
+    state.treasury += coins
+    await state_store.save(GLOBAL_STATE_KEY, state)
+    
+    return f"{coins} new RollCoins have been added to the treasury!"
+
+
+@as_command
+async def tax(
+    origin_admin: OriginAdmin,
+    wallet_lookup: WalletLookup,
+    target_name: Arg(0, missing_msg="Must provide a target to tax"),
+    coins: Arg(1, convert=float, missing_msg="Must provide coins to tax", fail_msg="Coins to tax by must be a number"),
+    wallet_store: Data(RollcoinWallet),
+    state_store: Data(RollcoinState),
+):
+    if not origin_admin:
+        RollbotFailure.PERMISSIONS.raise_exc("Only admins can tax someone")
+
+    if (target_id := wallet_lookup.get(target_name.lower(), None)) is None or (wallet := await wallet_store.load(target_id)) is None:
+        RollbotFailure.INVALID_ARGUMENTS.raise_exc(f"Could not find a wallet for {target_name}")
+
+    state = await state_store.load(GLOBAL_STATE_KEY)
+    state.treasury += coins
+    wallet.balance -= coins
+    await state_store.save(GLOBAL_STATE_KEY, state)
+    await wallet_store.save(target_id, wallet)
+    
+    return f"{coins} RollCoins were taken from {target_name} and put in the treasury!"