Spaces:
Paused
Paused
Update roulette.py
Browse files1 unmodified line234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301 unmodified linefrom discord import app_commandsimport randomfrom cash import user_cash # Ensure you have a 'cash.py' with a 'user_cash' dictionaryclass RouletteView(discord.ui.View):def __init__(self, user_id: int, bet: int, balance: float):super().__init__(timeout=None)self.user_id = user_idself.bet = betself.balance = balanceself.add_item(RollRouletteButton())class RollRouletteButton(discord.ui.Button):def __init__(self):super().__init__(style=discord.ButtonStyle.primary, label="Spin the Wheel", custom_id="roll_roulette")async def callback(self, interaction: discord.Interaction):if interaction.user.id != self.view.user_id:await interaction.response.send_message("You can't spin this wheel.", ephemeral=True)return# Simulate roulette spinnumber = random.randint(0, 36)color = self.get_color(number)win = Falsepayout = 0# Simple roulette logic: win if number is even, lose otherwiseif number != 0 and number % 2 == 0:win = Truepayout = self.view.bet # 1:1 payoutif win:self.view.balance += payoutresult_text = f"🎉 You won ${payout:.2f}! The ball landed on {number} ({color})."else:self.view.balance -= self.view.betresult_text = f"😞 You lost ${self.view.bet:.2f}. The ball landed on {number} ({color})."# Update user's balanceuser_cash[self.view.user_id] = self.view.balance# Create a new embed with the resultembed = discord.Embed(title="🎰 Roulette Spin", description=result_text, color=0x787878)embed.add_field(name="New Balance", value=f"${self.view.balance:.2f}", inline=False)# Update the view with a "Spin Again" buttonself.view.clear_items()self.view.add_item(SpinAgainButton())await interaction.response.edit_message(embed=embed, view=self.view)@staticmethoddef get_color(number: int) -> str:if number == 0:return "Green"# Simplified color assignment for demonstrationreturn "Red" if number % 2 == 0 else "Black"class SpinAgainButton(discord.ui.Button):def __init__(self):super().__init__(style=discord.ButtonStyle.success, label="Spin Again", custom_id="spin_again")async def callback(self, interaction: discord.Interaction):if interaction.user.id != self.view.user_id:await interaction.response.send_message("You can't spin this wheel.", ephemeral=True)return# Prevent betting if balance is insufficientif self.view.bet > self.view.balance:await interaction.response.send_message(f"You don't have enough cash to spin again. Your current balance is ${self.view.balance:.2f}",ephemeral=True)returnawait interaction.response.defer()# Create an embed to show the betting statusembed = discord.Embed(title="🎰 Roulette Spin",description=f"{interaction.user.name} is betting ${self.view.bet:.2f}",color=0xFFA500)embed.add_field(name="Current Balance", value=f"${self.view.balance:.2f}", inline=False)# Replace buttons with a new roll buttonself.view.clear_items()self.view.add_item(RollRouletteButton())await interaction.edit_message(embed=embed, view=self.view)@app_commands.command(name="roulette", description="Play roulette and place a bet.")async def roulette(interaction: discord.Interaction, bet: int):await play_roulette(interaction, bet)async def play_roulette(interaction: discord.Interaction, bet: int):user_id = interaction.user.idbalance = user_cash.get(user_id, 0)if bet <= 0:await interaction.response.send_message("❌ Your bet must be higher than $0.", ephemeral=True)returnif bet > balance:await interaction.response.send_message(f"❌ You don't have enough cash to bet ${bet:.2f}. Your current balance is ${balance:.2f}.",ephemeral=True)return# Create an embed to show the betting statusembed = discord.Embed(title="🎰 Roulette Spin",description=f"{interaction.user.name} is betting ${bet:.2f}",color=0xFFA500)embed.add_field(name="Current Balance", value=f"${balance:.2f}", inline=False)# Initialize the view with the Spin buttonview = RouletteView(user_id=user_id, bet=bet, balance=balance)# Add the RollRouletteButton to the viewview.add_item(RollRouletteButton())if interaction.response.is_done():await interaction.followup.send(embed=embed, view=view)else:1 unmodified line2345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667681 unmodified linefrom discord import app_commandsimport randomfrom cash import user_cash@app_commands.command(name="roulette", description="Play roulette and bet")async def roulette(interaction: discord.Interaction, bet: int):await play_roulette(interaction, bet)async def play_roulette(interaction: discord.Interaction, bet: int):user_id = interaction.user.idbalance = user_cash.get(user_id, 0)if bet <= 0:await interaction.response.send_message("Bet higher than 0, please.")returnif 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=0x3498db)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 = random.choice(["win", "lose"])if result == "win":winnings = bet * 2 # Assuming a simple win condition for demonstrationbalance += winningsresult_text = f"You won ${winnings:.2f}!"else:balance -= betresult_text = f"You lost ${bet:.2f}."user_cash[user_id] = balanceembed.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)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:
roulette.py+48-110