Spaces:
Paused
Paused
Update petroll.py
Browse files- petroll.py +83 -85
petroll.py
CHANGED
|
@@ -96,32 +96,28 @@ async def perform_roll(interaction: discord.Interaction):
|
|
| 96 |
view = discord.ui.View()
|
| 97 |
view.add_item(roll_again_button)
|
| 98 |
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
-
|
| 109 |
-
user_cash[user_id] = user_cash.get(user_id, 0) + sell_value
|
| 110 |
-
await interaction.response.send_message(f"You sold the pet for ${sell_value}. Your new balance is ${user_cash[user_id]}.", ephemeral=True)
|
| 111 |
-
for item in view.children:
|
| 112 |
-
if item.custom_id == "sell_pet":
|
| 113 |
-
view.remove_item(item)
|
| 114 |
-
break
|
| 115 |
-
await interaction.message.edit(view=view)
|
| 116 |
|
| 117 |
-
|
|
|
|
| 118 |
view.add_item(sell_button)
|
| 119 |
|
| 120 |
-
# Automatically process sale when auto-sell is active
|
| 121 |
-
if user_id in auto_sell_users:
|
| 122 |
-
user_cash[user_id] += rap_value
|
| 123 |
-
embed.add_field(name="Auto Sell", value=f"Pet automatically sold for ${rap_value}. New balance: ${user_cash[user_id]}", inline=False)
|
| 124 |
-
|
| 125 |
if user_id not in first_luck_claimed:
|
| 126 |
first_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Claim 100% Luck Forever", custom_id="first_luck")
|
| 127 |
|
|
@@ -225,82 +221,84 @@ async def perform_roll(interaction: discord.Interaction):
|
|
| 225 |
auto_sell_button.style = discord.ButtonStyle.primary
|
| 226 |
auto_sell_button.label = "Auto Pet Sell"
|
| 227 |
await interaction.response.send_message("Auto pet sell stopped.", ephemeral=True)
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
sell_button.style=discord.ButtonStyle.success
|
| 231 |
-
sell_button.label=f"Sell Pet for ${rap_value}"
|
| 232 |
-
view.add_item(sell_button)
|
| 233 |
-
|
| 234 |
else:
|
| 235 |
auto_sell_users.add(user_id)
|
| 236 |
auto_sell_button.style = discord.ButtonStyle.danger
|
| 237 |
auto_sell_button.label = "Stop Auto Pet Sell"
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
embed.add_field(name="Auto Sell", value=f"Pet automatically sold for ${rap_value}. New balance: ${user_cash[user_id]}", inline=False)
|
| 242 |
-
|
| 243 |
-
await interaction.response.send_message(f"Auto pet sell started. Pet sold for ${rap_value}. New balance is ${user_cash[user_id]}.", ephemeral=True)
|
| 244 |
-
|
| 245 |
-
await interaction.message.edit(view=view)
|
| 246 |
-
|
| 247 |
-
auto_sell_button.callback=auto_sell_callback
|
| 248 |
-
view.add_item(auto_sell_button)
|
| 249 |
-
|
| 250 |
-
return embed, view
|
| 251 |
-
|
| 252 |
-
async def schedule_next_luck_opportunity(interaction:discord.Interaction,user id:int):
|
| 253 |
-
await asyncio.sleep(1800) # Wait for 30 minutes
|
| 254 |
-
luck_opportunities[user id]=luck_opportunities.get(user id,0)+1
|
| 255 |
-
increase_luck_button=discord.ui.Button(style=discord.ButtonStyle.success,label="Increase Luck",custom id=f"increase luck {luck opportunities[user id]}")
|
| 256 |
-
|
| 257 |
-
async def increase_luck_callback(interaction:discord.Interaction):
|
| 258 |
-
if interaction.user.id!=user id:
|
| 259 |
-
await interaction.response.send message("You cannot use this button.",ephemeral=True)
|
| 260 |
-
return
|
| 261 |
-
|
| 262 |
-
if user id in used luck opportunities and len(used luck opportunities[user id])>=4:
|
| 263 |
-
await interaction.response.send message("You have already used all your luck opportunities.",ephemeral=True)
|
| 264 |
-
return
|
| 265 |
|
| 266 |
-
|
| 267 |
-
new luck=min(current luck+1,10)
|
| 268 |
-
luck multipliers[user id]=new luck
|
| 269 |
-
luck expiration[user id]=time.time()+1800
|
| 270 |
-
|
| 271 |
-
if user id not in used luck opportunities:
|
| 272 |
-
used luck opportunities[user id]=set()
|
| 273 |
-
used luck opportunities[user id].add(luck opportunities[user id])
|
| 274 |
|
| 275 |
-
|
| 276 |
-
|
| 277 |
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
view.remove item(item)
|
| 282 |
-
break
|
| 283 |
-
await interaction.message.edit(view=view)
|
| 284 |
|
| 285 |
-
|
| 286 |
-
asyncio.create task(schedule next luck opportunity(interaction,user id))
|
| 287 |
|
| 288 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 289 |
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
|
|
|
| 301 |
|
| 302 |
-
|
| 303 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 304 |
|
| 305 |
@app_commands.command(name="petroll", description="Roll for a random pet")
|
| 306 |
async def petroll(interaction: discord.Interaction):
|
|
|
|
| 96 |
view = discord.ui.View()
|
| 97 |
view.add_item(roll_again_button)
|
| 98 |
|
| 99 |
+
sell_button = discord.ui.Button(style=discord.ButtonStyle.success, label=f"Sell Pet for ${rap_value}", custom_id="sell_pet")
|
| 100 |
+
|
| 101 |
+
async def sell_pet_callback(interaction: discord.Interaction):
|
| 102 |
+
if interaction.user.id != user_id:
|
| 103 |
+
await interaction.response.send_message("You cannot sell this pet.", ephemeral=True)
|
| 104 |
+
return
|
| 105 |
|
| 106 |
+
sell_value = rap_value
|
| 107 |
+
user_cash[user_id] = user_cash.get(user_id, 0) + sell_value
|
| 108 |
+
await interaction.response.send_message(f"You sold the pet for ${sell_value}. Your new balance is ${user_cash[user_id]}.", ephemeral=True)
|
| 109 |
+
for item in view.children:
|
| 110 |
+
if item.custom_id == "sell_pet":
|
| 111 |
+
view.remove_item(item)
|
| 112 |
+
break
|
| 113 |
+
await interaction.message.edit(view=view)
|
| 114 |
|
| 115 |
+
sell_button.callback = sell_pet_callback
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
+
# Add sell button only if auto-sell is not enabled
|
| 118 |
+
if user_id not in auto_sell_users:
|
| 119 |
view.add_item(sell_button)
|
| 120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
if user_id not in first_luck_claimed:
|
| 122 |
first_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Claim 100% Luck Forever", custom_id="first_luck")
|
| 123 |
|
|
|
|
| 221 |
auto_sell_button.style = discord.ButtonStyle.primary
|
| 222 |
auto_sell_button.label = "Auto Pet Sell"
|
| 223 |
await interaction.response.send_message("Auto pet sell stopped.", ephemeral=True)
|
| 224 |
+
# Re-add the sell button
|
| 225 |
+
view.add_item(sell_button)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
else:
|
| 227 |
auto_sell_users.add(user_id)
|
| 228 |
auto_sell_button.style = discord.ButtonStyle.danger
|
| 229 |
auto_sell_button.label = "Stop Auto Pet Sell"
|
| 230 |
+
await interaction.response.send_message("Auto pet sell started.", ephemeral=True)
|
| 231 |
+
# Remove the sell button to prevent manual selling
|
| 232 |
+
view.remove_item(sell_button)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
|
| 234 |
+
await interaction.message.edit(view=view)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
|
| 236 |
+
auto_sell_button.callback = auto_sell_callback
|
| 237 |
+
view.add_item(auto_sell_button)
|
| 238 |
|
| 239 |
+
if user_id in auto_sell_users:
|
| 240 |
+
user_cash[user_id] = user_cash.get(user_id, 0) + rap_value
|
| 241 |
+
embed.add_field(name="Auto Sell", value=f"Pet automatically sold for ${rap_value}. New balance: ${user_cash[user_id]}", inline=False)
|
|
|
|
|
|
|
|
|
|
| 242 |
|
| 243 |
+
return embed, view
|
|
|
|
| 244 |
|
| 245 |
+
async def schedule_next_luck_opportunity(interaction: discord.Interaction, user_id: int):
|
| 246 |
+
await asyncio.sleep(1800) # Wait for 30 minutes
|
| 247 |
+
luck_opportunities[user_id] = luck_opportunities.get(user_id, 0) + 1
|
| 248 |
+
increase_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Increase Luck", custom_id=f"increase_luck_{luck_opportunities[user_id]}")
|
| 249 |
+
|
| 250 |
+
async def increase_luck_callback(interaction: discord.Interaction):
|
| 251 |
+
if interaction.user.id != user_id:
|
| 252 |
+
await interaction.response.send_message("You cannot use this button.", ephemeral=True)
|
| 253 |
+
return
|
| 254 |
+
|
| 255 |
+
if user_id in used_luck_opportunities and len(used_luck_opportunities[user_id]) >= 4:
|
| 256 |
+
await interaction.response.send_message("You have already used all your luck opportunities.", ephemeral=True)
|
| 257 |
+
return
|
| 258 |
|
| 259 |
+
current_luck = luck_multipliers.get(user_id, 1)
|
| 260 |
+
new_luck = min(current_luck + 1, 10)
|
| 261 |
+
luck_multipliers[user_id] = new_luck
|
| 262 |
+
luck_expiration[user_id] = time.time() + 1800
|
| 263 |
+
|
| 264 |
+
if user_id not in used_luck_opportunities:
|
| 265 |
+
used_luck_opportunities[user_id] = set()
|
| 266 |
+
used_luck_opportunities[user_id].add(luck_opportunities[user_id])
|
| 267 |
+
|
| 268 |
+
luck_percentage = (new_luck - 1) * 100
|
| 269 |
+
await interaction.response.send_message(f"Your luck has been increased to {luck_percentage}% for 30 minutes!", ephemeral=True)
|
| 270 |
+
|
| 271 |
+
view = interaction.message.components[0]
|
| 272 |
+
for item in view.children:
|
| 273 |
+
if item.custom_id == interaction.custom_id:
|
| 274 |
+
view.remove_item(item)
|
| 275 |
+
break
|
| 276 |
+
await interaction.message.edit(view=view)
|
| 277 |
|
| 278 |
+
# Schedule the next luck opportunity
|
| 279 |
+
asyncio.create_task(schedule_next_luck_opportunity(interaction, user_id))
|
| 280 |
+
|
| 281 |
+
increase_luck_button.callback = increase_luck_callback
|
| 282 |
+
|
| 283 |
+
view = interaction.message.components[0]
|
| 284 |
+
view.add_item(increase_luck_button)
|
| 285 |
+
await interaction.message.edit(view=view)
|
| 286 |
|
| 287 |
+
async def auto_roll(interaction: discord.Interaction):
|
| 288 |
+
user_id = interaction.user.id
|
| 289 |
+
start_time = time.time()
|
| 290 |
+
while user_id in auto_roll_users:
|
| 291 |
+
if time.time() - start_time >= 180: # 3 minutes
|
| 292 |
+
auto_roll_users.remove(user_id)
|
| 293 |
+
await interaction.followup.send("Auto roll has been automatically stopped after 3 minutes. You can start it again if you wish.", ephemeral=True)
|
| 294 |
+
break
|
| 295 |
+
|
| 296 |
+
result = await perform_roll(interaction)
|
| 297 |
+
if result:
|
| 298 |
+
await interaction.followup.send(embed=result[0], view=result[1])
|
| 299 |
+
else:
|
| 300 |
+
await interaction.followup.send("An error occurred.")
|
| 301 |
+
await asyncio.sleep(5) # Wait for 5 seconds between rolls
|
| 302 |
|
| 303 |
@app_commands.command(name="petroll", description="Roll for a random pet")
|
| 304 |
async def petroll(interaction: discord.Interaction):
|