Spaces:
Paused
Paused
Update petroll.py
Browse files- petroll.py +76 -196
petroll.py
CHANGED
|
@@ -5,108 +5,14 @@ import random
|
|
| 5 |
import time
|
| 6 |
import asyncio
|
| 7 |
|
| 8 |
-
from cash import user_cash
|
| 9 |
|
| 10 |
-
# Dictionaries to manage user states
|
| 11 |
luck_multipliers = {}
|
| 12 |
luck_expiration = {}
|
| 13 |
luck_opportunities = {}
|
| 14 |
used_luck_opportunities = {}
|
| 15 |
first_luck_claimed = set()
|
| 16 |
auto_roll_users = set()
|
| 17 |
-
auto_sell_users = set()
|
| 18 |
-
|
| 19 |
-
class PetRollView(discord.ui.View):
|
| 20 |
-
def __init__(self, rap_value, user_id):
|
| 21 |
-
super().__init__(timeout=None)
|
| 22 |
-
self.rap_value = rap_value
|
| 23 |
-
self.user_id = user_id
|
| 24 |
-
self.pet_sold = False
|
| 25 |
-
self.auto_sell = False
|
| 26 |
-
|
| 27 |
-
# Add buttons
|
| 28 |
-
self.add_item(discord.ui.Button(style=discord.ButtonStyle.primary, label="Roll Again", custom_id="roll_again"))
|
| 29 |
-
self.add_item(discord.ui.Button(style=discord.ButtonStyle.success, label=f"Sell Pet for ${self.rap_value}", custom_id="sell_pet"))
|
| 30 |
-
self.add_item(discord.ui.Button(style=discord.ButtonStyle.primary, label="Auto Pet Sell", custom_id="auto_pet_sell"))
|
| 31 |
-
|
| 32 |
-
async def interaction_check(self, interaction: discord.Interaction) -> bool:
|
| 33 |
-
if interaction.user.id != self.user_id:
|
| 34 |
-
await interaction.response.send_message("You cannot interact with these buttons.", ephemeral=True)
|
| 35 |
-
return False
|
| 36 |
-
return True
|
| 37 |
-
|
| 38 |
-
@discord.ui.button(style=discord.ButtonStyle.primary, label="Roll Again", custom_id="roll_again")
|
| 39 |
-
async def roll_again_button(self, button: discord.ui.Button, interaction: discord.Interaction):
|
| 40 |
-
await interaction.response.defer()
|
| 41 |
-
result = await perform_roll(interaction)
|
| 42 |
-
if result:
|
| 43 |
-
await interaction.followup.send(embed=result[0], view=result[1])
|
| 44 |
-
else:
|
| 45 |
-
await interaction.followup.send("An error occurred.")
|
| 46 |
-
|
| 47 |
-
@discord.ui.button(style=discord.ButtonStyle.success, label="Sell Pet", custom_id="sell_pet")
|
| 48 |
-
async def sell_pet_button(self, button: discord.ui.Button, interaction: discord.Interaction):
|
| 49 |
-
if self.pet_sold:
|
| 50 |
-
await interaction.response.send_message("This pet has already been sold.", ephemeral=True)
|
| 51 |
-
return
|
| 52 |
-
|
| 53 |
-
sell_value = self.rap_value
|
| 54 |
-
user_cash[self.user_id] = user_cash.get(self.user_id, 0) + sell_value
|
| 55 |
-
self.pet_sold = True
|
| 56 |
-
await interaction.response.send_message(f"You sold the pet for ${sell_value}. Your new balance is ${user_cash[self.user_id]}.", ephemeral=True)
|
| 57 |
-
|
| 58 |
-
# Remove the sell button to prevent duplicate sales
|
| 59 |
-
self.sell_pet_button.disabled = True
|
| 60 |
-
self.sell_pet_button.label = "Sold"
|
| 61 |
-
await interaction.message.edit(view=self)
|
| 62 |
-
|
| 63 |
-
# If auto-sell is enabled, ensure it's disabled since the pet is already sold
|
| 64 |
-
if self.auto_sell:
|
| 65 |
-
self.auto_sell = False
|
| 66 |
-
self.auto_pet_sell_button.label = "Auto Pet Sell"
|
| 67 |
-
await interaction.message.edit(view=self)
|
| 68 |
-
|
| 69 |
-
@discord.ui.button(style=discord.ButtonStyle.primary, label="Auto Pet Sell", custom_id="auto_pet_sell")
|
| 70 |
-
async def auto_pet_sell_button(self, button: discord.ui.Button, interaction: discord.Interaction):
|
| 71 |
-
if self.auto_sell:
|
| 72 |
-
self.auto_sell = False
|
| 73 |
-
auto_sell_users.discard(self.user_id)
|
| 74 |
-
button.label = "Auto Pet Sell"
|
| 75 |
-
await interaction.response.send_message("Auto pet sell stopped.", ephemeral=True)
|
| 76 |
-
else:
|
| 77 |
-
if self.pet_sold:
|
| 78 |
-
await interaction.response.send_message("This pet has already been sold.", ephemeral=True)
|
| 79 |
-
return
|
| 80 |
-
self.auto_sell = True
|
| 81 |
-
auto_sell_users.add(self.user_id)
|
| 82 |
-
button.label = "Stop Auto Pet Sell"
|
| 83 |
-
await interaction.response.send_message("Auto pet sell started. You cannot manually sell pets while auto-sell is enabled.", ephemeral=True)
|
| 84 |
-
asyncio.create_task(auto_sell_process(interaction, self))
|
| 85 |
-
|
| 86 |
-
await interaction.message.edit(view=self)
|
| 87 |
-
|
| 88 |
-
async def auto_sell_process(interaction: discord.Interaction, view: PetRollView):
|
| 89 |
-
user_id = view.user_id
|
| 90 |
-
try:
|
| 91 |
-
while view.auto_sell and not view.pet_sold:
|
| 92 |
-
# Automatically sell the pet
|
| 93 |
-
sell_value = view.rap_value
|
| 94 |
-
user_cash[user_id] = user_cash.get(user_id, 0) + sell_value
|
| 95 |
-
view.pet_sold = True
|
| 96 |
-
await interaction.followup.send(f"Auto-sell: You sold the pet for ${sell_value}. Your new balance is ${user_cash[user_id]}.", ephemeral=True)
|
| 97 |
-
|
| 98 |
-
# Disable the sell button
|
| 99 |
-
view.sell_pet_button.disabled = True
|
| 100 |
-
view.sell_pet_button.label = "Sold"
|
| 101 |
-
# Disable auto-sell as the pet is already sold
|
| 102 |
-
view.auto_sell = False
|
| 103 |
-
view.auto_pet_sell_button.label = "Auto Pet Sell"
|
| 104 |
-
await interaction.message.edit(view=view)
|
| 105 |
-
break
|
| 106 |
-
|
| 107 |
-
# If you want auto-sell to handle multiple pets rolled, you can extend this logic
|
| 108 |
-
except Exception as e:
|
| 109 |
-
print(f"Auto-sell process encountered an error: {e}")
|
| 110 |
|
| 111 |
async def perform_roll(interaction: discord.Interaction):
|
| 112 |
async def fetch_data(url):
|
|
@@ -129,12 +35,12 @@ async def perform_roll(interaction: discord.Interaction):
|
|
| 129 |
|
| 130 |
user_id = interaction.user.id
|
| 131 |
luck_multiplier = luck_multipliers.get(user_id, 1)
|
| 132 |
-
|
| 133 |
sorted_pets = sorted(pets, key=lambda x: x['configData']['difficulty'])
|
| 134 |
-
|
| 135 |
max_index = len(sorted_pets) - 1
|
| 136 |
index = int(max_index * (luck_multiplier - 1) / 9)
|
| 137 |
-
|
| 138 |
rolled_pet = random.choice(sorted_pets[:index+1])
|
| 139 |
|
| 140 |
pet_rap = next((pet for pet in rap_data['data'] if pet['configData']['id'] == rolled_pet['configName']), None)
|
|
@@ -156,10 +62,15 @@ async def perform_roll(interaction: discord.Interaction):
|
|
| 156 |
else:
|
| 157 |
return f"{difficulty} ({difficulty:,})"
|
| 158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
embed = discord.Embed(title=f"{interaction.user.name} rolled: {rolled_pet['configData']['name']}", color=0x787878)
|
| 160 |
embed.add_field(name="Value", value=f"{rap_value:,} diamonds", inline=True)
|
| 161 |
embed.add_field(name="Difficulty", value=format_difficulty(rolled_pet['configData']['difficulty']), inline=True)
|
| 162 |
embed.add_field(name="Category", value=rolled_pet['category'], inline=True)
|
|
|
|
| 163 |
embed.set_thumbnail(url=thumbnail_url)
|
| 164 |
|
| 165 |
luck_text = ""
|
|
@@ -174,12 +85,22 @@ async def perform_roll(interaction: discord.Interaction):
|
|
| 174 |
|
| 175 |
embed.set_footer(text=f"Click 'Roll Again' to roll again!{luck_text}")
|
| 176 |
|
| 177 |
-
|
| 178 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
|
| 180 |
-
# Handle first luck claim
|
| 181 |
if user_id not in first_luck_claimed:
|
| 182 |
-
# Add the first luck button
|
| 183 |
first_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Claim 100% Luck Forever", custom_id="first_luck")
|
| 184 |
|
| 185 |
async def first_luck_callback(interaction: discord.Interaction):
|
|
@@ -192,15 +113,16 @@ async def perform_roll(interaction: discord.Interaction):
|
|
| 192 |
|
| 193 |
await interaction.response.send_message("You've claimed 100% luck forever!", ephemeral=True)
|
| 194 |
|
| 195 |
-
|
| 196 |
-
|
|
|
|
|
|
|
| 197 |
await interaction.message.edit(view=view)
|
| 198 |
|
| 199 |
first_luck_button.callback = first_luck_callback
|
| 200 |
view.add_item(first_luck_button)
|
| 201 |
|
| 202 |
elif random.random() < 0.6 or user_id not in luck_multipliers:
|
| 203 |
-
# Add the increase luck button
|
| 204 |
luck_opportunities[user_id] = luck_opportunities.get(user_id, 0) + 1
|
| 205 |
increase_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Increase Luck", custom_id=f"increase_luck_{luck_opportunities[user_id]}")
|
| 206 |
|
|
@@ -216,7 +138,7 @@ async def perform_roll(interaction: discord.Interaction):
|
|
| 216 |
current_luck = luck_multipliers.get(user_id, 1)
|
| 217 |
new_luck = min(current_luck + 1, 10)
|
| 218 |
luck_multipliers[user_id] = new_luck
|
| 219 |
-
luck_expiration[user_id] = time.time() + 1800
|
| 220 |
|
| 221 |
if user_id not in used_luck_opportunities:
|
| 222 |
used_luck_opportunities[user_id] = set()
|
|
@@ -225,8 +147,10 @@ async def perform_roll(interaction: discord.Interaction):
|
|
| 225 |
luck_percentage = (new_luck - 1) * 100
|
| 226 |
await interaction.response.send_message(f"Your luck has been increased to {luck_percentage}% for 30 minutes!", ephemeral=True)
|
| 227 |
|
| 228 |
-
|
| 229 |
-
|
|
|
|
|
|
|
| 230 |
await interaction.message.edit(view=view)
|
| 231 |
|
| 232 |
# Schedule the next luck opportunity
|
|
@@ -235,13 +159,46 @@ async def perform_roll(interaction: discord.Interaction):
|
|
| 235 |
increase_luck_button.callback = increase_luck_callback
|
| 236 |
view.add_item(increase_luck_button)
|
| 237 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
return embed, view
|
| 239 |
|
| 240 |
async def schedule_next_luck_opportunity(interaction: discord.Interaction, user_id: int):
|
| 241 |
await asyncio.sleep(1800) # Wait for 30 minutes
|
| 242 |
luck_opportunities[user_id] = luck_opportunities.get(user_id, 0) + 1
|
| 243 |
increase_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Increase Luck", custom_id=f"increase_luck_{luck_opportunities[user_id]}")
|
| 244 |
-
|
| 245 |
async def increase_luck_callback(interaction: discord.Interaction):
|
| 246 |
if interaction.user.id != user_id:
|
| 247 |
await interaction.response.send_message("You cannot use this button.", ephemeral=True)
|
|
@@ -254,7 +211,7 @@ async def schedule_next_luck_opportunity(interaction: discord.Interaction, user_
|
|
| 254 |
current_luck = luck_multipliers.get(user_id, 1)
|
| 255 |
new_luck = min(current_luck + 1, 10)
|
| 256 |
luck_multipliers[user_id] = new_luck
|
| 257 |
-
luck_expiration[user_id] = time.time() + 1800
|
| 258 |
|
| 259 |
if user_id not in used_luck_opportunities:
|
| 260 |
used_luck_opportunities[user_id] = set()
|
|
@@ -263,9 +220,11 @@ async def schedule_next_luck_opportunity(interaction: discord.Interaction, user_
|
|
| 263 |
luck_percentage = (new_luck - 1) * 100
|
| 264 |
await interaction.response.send_message(f"Your luck has been increased to {luck_percentage}% for 30 minutes!", ephemeral=True)
|
| 265 |
|
| 266 |
-
# Remove the increase luck button
|
| 267 |
view = interaction.message.components[0]
|
| 268 |
-
view.
|
|
|
|
|
|
|
|
|
|
| 269 |
await interaction.message.edit(view=view)
|
| 270 |
|
| 271 |
# Schedule the next luck opportunity
|
|
@@ -273,68 +232,9 @@ async def schedule_next_luck_opportunity(interaction: discord.Interaction, user_
|
|
| 273 |
|
| 274 |
increase_luck_button.callback = increase_luck_callback
|
| 275 |
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
message = interaction.message
|
| 280 |
-
view = PetRollView(rap_value=0, user_id=user_id) # rap_value is irrelevant here
|
| 281 |
-
view.remove_item(increase_luck_button)
|
| 282 |
-
view.add_item(increase_luck_button)
|
| 283 |
-
await message.edit(view=view)
|
| 284 |
-
except Exception as e:
|
| 285 |
-
print(f"Error scheduling next luck opportunity: {e}")
|
| 286 |
-
|
| 287 |
-
async def auto_sell_process_new_pet(interaction: discord.Interaction, view: PetRollView):
|
| 288 |
-
"""
|
| 289 |
-
This function handles auto-selling new pets rolled while auto-sell is enabled.
|
| 290 |
-
"""
|
| 291 |
-
user_id = view.user_id
|
| 292 |
-
sell_value = view.rap_value
|
| 293 |
-
|
| 294 |
-
if not view.pet_sold:
|
| 295 |
-
# Automatically sell the pet
|
| 296 |
-
user_cash[user_id] = user_cash.get(user_id, 0) + sell_value
|
| 297 |
-
view.pet_sold = True
|
| 298 |
-
await interaction.followup.send(f"Auto-sell: You sold the pet for ${sell_value}. Your new balance is ${user_cash[user_id]}.", ephemeral=True)
|
| 299 |
-
|
| 300 |
-
# Disable the sell button
|
| 301 |
-
view.sell_pet_button.disabled = True
|
| 302 |
-
view.sell_pet_button.label = "Sold"
|
| 303 |
-
|
| 304 |
-
# Disable auto-sell since the pet is already sold
|
| 305 |
-
view.auto_sell = False
|
| 306 |
-
view.auto_pet_sell_button.label = "Auto Pet Sell"
|
| 307 |
-
await interaction.message.edit(view=view)
|
| 308 |
-
|
| 309 |
-
# Notify the user
|
| 310 |
-
await interaction.followup.send("Auto-sell has been disabled since the pet was automatically sold.", ephemeral=True)
|
| 311 |
-
|
| 312 |
-
async def auto_sell(interaction: discord.Interaction, view: PetRollView):
|
| 313 |
-
"""
|
| 314 |
-
This coroutine handles continuous auto-selling while auto-sell is enabled.
|
| 315 |
-
"""
|
| 316 |
-
user_id = view.user_id
|
| 317 |
-
while view.auto_sell and not view.pet_sold:
|
| 318 |
-
# Automatically sell the pet
|
| 319 |
-
sell_value = view.rap_value
|
| 320 |
-
user_cash[user_id] = user_cash.get(user_id, 0) + sell_value
|
| 321 |
-
view.pet_sold = True
|
| 322 |
-
await interaction.followup.send(f"Auto-sell: You sold the pet for ${sell_value}. Your new balance is ${user_cash[user_id]}.", ephemeral=True)
|
| 323 |
-
|
| 324 |
-
# Disable the sell button
|
| 325 |
-
view.sell_pet_button.disabled = True
|
| 326 |
-
view.sell_pet_button.label = "Sold"
|
| 327 |
-
|
| 328 |
-
# Disable auto-sell since the pet is already sold
|
| 329 |
-
view.auto_sell = False
|
| 330 |
-
view.auto_pet_sell_button.label = "Auto Pet Sell"
|
| 331 |
-
await interaction.message.edit(view=view)
|
| 332 |
-
|
| 333 |
-
# Notify the user
|
| 334 |
-
await interaction.followup.send("Auto-sell has been disabled since the pet was automatically sold.", ephemeral=True)
|
| 335 |
-
break # Exit the loop since the pet is sold
|
| 336 |
-
|
| 337 |
-
# If you want auto-sell to handle multiple pets rolled over time, remove the break and implement additional logic
|
| 338 |
|
| 339 |
async def auto_roll(interaction: discord.Interaction):
|
| 340 |
user_id = interaction.user.id
|
|
@@ -342,32 +242,12 @@ async def auto_roll(interaction: discord.Interaction):
|
|
| 342 |
while user_id in auto_roll_users:
|
| 343 |
if time.time() - start_time >= 180: # 3 minutes
|
| 344 |
auto_roll_users.remove(user_id)
|
| 345 |
-
await interaction.followup.send("
|
| 346 |
break
|
| 347 |
|
| 348 |
result = await perform_roll(interaction)
|
| 349 |
if result:
|
| 350 |
-
embed, view
|
| 351 |
-
# If auto-sell is enabled, automatically sell the pet
|
| 352 |
-
if user_id in auto_sell_users:
|
| 353 |
-
# Wait briefly to ensure the message is sent before auto-selling
|
| 354 |
-
await asyncio.sleep(1)
|
| 355 |
-
# Automatically sell the pet
|
| 356 |
-
sell_value = view.rap_value
|
| 357 |
-
user_cash[user_id] = user_cash.get(user_id, 0) + sell_value
|
| 358 |
-
view.pet_sold = True
|
| 359 |
-
await interaction.followup.send(f"Auto-sell: You sold the pet for ${sell_value}. Your new balance is ${user_cash[user_id]}.", ephemeral=True)
|
| 360 |
-
|
| 361 |
-
# Disable the sell button
|
| 362 |
-
view.sell_pet_button.disabled = True
|
| 363 |
-
view.sell_pet_button.label = "Sold"
|
| 364 |
-
|
| 365 |
-
# Disable auto-sell since the pet is already sold
|
| 366 |
-
view.auto_sell = False
|
| 367 |
-
view.auto_pet_sell_button.label = "Auto Pet Sell"
|
| 368 |
-
await interaction.message.edit(view=view)
|
| 369 |
-
|
| 370 |
-
await interaction.followup.send(embed=embed, view=view)
|
| 371 |
else:
|
| 372 |
await interaction.followup.send("An error occurred.")
|
| 373 |
await asyncio.sleep(5) # Wait for 5 seconds between rolls
|
|
|
|
| 5 |
import time
|
| 6 |
import asyncio
|
| 7 |
|
| 8 |
+
from cash import user_cash
|
| 9 |
|
|
|
|
| 10 |
luck_multipliers = {}
|
| 11 |
luck_expiration = {}
|
| 12 |
luck_opportunities = {}
|
| 13 |
used_luck_opportunities = {}
|
| 14 |
first_luck_claimed = set()
|
| 15 |
auto_roll_users = set()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
async def perform_roll(interaction: discord.Interaction):
|
| 18 |
async def fetch_data(url):
|
|
|
|
| 35 |
|
| 36 |
user_id = interaction.user.id
|
| 37 |
luck_multiplier = luck_multipliers.get(user_id, 1)
|
| 38 |
+
|
| 39 |
sorted_pets = sorted(pets, key=lambda x: x['configData']['difficulty'])
|
| 40 |
+
|
| 41 |
max_index = len(sorted_pets) - 1
|
| 42 |
index = int(max_index * (luck_multiplier - 1) / 9)
|
| 43 |
+
|
| 44 |
rolled_pet = random.choice(sorted_pets[:index+1])
|
| 45 |
|
| 46 |
pet_rap = next((pet for pet in rap_data['data'] if pet['configData']['id'] == rolled_pet['configName']), None)
|
|
|
|
| 62 |
else:
|
| 63 |
return f"{difficulty} ({difficulty:,})"
|
| 64 |
|
| 65 |
+
# Automatically sell the pet
|
| 66 |
+
sell_value = rap_value
|
| 67 |
+
user_cash[user_id] = user_cash.get(user_id, 0) + sell_value
|
| 68 |
+
|
| 69 |
embed = discord.Embed(title=f"{interaction.user.name} rolled: {rolled_pet['configData']['name']}", color=0x787878)
|
| 70 |
embed.add_field(name="Value", value=f"{rap_value:,} diamonds", inline=True)
|
| 71 |
embed.add_field(name="Difficulty", value=format_difficulty(rolled_pet['configData']['difficulty']), inline=True)
|
| 72 |
embed.add_field(name="Category", value=rolled_pet['category'], inline=True)
|
| 73 |
+
embed.add_field(name="Sold For", value=f"${sell_value:,}", inline=True)
|
| 74 |
embed.set_thumbnail(url=thumbnail_url)
|
| 75 |
|
| 76 |
luck_text = ""
|
|
|
|
| 85 |
|
| 86 |
embed.set_footer(text=f"Click 'Roll Again' to roll again!{luck_text}")
|
| 87 |
|
| 88 |
+
roll_again_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Roll Again", custom_id="roll_again")
|
| 89 |
+
|
| 90 |
+
async def roll_again_callback(interaction: discord.Interaction):
|
| 91 |
+
await interaction.response.defer()
|
| 92 |
+
result = await perform_roll(interaction)
|
| 93 |
+
if result:
|
| 94 |
+
await interaction.followup.send(embed=result[0], view=result[1])
|
| 95 |
+
else:
|
| 96 |
+
await interaction.followup.send("An error occurred.")
|
| 97 |
+
|
| 98 |
+
roll_again_button.callback = roll_again_callback
|
| 99 |
+
|
| 100 |
+
view = discord.ui.View()
|
| 101 |
+
view.add_item(roll_again_button)
|
| 102 |
|
|
|
|
| 103 |
if user_id not in first_luck_claimed:
|
|
|
|
| 104 |
first_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Claim 100% Luck Forever", custom_id="first_luck")
|
| 105 |
|
| 106 |
async def first_luck_callback(interaction: discord.Interaction):
|
|
|
|
| 113 |
|
| 114 |
await interaction.response.send_message("You've claimed 100% luck forever!", ephemeral=True)
|
| 115 |
|
| 116 |
+
for item in view.children:
|
| 117 |
+
if item.custom_id == "first_luck":
|
| 118 |
+
view.remove_item(item)
|
| 119 |
+
break
|
| 120 |
await interaction.message.edit(view=view)
|
| 121 |
|
| 122 |
first_luck_button.callback = first_luck_callback
|
| 123 |
view.add_item(first_luck_button)
|
| 124 |
|
| 125 |
elif random.random() < 0.6 or user_id not in luck_multipliers:
|
|
|
|
| 126 |
luck_opportunities[user_id] = luck_opportunities.get(user_id, 0) + 1
|
| 127 |
increase_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Increase Luck", custom_id=f"increase_luck_{luck_opportunities[user_id]}")
|
| 128 |
|
|
|
|
| 138 |
current_luck = luck_multipliers.get(user_id, 1)
|
| 139 |
new_luck = min(current_luck + 1, 10)
|
| 140 |
luck_multipliers[user_id] = new_luck
|
| 141 |
+
luck_expiration[user_id] = time.time() + 1800
|
| 142 |
|
| 143 |
if user_id not in used_luck_opportunities:
|
| 144 |
used_luck_opportunities[user_id] = set()
|
|
|
|
| 147 |
luck_percentage = (new_luck - 1) * 100
|
| 148 |
await interaction.response.send_message(f"Your luck has been increased to {luck_percentage}% for 30 minutes!", ephemeral=True)
|
| 149 |
|
| 150 |
+
for item in view.children:
|
| 151 |
+
if item.custom_id == interaction.custom_id:
|
| 152 |
+
view.remove_item(item)
|
| 153 |
+
break
|
| 154 |
await interaction.message.edit(view=view)
|
| 155 |
|
| 156 |
# Schedule the next luck opportunity
|
|
|
|
| 159 |
increase_luck_button.callback = increase_luck_callback
|
| 160 |
view.add_item(increase_luck_button)
|
| 161 |
|
| 162 |
+
auto_roll_button = discord.ui.Button(
|
| 163 |
+
style=discord.ButtonStyle.primary if user_id not in auto_roll_users else discord.ButtonStyle.danger,
|
| 164 |
+
label="Auto Roll" if user_id not in auto_roll_users else "Stop Auto Roll",
|
| 165 |
+
custom_id="auto_roll"
|
| 166 |
+
)
|
| 167 |
+
|
| 168 |
+
async def auto_roll_callback(interaction: discord.Interaction):
|
| 169 |
+
if interaction.user.id != user_id:
|
| 170 |
+
await interaction.response.send_message("You cannot use this button.", ephemeral=True)
|
| 171 |
+
return
|
| 172 |
+
|
| 173 |
+
if user_id in auto_roll_users:
|
| 174 |
+
auto_roll_users.remove(user_id)
|
| 175 |
+
auto_roll_button.style = discord.ButtonStyle.primary
|
| 176 |
+
auto_roll_button.label = "Auto Roll"
|
| 177 |
+
await interaction.response.send_message("Auto roll stopped.", ephemeral=True)
|
| 178 |
+
else:
|
| 179 |
+
auto_roll_users.add(user_id)
|
| 180 |
+
auto_roll_button.style = discord.ButtonStyle.danger
|
| 181 |
+
auto_roll_button.label = "Stop Auto Roll"
|
| 182 |
+
await interaction.response.send_message("Auto roll started. It will automatically stop after 3 minutes.", ephemeral=True)
|
| 183 |
+
asyncio.create_task(auto_roll(interaction))
|
| 184 |
+
|
| 185 |
+
await interaction.message.edit(view=view)
|
| 186 |
+
|
| 187 |
+
auto_roll_button.callback = auto_roll_callback
|
| 188 |
+
view.add_item(auto_roll_button)
|
| 189 |
+
|
| 190 |
+
# Auto Sell is now default and always active
|
| 191 |
+
sell_value = rap_value
|
| 192 |
+
user_cash[user_id] = user_cash.get(user_id, 0) + sell_value
|
| 193 |
+
embed.add_field(name="Auto Sell", value=f"Pet automatically sold for ${sell_value:,}. New balance: ${user_cash[user_id]:,}", inline=False)
|
| 194 |
+
|
| 195 |
return embed, view
|
| 196 |
|
| 197 |
async def schedule_next_luck_opportunity(interaction: discord.Interaction, user_id: int):
|
| 198 |
await asyncio.sleep(1800) # Wait for 30 minutes
|
| 199 |
luck_opportunities[user_id] = luck_opportunities.get(user_id, 0) + 1
|
| 200 |
increase_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Increase Luck", custom_id=f"increase_luck_{luck_opportunities[user_id]}")
|
| 201 |
+
|
| 202 |
async def increase_luck_callback(interaction: discord.Interaction):
|
| 203 |
if interaction.user.id != user_id:
|
| 204 |
await interaction.response.send_message("You cannot use this button.", ephemeral=True)
|
|
|
|
| 211 |
current_luck = luck_multipliers.get(user_id, 1)
|
| 212 |
new_luck = min(current_luck + 1, 10)
|
| 213 |
luck_multipliers[user_id] = new_luck
|
| 214 |
+
luck_expiration[user_id] = time.time() + 1800
|
| 215 |
|
| 216 |
if user_id not in used_luck_opportunities:
|
| 217 |
used_luck_opportunities[user_id] = set()
|
|
|
|
| 220 |
luck_percentage = (new_luck - 1) * 100
|
| 221 |
await interaction.response.send_message(f"Your luck has been increased to {luck_percentage}% for 30 minutes!", ephemeral=True)
|
| 222 |
|
|
|
|
| 223 |
view = interaction.message.components[0]
|
| 224 |
+
for item in view.children:
|
| 225 |
+
if item.custom_id == interaction.custom_id:
|
| 226 |
+
view.remove_item(item)
|
| 227 |
+
break
|
| 228 |
await interaction.message.edit(view=view)
|
| 229 |
|
| 230 |
# Schedule the next luck opportunity
|
|
|
|
| 232 |
|
| 233 |
increase_luck_button.callback = increase_luck_callback
|
| 234 |
|
| 235 |
+
view = interaction.message.components[0]
|
| 236 |
+
view.add_item(increase_luck_button)
|
| 237 |
+
await interaction.message.edit(view=view)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
|
| 239 |
async def auto_roll(interaction: discord.Interaction):
|
| 240 |
user_id = interaction.user.id
|
|
|
|
| 242 |
while user_id in auto_roll_users:
|
| 243 |
if time.time() - start_time >= 180: # 3 minutes
|
| 244 |
auto_roll_users.remove(user_id)
|
| 245 |
+
await interaction.followup.send("autoroll stopped, to turn on again, roll and turn it on", ephemeral=True)
|
| 246 |
break
|
| 247 |
|
| 248 |
result = await perform_roll(interaction)
|
| 249 |
if result:
|
| 250 |
+
await interaction.followup.send(embed=result[0], view=result[1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
else:
|
| 252 |
await interaction.followup.send("An error occurred.")
|
| 253 |
await asyncio.sleep(5) # Wait for 5 seconds between rolls
|