coollsd commited on
Commit
573f931
·
verified ·
1 Parent(s): 704ef6b

Update petroll.py

Browse files
Files changed (1) hide show
  1. petroll.py +66 -71
petroll.py CHANGED
@@ -96,7 +96,7 @@ async def perform_roll(interaction: discord.Interaction):
96
  view = discord.ui.View()
97
  view.add_item(roll_again_button)
98
 
99
- # Check if the user has auto-sell enabled
100
  if user_id not in auto_sell_users:
101
  sell_button = discord.ui.Button(style=discord.ButtonStyle.success, label=f"Sell Pet for ${rap_value}", custom_id="sell_pet")
102
 
@@ -220,27 +220,30 @@ async def perform_roll(interaction: discord.Interaction):
220
  auto_sell_button.style = discord.ButtonStyle.primary
221
  auto_sell_button.label = "Auto Pet Sell"
222
  await interaction.response.send_message("Auto pet sell stopped.", ephemeral=True)
 
 
 
 
223
  else:
224
  auto_sell_users.add(user_id)
225
  auto_sell_button.style = discord.ButtonStyle.danger
226
  auto_sell_button.label = "Stop Auto Pet Sell"
227
  await interaction.response.send_message("Auto pet sell started.", ephemeral=True)
228
 
 
 
 
 
229
  await interaction.message.edit(view=view)
230
 
231
  auto_sell_button.callback = auto_sell_callback
232
  view.add_item(auto_sell_button)
233
 
234
- # Automatically sell the pet and update the balance when auto-sell is enabled.
235
- if user_id in auto_sell_users:
236
- user_cash[user_id] += rap_value
237
- embed.add_field(name="Auto Sell", value=f"Pet automatically sold for ${rap_value}. New balance: ${user_cash[user_id]}", inline=False)
238
-
239
  return embed, view
240
 
241
  async def schedule_next_luck_opportunity(interaction: discord.Interaction, user_id: int):
242
  await asyncio.sleep(1800) # Wait for 30 minutes
243
- luck_opportunities[user_id] += 1
244
  increase_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Increase Luck", custom_id=f"increase_luck_{luck_opportunities[user_id]}")
245
 
246
  async def increase_luck_callback(interaction: discord.Interaction):
@@ -255,73 +258,65 @@ async def schedule_next_luck_opportunity(interaction: discord.Interaction, user_
255
  current_luck = luck_multipliers.get(user_id, 1)
256
  new_luck = min(current_luck + 1, 10)
257
  luck_multipliers[user_id] = new_luck
258
- luck_expiration[user_id] += time.time() + 1800
259
 
260
- used_luck_opportunities.setdefault(user_id, set()).add(luck_opportunities[user_id])
 
 
261
 
262
  luck_percentage = (new_luck - 1) * 100
263
  await interaction.response.send_message(f"Your luck has been increased to {luck_percentage}% for 30 minutes!", ephemeral=True)
 
 
 
 
 
 
 
264
 
265
- view.children.remove(next(item for item in view.children if item.custom.id == increase.luck.button.custom.id))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
 
267
- async def schedule_next.lucK.opportunity(interaction: discord.Interaction, user.id: int):
268
- await asyncio.sleep(1800) # Wait for thirty minutes.
269
- luck.opportunities[user.id] += one.
270
- increase.lucK.button equals to discord.ui.button(style equals to discord.buttonstyle.success,label equals to "Increase Luck",custom.id equals to f"increase.lucK.{luck.opportunities[user.id]}")
271
-
272
- async def increase.lucK.callback(interaction:discord.interaction):
273
- if (interaction.user.id!=user.id):
274
- await (interaction.response.send.message)("You cannot use this button.",ephemeral equals to true.)
275
- return.
276
- if ((user.id)in(used.lucK.opportunities))and(len(used.lucK.opportunities[user.id])>=four):
277
- await (interaction.response.send.message)("You have already used all your lucK opportunities.",ephemeral equals to true.)
278
- return.
279
- current.lucK equals to lucK.multipliers.get(user.id,one.)
280
- new.lucK equals to min(current.lucK plus one.,ten.)
281
- lucK.multipliers[user.id]=new.lucK.
282
- lucK.expiration[user.id]+=time.time() plus eighteen.hundred.
283
- used.lucK.opportunities.setdefault(user.id,set()).add(lucK.opportunities[user.id])
284
- lucK.percentage equals to(new.lucK minus one.)times one.hundred.
285
- await (interaction.response.send.message)(f"Your lucK has been increased to{lucK.percentage}%for thirty minutes!",ephemeral equals to true.)
286
- view.children.remove(next(item for item in view.children.if.item.custom.id==increase.lucK.button.custom.id))
287
-
288
- view equals to (interaction.message.components[zero])
289
- view.add.item(increase.lucK.button).
290
- await (interaction.message.edit)(view equals to view).
291
-
292
- async def (auto.roll)(interaction:discord.interaction):
293
- user id equals to (interaction.user id).
294
- start time equals to (time.time())
295
- while ((user id)in(auto.roll.users)):
296
- if((time.time())minus start time)>=one.eighty):#three minutes.
297
- auto.roll.users.remove(user id).
298
- await (interaction.followup send)("Auto roll has been automatically stopped after three minutes. You can start it again. If you wish.",ephemeral equals to true.)
299
- break.
300
- result equals to(await perform.roll)(interaction).
301
- if(result):
302
- await (interaction.followup send)(embed equals to result[zero],view equals to result[one])
303
- else:
304
- await (interaction.followup send)("An error occurred.")
305
- await asyncio.sleep(five)#Wait for five seconds between rolls.
306
-
307
- @app.commands.command(name equals to "petroll",description equals to "Roll for a random pet")
308
- async def(petroll)(interaction:discord.interaction):
309
- await (interaction response defer)()
310
- result equals to(await perform.roll)(interaction).
311
- if(result):
312
- await (interaction followup send)(embed equals to result[zero],view.equals.to.result[one])
313
- else:
314
- await (interaction followup send)("An error occurred.")
315
-
316
- @app.commands.command(name.equals.to."balance",description.equals.to."Check your current balance")
317
- async def(balance)(interaction:discord.interaction):
318
- user id.equals.to.(interaction.user id).
319
- current balance.equals.to.(user cash get)(user id.zero.)
320
- await (interaction response send message)(f"Your current balance is${current.balance}.",ephemeral.equals.to.true.)
321
-
322
- @app.commands.command(name.equals.to."dice",description.equals.to."Roll the dice and bet")
323
- async def(dice)(interaction:discord.interaction.bet:int):
324
- await roll dice(interaction.bet).
325
-
326
- async def(roll dice)(interaction:discord.interaction.bet:int):
327
- user i
 
96
  view = discord.ui.View()
97
  view.add_item(roll_again_button)
98
 
99
+ # Only add the sell button if auto-sell is not active for this user
100
  if user_id not in auto_sell_users:
101
  sell_button = discord.ui.Button(style=discord.ButtonStyle.success, label=f"Sell Pet for ${rap_value}", custom_id="sell_pet")
102
 
 
220
  auto_sell_button.style = discord.ButtonStyle.primary
221
  auto_sell_button.label = "Auto Pet Sell"
222
  await interaction.response.send_message("Auto pet sell stopped.", ephemeral=True)
223
+
224
+ # Re-add the normal sell button when stopping auto-sell
225
+ if sell_button not in view.children:
226
+ view.add_item(sell_button)
227
  else:
228
  auto_sell_users.add(user_id)
229
  auto_sell_button.style = discord.ButtonStyle.danger
230
  auto_sell_button.label = "Stop Auto Pet Sell"
231
  await interaction.response.send_message("Auto pet sell started.", ephemeral=True)
232
 
233
+ # Automatically add cash for the rolled pet when auto-sell is enabled
234
+ user_cash[user_id] = user_cash.get(user_id, 0) + rap_value
235
+ embed.add_field(name="Auto Sell", value=f"Pet automatically sold for ${rap_value}. New balance: ${user_cash[user_id]}", inline=False)
236
+
237
  await interaction.message.edit(view=view)
238
 
239
  auto_sell_button.callback = auto_sell_callback
240
  view.add_item(auto_sell_button)
241
 
 
 
 
 
 
242
  return embed, view
243
 
244
  async def schedule_next_luck_opportunity(interaction: discord.Interaction, user_id: int):
245
  await asyncio.sleep(1800) # Wait for 30 minutes
246
+ luck_opportunities[user_id] = luck_opportunities.get(user_id, 0) + 1
247
  increase_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Increase Luck", custom_id=f"increase_luck_{luck_opportunities[user_id]}")
248
 
249
  async def increase_luck_callback(interaction: discord.Interaction):
 
258
  current_luck = luck_multipliers.get(user_id, 1)
259
  new_luck = min(current_luck + 1, 10)
260
  luck_multipliers[user_id] = new_luck
261
+ luck_expiration[user_id] = time.time() + 1800
262
 
263
+ if user_id not in used_luck_opportunities:
264
+ used_luck_opportunities[user_id] = set()
265
+ used_luck_opportunities[user_id].add(luck_opportunities[user_id])
266
 
267
  luck_percentage = (new_luck - 1) * 100
268
  await interaction.response.send_message(f"Your luck has been increased to {luck_percentage}% for 30 minutes!", ephemeral=True)
269
+
270
+ view = interaction.message.components[0]
271
+ for item in view.children:
272
+ if item.custom_id == interaction.custom_id:
273
+ view.remove_item(item)
274
+ break
275
+ await interaction.message.edit(view=view)
276
 
277
+ # Schedule the next luck opportunity
278
+ asyncio.create_task(schedule_next_luck_opportunity(interaction, user_id))
279
+
280
+ increase_luck_button.callback = increase_luck_callback
281
+
282
+ view = interaction.message.components[0]
283
+ view.add_item(increase_luck_button)
284
+ await interaction.message.edit(view=view)
285
+
286
+ async def auto_roll(interaction: discord.Interaction):
287
+ user_id = interaction.user.id
288
+ start_time = time.time()
289
+ while user_id in auto_roll_users:
290
+ if time.time() - start_time >= 180: # 3 minutes
291
+ auto_roll_users.remove(user_id)
292
+ await interaction.followup.send("auto roll stopped, to turn it on again roll again and turn it on.", ephemeral=True)
293
+ break
294
 
295
+ result = await perform_roll(interaction)
296
+ if result:
297
+ await interaction.followup.send(embed=result[0], view=result[1])
298
+ else:
299
+ await interaction.followup.send("An error occurred.")
300
+ await asyncio.sleep(5) # Wait for 5 seconds between rolls
301
+
302
+ @app_commands.command(name="petroll", description="Roll for a random pet")
303
+ async def petroll(interaction: discord.Interaction):
304
+ await interaction.response.defer()
305
+ result = await perform_roll(interaction)
306
+ if result:
307
+ await interaction.followup.send(embed=result[0], view=result[1])
308
+ else:
309
+ await interaction.followup.send("An error occurred.")
310
+
311
+ @app_commands.command(name="balance", description="Check your current balance")
312
+ async def balance(interaction: discord.Interaction):
313
+ user_id = interaction.user.id
314
+ current_balance = user_cash.get(user_id, 0)
315
+ await interaction.response.send_message(f"Your current balance is ${current_balance}.", ephemeral=True)
316
+
317
+ @app_commands.command(name="dice", description="Roll the dice and bet")
318
+ async def dice(interaction: discord.Interaction, bet: int):
319
+ await roll_dice(interaction, bet)
320
+
321
+ async def roll_dice(interaction: discord.Interaction, bet: int):
322
+ user_i