Browse Source

Add M and B notation for rollcoin, and half values

Kirk Trombley 4 years ago
parent
commit
53ac7d4bbf
1 changed files with 20 additions and 2 deletions
  1. 20 2
      src/plugins/rollcoin.py

+ 20 - 2
src/plugins/rollcoin.py

@@ -71,13 +71,23 @@ def balance(wallet: Singleton(RollcoinWallet), holdings: Singleton(RollcoinGambl
     return f"You have {wallet.balance} Rollcoins in your wallet and {holdings.balance} Rollcoins in the market"
 
 
-SPECIAL_AMOUNTS = ("ALL", "FRAC", "-ALL", "-FRAC")
+SPECIAL_AMOUNTS = ("ALL", "FRAC", "-ALL", "-FRAC", "HALF", "-HALF")
+SPECIAL_MULTS = {
+    "B": 10 ** 9,
+    "M": 10 ** 6,
+    "K": 10 ** 3,
+    "T": 10 ** 3,
+}
 
 
 def parse_amount(amount):
     if (up_amount := amount.upper()) in SPECIAL_AMOUNTS:
         return up_amount
-    return float(amount)
+    mult = SPECIAL_MULTS.get(up_amount[-1], None)
+    if mult is None:
+        return float(amount)
+    else:
+        return mult * float(amount[:-1])
 
 
 def assert_positive(amount):
@@ -109,6 +119,8 @@ def tip(target_name: Arg(0),
             amount = sender_wallet.balance
         elif amount == "FRAC":
             amount = fractional_part(sender_wallet.balance)
+        elif amount == "HALF":
+            amount = sender_wallet.balance / 2
         else:
             amount = -1
     assert_positive(amount)
@@ -140,6 +152,8 @@ def donate(amount: Arg(0, parse_amount, "Amount should be a number or ALL or FRA
             amount = sender_wallet.balance
         elif amount == "FRAC":
             amount = fractional_part(sender_wallet.balance)
+        elif amount == "HALF":
+            amount = sender_wallet.balance / 2
         else:
             amount = -1
     assert_positive(amount)
@@ -267,10 +281,14 @@ def gamble(amount: Arg(0, parse_amount, "Amount should be a number or ALL or FRA
             amount = sender_wallet.balance
         elif amount == "FRAC":
             amount = fractional_part(sender_wallet.balance)
+        elif amount == "HALF":
+            amount = sender_wallet.balance / 2
         elif amount == "-ALL":
             amount = -sender_holdings.balance
         elif amount == "-FRAC":
             amount = -fractional_part(sender_holdings.balance)
+        elif amount == "-HALF":
+            amount = -sender_holdings.balance / 2
         else:
             raise ValueError(amount)