Spaces:
Building
Building
Update roulette.py
Browse files- roulette.py +25 -14
roulette.py
CHANGED
@@ -5,10 +5,10 @@ import random
|
|
5 |
from cash import user_cash
|
6 |
|
7 |
@app_commands.command(name="roulette", description="Play roulette and bet")
|
8 |
-
async def roulette(interaction: discord.Interaction, bet: int):
|
9 |
-
await play_roulette(interaction, bet)
|
10 |
|
11 |
-
async def play_roulette(interaction: discord.Interaction, bet: int):
|
12 |
user_id = interaction.user.id
|
13 |
balance = user_cash.get(user_id, 0)
|
14 |
|
@@ -17,28 +17,37 @@ async def play_roulette(interaction: discord.Interaction, bet: int):
|
|
17 |
return
|
18 |
|
19 |
if bet > balance:
|
20 |
-
await interaction.response.send_message(f"
|
|
|
|
|
|
|
|
|
21 |
return
|
22 |
|
23 |
-
embed = discord.Embed(title="Roulette Game", description=f"{interaction.user.name} is betting ${bet:.2f}", color=
|
24 |
embed.add_field(name="Current Balance", value=f"${balance:.2f}", inline=False)
|
25 |
|
26 |
spin_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Spin the Roulette", custom_id="spin_roulette")
|
27 |
|
28 |
async def spin_roulette_callback(interaction: discord.Interaction):
|
29 |
nonlocal balance
|
30 |
-
|
|
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
else:
|
37 |
-
|
38 |
-
|
39 |
|
|
|
40 |
user_cash[user_id] = balance
|
41 |
|
|
|
|
|
|
|
42 |
embed.clear_fields()
|
43 |
embed.add_field(name="Result", value=result_text, inline=False)
|
44 |
embed.add_field(name="New Balance", value=f"${balance:.2f}", inline=False)
|
@@ -47,7 +56,7 @@ async def play_roulette(interaction: discord.Interaction, bet: int):
|
|
47 |
|
48 |
async def spin_again_callback(interaction: discord.Interaction):
|
49 |
if interaction.user.id == user_id:
|
50 |
-
await play_roulette(interaction, bet)
|
51 |
else:
|
52 |
await interaction.response.send_message("You can't spin this.", ephemeral=True)
|
53 |
|
@@ -66,4 +75,6 @@ async def play_roulette(interaction: discord.Interaction, bet: int):
|
|
66 |
if interaction.response.is_done():
|
67 |
await interaction.followup.send(embed=embed, view=view)
|
68 |
else:
|
69 |
-
await interaction.response.send_message(embed=embed, view=view)
|
|
|
|
|
|
5 |
from cash import user_cash
|
6 |
|
7 |
@app_commands.command(name="roulette", description="Play roulette and bet")
|
8 |
+
async def roulette(interaction: discord.Interaction, bet: int, choice: str):
|
9 |
+
await play_roulette(interaction, bet, choice)
|
10 |
|
11 |
+
async def play_roulette(interaction: discord.Interaction, bet: int, choice: str):
|
12 |
user_id = interaction.user.id
|
13 |
balance = user_cash.get(user_id, 0)
|
14 |
|
|
|
17 |
return
|
18 |
|
19 |
if bet > balance:
|
20 |
+
await interaction.response.send_message(f"you got no money. Your current balance is ${balance:.2f}")
|
21 |
+
return
|
22 |
+
|
23 |
+
if choice not in ["red", "black", "green"] and not (choice.isdigit() and 0 <= int(choice) <= 36):
|
24 |
+
await interaction.response.send_message("Invalid. Choose 'red', 'black', 'green', or a number between 0 and 36.")
|
25 |
return
|
26 |
|
27 |
+
embed = discord.Embed(title="Roulette Game", description=f"{interaction.user.name} is betting ${bet:.2f} on {choice}", color=0x787878)
|
28 |
embed.add_field(name="Current Balance", value=f"${balance:.2f}", inline=False)
|
29 |
|
30 |
spin_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Spin the Roulette", custom_id="spin_roulette")
|
31 |
|
32 |
async def spin_roulette_callback(interaction: discord.Interaction):
|
33 |
nonlocal balance
|
34 |
+
result_number = random.randint(0, 36)
|
35 |
+
result_color = "green" if result_number == 0 else ("red" if result_number % 2 == 1 else "black")
|
36 |
|
37 |
+
win = False
|
38 |
+
if choice.isdigit():
|
39 |
+
win = int(choice) == result_number
|
40 |
+
payout = bet * 35 if win else -bet
|
41 |
else:
|
42 |
+
win = choice == result_color
|
43 |
+
payout = bet * 2 if win else -bet
|
44 |
|
45 |
+
balance += payout
|
46 |
user_cash[user_id] = balance
|
47 |
|
48 |
+
result_text = f"The ball landed on {result_color} {result_number}. "
|
49 |
+
result_text += f"You {'won' if win else 'lost'} ${abs(payout):.2f}."
|
50 |
+
|
51 |
embed.clear_fields()
|
52 |
embed.add_field(name="Result", value=result_text, inline=False)
|
53 |
embed.add_field(name="New Balance", value=f"${balance:.2f}", inline=False)
|
|
|
56 |
|
57 |
async def spin_again_callback(interaction: discord.Interaction):
|
58 |
if interaction.user.id == user_id:
|
59 |
+
await play_roulette(interaction, bet, choice)
|
60 |
else:
|
61 |
await interaction.response.send_message("You can't spin this.", ephemeral=True)
|
62 |
|
|
|
75 |
if interaction.response.is_done():
|
76 |
await interaction.followup.send(embed=embed, view=view)
|
77 |
else:
|
78 |
+
await interaction.response.send_message(embed=embed, view=view)
|
79 |
+
|
80 |
+
# Ensure you have set up your bot and registered this command appropriately in your bot setup code.
|