Spaces:
Paused
Paused
Update roulette.py
Browse files3 unmodified lines45678910111213144 unmodified lines1920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980813 unmodified linesfrom cash import user_cash@app_commands.command(name="roulette", description="Play roulette and bet")async def roulette(interaction: discord.Interaction, bet: int, choice: str):await play_roulette(interaction, bet, choice)async def play_roulette(interaction: discord.Interaction, bet: int, choice: str):user_id = interaction.user.idbalance = user_cash.get(user_id, 0)4 unmodified linesif bet > balance:await interaction.response.send_message(f"You don't have enough cash. Your current balance is ${balance:.2f}")returnvalid_choices = ["red", "black", "green"] + [str(i) for i in range(37)]if choice not in valid_choices:await interaction.response.send_message("Invalid choice. Choose 'red', 'black', 'green', or a number between 0 and 36.")returnembed = discord.Embed(title="Roulette Game", description=f"{interaction.user.name} is betting ${bet:.2f}", color=0x787878)embed.add_field(name="Your Bet", value=f"Choice: {choice}", inline=False)embed.add_field(name="Current Balance", value=f"${balance:.2f}", inline=False)spin_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Spin the Roulette 🎡", custom_id="spin_roulette")async def spin_roulette_callback(interaction: discord.Interaction):nonlocal balanceresult_number = random.randint(0, 36)result_color = "green" if result_number == 0 else ("red" if result_number % 2 == 1 else "black")win = Falsepayout = -betif choice.isdigit():win = int(choice) == result_numberpayout = bet * 35 if win else payoutelse:win = choice == result_colorpayout = bet * 2 if win else payoutbalance += payoutuser_cash[user_id] = balanceresult_text = f"The ball landed on {result_color} {result_number}. "result_text += f"You {'won' if win else 'lost'} ${abs(payout):.2f}."embed.clear_fields()embed.add_field(name="Result", value=result_text, inline=False)embed.add_field(name="New Balance", value=f"${balance:.2f}", inline=False)spin_again_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Spin Again 🔄", custom_id="spin_again")async def spin_again_callback(interaction: discord.Interaction):if interaction.user.id == user_id:await play_roulette(interaction, bet, choice)else:await interaction.response.send_message("You can't spin this.", ephemeral=True)spin_again_button.callback = spin_again_callbacknew_view = discord.ui.View()new_view.add_item(spin_again_button)await interaction.response.edit_message(embed=embed, view=new_view)spin_button.callback = spin_roulette_callbackview = discord.ui.View()view.add_item(spin_button)if interaction.response.is_done():await interaction.followup.send(embed=embed, view=view)else:await interaction.response.send_message(embed=embed, view=view)3 unmodified lines4567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253544 unmodified lines59606162636465666768693 unmodified linesfrom cash import user_cashclass RouletteGame(discord.ui.View):def __init__(self, user_id, bet, choice):super().__init__()self.user_id = user_idself.bet = betself.choice = choiceself.balance = user_cash.get(user_id, 0)@discord.ui.button(style=discord.ButtonStyle.primary, label="Spin the Roulette 🎡", custom_id="spin_roulette")async def spin_roulette_callback(self, interaction: discord.Interaction, button: discord.ui.Button):if interaction.user.id != self.user_id:await interaction.response.send_message("You can't spin this.", ephemeral=True)returnresult_number = random.randint(0, 36)result_color = "green" if result_number == 0 else ("red" if result_number % 2 == 1 else "black")win = Falsepayout = -self.betif self.choice.isdigit():win = int(self.choice) == result_numberpayout = self.bet * 35 if win else payoutelse:win = self.choice == result_colorpayout = self.bet * 2 if win else payoutself.balance += payoutuser_cash[self.user_id] = self.balanceembed = discord.Embed(title="Roulette Game", color=0x787878)embed.add_field(name="Result", value=f"The ball landed on {result_color} {result_number}. You {'won' if win else 'lost'} ${abs(payout):.2f}.", inline=False)embed.add_field(name="New Balance", value=f"${self.balance:.2f}", inline=False)await interaction.response.edit_message(embed=embed, view=None)@app_commands.command(name="roulette", description="Play roulette and bet")@app_commands.describe(choice="Choose 'red', 'black', 'green', or a number between 0 and 36.")@app_commands.choices(choice=[app_commands.Choice(name="Red", value="red"),app_commands.Choice(name="Black", value="black"),app_commands.Choice(name="Green", value="green")] + [app_commands.Choice(name=str(i), value=str(i)) for i in range(37)])async def roulette(interaction: discord.Interaction, bet: int, choice: str):user_id = interaction.user.idbalance = user_cash.get(user_id, 0)4 unmodified linesif bet > balance:await interaction.response.send_message(f"You don't have enough cash. Your current balance is ${balance:.2f}")returnembed = discord.Embed(title="Roulette Game", description=f"{interaction.user.name} is betting ${bet:.2f}", color=0x787878)embed.add_field(name="Your Bet", value=f"Choice: {choice}", inline=False)embed.add_field(name="Current Balance", value=f"${balance:.2f}", inline=False)view = RouletteGame(user_id=user_id, bet=bet, choice=choice)await interaction.response.send_message(embed=embed, view=view)
roulette.py+46-58