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