Skip to content

Commit f849eb8

Browse files
committed
refactor(examples): update example bot to use simplified send_message API
Migrate example bot from high-level API methods to direct send_message calls: - Update imports to use new module structure - Replace method calls with send_message format - Simplify logging and remove excessive output - Remove state tracking and intermediate responses
1 parent 69fa934 commit f849eb8

File tree

1 file changed

+20
-48
lines changed

1 file changed

+20
-48
lines changed

bots/example.py

Lines changed: 20 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,68 +2,40 @@
22

33
import logging
44

5-
from balatrobot import BalatroClient, BalatroError, State
5+
from src.balatrobot.client import BalatroClient
6+
from src.balatrobot.exceptions import BalatroError
67

78
logger = logging.getLogger(__name__)
9+
logging.basicConfig(level=logging.INFO)
810

911

1012
def main():
1113
"""Example of using the new BalatroBot API."""
12-
logging.basicConfig(level=logging.INFO, format="%(levelname)s - %(message)s")
1314
logger.info("BalatroBot API Example")
14-
logger.info("=" * 50)
1515

16-
# Create client and connect
1716
with BalatroClient() as client:
1817
try:
19-
# Get initial game state
20-
logger.info("Getting initial game state...")
21-
game_state = client.get_game_state()
22-
logger.info(f"Current state: {game_state.state_enum.name}")
23-
24-
# Go to menu if not already there
25-
if game_state.state_enum != State.MENU:
26-
logger.info("Going to menu...")
27-
game_state = client.go_to_menu()
28-
logger.info(f"Now in state: {game_state.state_enum.name}")
29-
30-
# Start a new run
31-
logger.info("Starting new run...")
32-
game_state = client.start_run(deck="Red Deck", stake=1, seed="EXAMPLE")
33-
logger.info(f"Run started, state: {game_state.state_enum.name}")
34-
35-
# Select the blind
36-
logger.info("Selecting blind...")
37-
game_state = client.skip_or_select_blind("select")
38-
logger.info(f"Blind selected, state: {game_state.state_enum.name}")
39-
logger.info(f"Hand size: {len(game_state.hand)}")
40-
41-
# Play a hand (first 4 cards)
42-
if len(game_state.hand) >= 4:
43-
logger.info("Playing hand with first 4 cards...")
44-
game_state = client.play_hand_or_discard("play_hand", [0, 1, 2, 3])
45-
logger.info(f"Hand played, state: {game_state.state_enum.name}")
46-
47-
# If we won the round, cash out
48-
if game_state.state_enum == State.ROUND_EVAL:
49-
logger.info("Cashing out...")
50-
game_state = client.cash_out()
51-
logger.info(f"Cashed out, state: {game_state.state_enum.name}")
52-
53-
# Go to next round
54-
logger.info("Going to next round...")
55-
game_state = client.shop("next_round")
56-
logger.info(f"Next round, state: {game_state.state_enum.name}")
57-
58-
# Go back to menu at the end
59-
logger.info("Going back to menu...")
60-
game_state = client.go_to_menu()
61-
logger.info(f"Back to menu, state: {game_state.state_enum.name}")
18+
client.send_message("go_to_menu", {})
19+
client.send_message(
20+
"start_run",
21+
{"deck": "Red Deck", "stake": 1, "seed": "OOOO155"},
22+
)
23+
client.send_message(
24+
"skip_or_select_blind",
25+
{"action": "select"},
26+
)
27+
client.send_message(
28+
"play_hand_or_discard",
29+
{"action": "play_hand", "cards": [0, 1, 2, 3]},
30+
)
31+
client.send_message("cash_out", {})
32+
client.send_message("shop", {"action": "next_round"})
33+
client.send_message("go_to_menu", {})
34+
logger.info("All actions executed successfully")
6235

6336
except BalatroError as e:
6437
logger.error(f"API Error: {e}")
6538
logger.error(f"Error code: {e.error_code}")
66-
logger.error(f"Context: {e.context}")
6739

6840
except Exception as e:
6941
logger.error(f"Unexpected error: {e}")

0 commit comments

Comments
 (0)