coollsd commited on
Commit
f7609fd
·
verified ·
1 Parent(s): 55ac1e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -15,6 +15,7 @@ tree = app_commands.CommandTree(bot)
15
 
16
  luck_multipliers = {}
17
  luck_expiration = {}
 
18
 
19
  @app.get("/")
20
  async def read_root():
@@ -95,14 +96,11 @@ async def perform_roll(interaction: discord.Interaction):
95
  user_id = interaction.user.id
96
  luck_multiplier = luck_multipliers.get(user_id, 1)
97
 
98
- # Sort pets by difficulty
99
  sorted_pets = sorted(pets, key=lambda x: x['configData']['difficulty'])
100
 
101
- # Calculate the index based on luck
102
  max_index = len(sorted_pets) - 1
103
- index = int(max_index * (luck_multiplier - 1) / 9) # Assuming max luck is 10
104
 
105
- # Select a random pet from the start of the list to the calculated index
106
  rolled_pet = random.choice(sorted_pets[:index+1])
107
 
108
  pet_rap = next((pet for pet in rap_data['data'] if pet['configData']['id'] == rolled_pet['configName']), None)
@@ -135,7 +133,7 @@ async def perform_roll(interaction: discord.Interaction):
135
  remaining_time = int(luck_expiration[user_id] - time.time())
136
  if remaining_time > 0:
137
  luck_percentage = (luck_multiplier - 1) * 100
138
- luck_text = f"\nYou have {remaining_time // 60} minutes and {remaining_time % 60} seconds of luck left! (x{luck_percentage}% luck)"
139
  else:
140
  del luck_multipliers[user_id]
141
  del luck_expiration[user_id]
@@ -157,7 +155,7 @@ async def perform_roll(interaction: discord.Interaction):
157
  view = discord.ui.View()
158
  view.add_item(roll_again_button)
159
 
160
- if random.random() < 0.2:
161
  increase_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Increase Luck", custom_id="increase_luck")
162
 
163
  async def increase_luck_callback(interaction: discord.Interaction):
@@ -165,12 +163,17 @@ async def perform_roll(interaction: discord.Interaction):
165
  await interaction.response.send_message("cannot use", ephemeral=True)
166
  return
167
 
 
 
 
 
168
  current_luck = luck_multipliers.get(user_id, 1)
169
- new_luck = min(current_luck + 1, 1000) # Cap at 10x
170
  luck_multipliers[user_id] = new_luck
171
- luck_expiration[user_id] = time.time() + 1800 # 30 minutes
 
172
 
173
- luck_percentage = (new_luck - 10) * 100
174
  await interaction.response.send_message(f"Your luck has been increased to x{luck_percentage}% for 30 minutes!", ephemeral=True)
175
 
176
  increase_luck_button.callback = increase_luck_callback
 
15
 
16
  luck_multipliers = {}
17
  luck_expiration = {}
18
+ luck_used = set()
19
 
20
  @app.get("/")
21
  async def read_root():
 
96
  user_id = interaction.user.id
97
  luck_multiplier = luck_multipliers.get(user_id, 1)
98
 
 
99
  sorted_pets = sorted(pets, key=lambda x: x['configData']['difficulty'])
100
 
 
101
  max_index = len(sorted_pets) - 1
102
+ index = int(max_index * (luck_multiplier - 1) / 9)
103
 
 
104
  rolled_pet = random.choice(sorted_pets[:index+1])
105
 
106
  pet_rap = next((pet for pet in rap_data['data'] if pet['configData']['id'] == rolled_pet['configName']), None)
 
133
  remaining_time = int(luck_expiration[user_id] - time.time())
134
  if remaining_time > 0:
135
  luck_percentage = (luck_multiplier - 1) * 100
136
+ luck_text = f"\nYou have {remaining_time // 60} minutes and {remaining_time % 60} seconds of luck left! ({luck_percentage}% luck)"
137
  else:
138
  del luck_multipliers[user_id]
139
  del luck_expiration[user_id]
 
155
  view = discord.ui.View()
156
  view.add_item(roll_again_button)
157
 
158
+ if random.random() < 0.2 and user_id not in luck_used:
159
  increase_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Increase Luck", custom_id="increase_luck")
160
 
161
  async def increase_luck_callback(interaction: discord.Interaction):
 
163
  await interaction.response.send_message("cannot use", ephemeral=True)
164
  return
165
 
166
+ if user_id in luck_used:
167
+ await interaction.response.send_message("You've already used your luck increase!", ephemeral=True)
168
+ return
169
+
170
  current_luck = luck_multipliers.get(user_id, 1)
171
+ new_luck = min(current_luck + 1, 10)
172
  luck_multipliers[user_id] = new_luck
173
+ luck_expiration[user_id] = time.time() + 1800
174
+ luck_used.add(user_id)
175
 
176
+ luck_percentage = (new_luck - 1) * 100
177
  await interaction.response.send_message(f"Your luck has been increased to x{luck_percentage}% for 30 minutes!", ephemeral=True)
178
 
179
  increase_luck_button.callback = increase_luck_callback