coollsd commited on
Commit
8b11f06
·
verified ·
1 Parent(s): 7ceaf47

Update petroll.py

Browse files
Files changed (1) hide show
  1. petroll.py +128 -5
petroll.py CHANGED
@@ -4,9 +4,13 @@ import aiohttp
4
  import random
5
  import time
6
 
 
 
7
  luck_multipliers = {}
8
  luck_expiration = {}
9
  luck_opportunities = {}
 
 
10
 
11
  async def perform_roll(interaction: discord.Interaction):
12
  async def fetch_data(url):
@@ -57,9 +61,9 @@ async def perform_roll(interaction: discord.Interaction):
57
  return f"{difficulty} ({difficulty:,})"
58
 
59
  embed = discord.Embed(title=f"{interaction.user.name} rolled: {rolled_pet['configData']['name']}", color=0x787878)
60
- embed.add_field(name="value", value=f"{rap_value:,} diamonds", inline=True)
61
- embed.add_field(name="difficulty", value=format_difficulty(rolled_pet['configData']['difficulty']), inline=True)
62
- embed.add_field(name="category", value=rolled_pet['category'], inline=True)
63
  embed.set_thumbnail(url=thumbnail_url)
64
 
65
  luck_text = ""
@@ -89,7 +93,48 @@ async def perform_roll(interaction: discord.Interaction):
89
  view = discord.ui.View()
90
  view.add_item(roll_again_button)
91
 
92
- if random.random() < 0.2:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  luck_opportunities[user_id] = luck_opportunities.get(user_id, 0) + 1
94
  increase_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Increase Luck", custom_id=f"increase_luck_{luck_opportunities[user_id]}")
95
 
@@ -98,11 +143,19 @@ async def perform_roll(interaction: discord.Interaction):
98
  await interaction.response.send_message("You cannot use this button.", ephemeral=True)
99
  return
100
 
 
 
 
 
101
  current_luck = luck_multipliers.get(user_id, 1)
102
  new_luck = min(current_luck + 1, 10)
103
  luck_multipliers[user_id] = new_luck
104
  luck_expiration[user_id] = time.time() + 1800
105
 
 
 
 
 
106
  luck_percentage = (new_luck - 1) * 100
107
  await interaction.response.send_message(f"Your luck has been increased to {luck_percentage}% for 30 minutes!", ephemeral=True)
108
 
@@ -124,4 +177,74 @@ async def petroll(interaction: discord.Interaction):
124
  if result:
125
  await interaction.followup.send(embed=result[0], view=result[1])
126
  else:
127
- await interaction.followup.send("errer")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  import random
5
  import time
6
 
7
+ from cash import user_cash
8
+
9
  luck_multipliers = {}
10
  luck_expiration = {}
11
  luck_opportunities = {}
12
+ used_luck_opportunities = set()
13
+ first_luck_claimed = set()
14
 
15
  async def perform_roll(interaction: discord.Interaction):
16
  async def fetch_data(url):
 
61
  return f"{difficulty} ({difficulty:,})"
62
 
63
  embed = discord.Embed(title=f"{interaction.user.name} rolled: {rolled_pet['configData']['name']}", color=0x787878)
64
+ embed.add_field(name="Value", value=f"{rap_value:,} diamonds", inline=True)
65
+ embed.add_field(name="Difficulty", value=format_difficulty(rolled_pet['configData']['difficulty']), inline=True)
66
+ embed.add_field(name="Category", value=rolled_pet['category'], inline=True)
67
  embed.set_thumbnail(url=thumbnail_url)
68
 
69
  luck_text = ""
 
93
  view = discord.ui.View()
94
  view.add_item(roll_again_button)
95
 
96
+ sell_button = discord.ui.Button(style=discord.ButtonStyle.success, label=f"Sell Pet for ${rap_value}", custom_id="sell_pet")
97
+
98
+ async def sell_pet_callback(interaction: discord.Interaction):
99
+ if interaction.user.id != user_id:
100
+ await interaction.response.send_message("You cannot sell this pet.", ephemeral=True)
101
+ return
102
+
103
+ sell_value = rap_value
104
+ user_cash[user_id] = user_cash.get(user_id, 0) + sell_value
105
+ await interaction.response.send_message(f"You sold the pet for ${sell_value}. Your new balance is ${user_cash[user_id]}.", ephemeral=True)
106
+ for item in view.children:
107
+ if item.custom_id == "sell_pet":
108
+ view.remove_item(item)
109
+ break
110
+ await interaction.message.edit(view=view)
111
+
112
+ sell_button.callback = sell_pet_callback
113
+ view.add_item(sell_button)
114
+
115
+ if user_id not in first_luck_claimed:
116
+ first_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Claim 100% Luck Forever", custom_id="first_luck")
117
+
118
+ async def first_luck_callback(interaction: discord.Interaction):
119
+ if interaction.user.id != user_id:
120
+ await interaction.response.send_message("You cannot use this button.", ephemeral=True)
121
+ return
122
+
123
+ luck_multipliers[user_id] = 10 # 100% luck
124
+ first_luck_claimed.add(user_id)
125
+
126
+ await interaction.response.send_message("You've claimed 100% luck forever!", ephemeral=True)
127
+
128
+ for item in view.children:
129
+ if item.custom_id == "first_luck":
130
+ view.remove_item(item)
131
+ break
132
+ await interaction.message.edit(view=view)
133
+
134
+ first_luck_button.callback = first_luck_callback
135
+ view.add_item(first_luck_button)
136
+
137
+ elif random.random() < 0.6 and luck_opportunities.get(user_id, 0) < 4:
138
  luck_opportunities[user_id] = luck_opportunities.get(user_id, 0) + 1
139
  increase_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Increase Luck", custom_id=f"increase_luck_{luck_opportunities[user_id]}")
140
 
 
143
  await interaction.response.send_message("You cannot use this button.", ephemeral=True)
144
  return
145
 
146
+ if user_id in used_luck_opportunities and len(used_luck_opportunities[user_id]) >= 4:
147
+ await interaction.response.send_message("You have already used all your luck opportunities.", ephemeral=True)
148
+ return
149
+
150
  current_luck = luck_multipliers.get(user_id, 1)
151
  new_luck = min(current_luck + 1, 10)
152
  luck_multipliers[user_id] = new_luck
153
  luck_expiration[user_id] = time.time() + 1800
154
 
155
+ if user_id not in used_luck_opportunities:
156
+ used_luck_opportunities[user_id] = set()
157
+ used_luck_opportunities[user_id].add(luck_opportunities[user_id])
158
+
159
  luck_percentage = (new_luck - 1) * 100
160
  await interaction.response.send_message(f"Your luck has been increased to {luck_percentage}% for 30 minutes!", ephemeral=True)
161
 
 
177
  if result:
178
  await interaction.followup.send(embed=result[0], view=result[1])
179
  else:
180
+ await interaction.followup.send("An error occurred.")
181
+
182
+ @app_commands.command(name="balance", description="Check your current balance")
183
+ async def balance(interaction: discord.Interaction):
184
+ user_id = interaction.user.id
185
+ current_balance = user_cash.get(user_id, 0)
186
+ await interaction.response.send_message(f"Your current balance is ${current_balance}.", ephemeral=True)
187
+
188
+ @app_commands.command(name="dice", description="Roll the dice and bet")
189
+ async def dice(interaction: discord.Interaction, bet: int):
190
+ await roll_dice(interaction, bet)
191
+
192
+ async def roll_dice(interaction: discord.Interaction, bet: int):
193
+ user_id = interaction.user.id
194
+ balance = user_cash.get(user_id, 0)
195
+
196
+ if bet <= 0:
197
+ await interaction.response.send_message("Bet Higher than 0 Idiot.")
198
+ return
199
+
200
+ if bet > balance:
201
+ await interaction.response.send_message(f"You don't have enough cash. Your current balance is ${balance:.2f}")
202
+ return
203
+
204
+ embed = discord.Embed(title="Dice Roll", description=f"{interaction.user.name} is betting ${bet:.2f}", color=0x787878)
205
+ embed.add_field(name="Current Balance", value=f"${balance:.2f}", inline=False)
206
+
207
+ roll_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Roll the Dice", custom_id="roll_dice")
208
+
209
+ async def roll_dice_callback(interaction: discord.Interaction):
210
+ nonlocal balance
211
+ result = random.choice(["win", "lose"])
212
+
213
+ if result == "win":
214
+ winnings = bet
215
+ balance += winnings
216
+ result_text = f"You won ${winnings:.2f}!"
217
+ else:
218
+ balance -= bet
219
+ result_text = f"You lost ${bet:.2f}."
220
+
221
+ user_cash[user_id] = balance
222
+
223
+ embed.clear_fields()
224
+ embed.add_field(name="Result", value=result_text, inline=False)
225
+ embed.add_field(name="New Balance", value=f"${balance:.2f}", inline=False)
226
+
227
+ roll_again_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Roll Again", custom_id="roll_again")
228
+
229
+ async def roll_again_callback(interaction: discord.Interaction):
230
+ if interaction.user.id == user_id:
231
+ await roll_dice(interaction, bet)
232
+ else:
233
+ await interaction.response.send_message("you cant roll this", ephemeral=True)
234
+
235
+ roll_again_button.callback = roll_again_callback
236
+
237
+ new_view = discord.ui.View()
238
+ new_view.add_item(roll_again_button)
239
+
240
+ await interaction.response.edit_message(embed=embed, view=new_view)
241
+
242
+ roll_button.callback = roll_dice_callback
243
+
244
+ view = discord.ui.View()
245
+ view.add_item(roll_button)
246
+
247
+ if interaction.response.is_done():
248
+ await interaction.followup.send(embed=embed, view=view)
249
+ else:
250
+ await interaction.response.send_message(embed=embed, view=view)