Browse Source

Implement market manipulation

Kirk Trombley 3 years ago
parent
commit
4157ffaae0
1 changed files with 21 additions and 1 deletions
  1. 21 1
      commands/commands/rollcoin.py

+ 21 - 1
commands/commands/rollcoin.py

@@ -26,7 +26,7 @@ from rollbot.injection import Data, Sender, Config, Const, Arg, Reply, OriginAdm
 #   !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 skip - skip the current mining puzzle
-#   * !market - force the market to transition to a given state
+#   !market - force the market to transition to a given state
 
 
 @initialize_data
@@ -422,3 +422,23 @@ async def tax(
     await wallet_store.save(target_id, wallet)
 
     return f"{coins} RollCoins were taken from {target_name} and put in the treasury!"
+
+
+@as_command
+async def market(
+    origin_admin: OriginAdmin,
+    target_state: Arg(0, convert=int, missing_msg="Must provide target state for market", fail_msg="Target market state must be an integer"),
+    state_store: Data(RollcoinState),
+    messages: MarketMessages,
+):
+    if not origin_admin:
+        RollbotFailure.PERMISSIONS.raise_exc("Only admins can manipulate the market")
+
+    if target_state < 0 or target_state >= len(messages):
+        RollbotFailure.INVALID_ARGUMENTS.raise_exc("Market state invalid")
+
+    state = await state_store.load(GLOBAL_STATE_KEY)
+    state.market_state = target_state
+    await state_store.save(GLOBAL_STATE_KEY, state)
+
+    return f"Market status: {messages[state.market_state]}"