Spaces:
Building
Building
Update app.py
Browse files
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,14 @@ 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
|
102 |
-
|
103 |
|
104 |
-
# Select a random pet from the
|
105 |
-
rolled_pet = random.choice(sorted_pets[:
|
106 |
|
107 |
pet_rap = next((pet for pet in rap_data['data'] if pet['configData']['id'] == rolled_pet['configName']), None)
|
108 |
|
@@ -155,17 +156,22 @@ async def perform_roll(interaction: discord.Interaction):
|
|
155 |
view = discord.ui.View()
|
156 |
view.add_item(roll_again_button)
|
157 |
|
158 |
-
if random.random() < 0.2:
|
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):
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
|
|
|
|
|
|
|
|
|
|
169 |
|
170 |
increase_luck_button.callback = increase_luck_callback
|
171 |
view.add_item(increase_luck_button)
|
|
|
15 |
|
16 |
luck_multipliers = {}
|
17 |
luck_expiration = {}
|
18 |
+
luck_button_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 |
+
# Sort pets by difficulty in descending order
|
100 |
+
sorted_pets = sorted(pets, key=lambda x: x['configData']['difficulty'], reverse=True)
|
101 |
|
102 |
+
# Calculate the number of pets to consider based on luck
|
103 |
+
num_pets_to_consider = max(1, int(len(sorted_pets) * (luck_multiplier / 10)))
|
104 |
|
105 |
+
# Select a random pet from the top pets based on luck
|
106 |
+
rolled_pet = random.choice(sorted_pets[:num_pets_to_consider])
|
107 |
|
108 |
pet_rap = next((pet for pet in rap_data['data'] if pet['configData']['id'] == rolled_pet['configName']), None)
|
109 |
|
|
|
156 |
view = discord.ui.View()
|
157 |
view.add_item(roll_again_button)
|
158 |
|
159 |
+
if random.random() < 0.2 and user_id not in luck_button_used:
|
160 |
increase_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Increase Luck", custom_id="increase_luck")
|
161 |
|
162 |
async def increase_luck_callback(interaction: discord.Interaction):
|
163 |
+
if interaction.user.id != user_id:
|
164 |
+
await interaction.response.send_message("You cannot use this look!", ephemeral=True)
|
165 |
+
return
|
166 |
+
|
167 |
+
if user_id in luck_button_used:
|
168 |
+
await interaction.response.send_message("You already used your lick!", ephemeral=True)
|
169 |
+
return
|
170 |
+
|
171 |
+
luck_multipliers[user_id] = 10
|
172 |
+
luck_expiration[user_id] = time.time() + 1800 # 30 minutes
|
173 |
+
luck_button_used.add(user_id)
|
174 |
+
await interaction.response.send_message("Your luck has been increased for 30 minutes!", ephemeral=True)
|
175 |
|
176 |
increase_luck_button.callback = increase_luck_callback
|
177 |
view.add_item(increase_luck_button)
|