Spaces:
Paused
Paused
Update petroll.py
Browse files- petroll.py +15 -186
petroll.py
CHANGED
|
@@ -3,28 +3,12 @@ from discord import app_commands
|
|
| 3 |
import aiohttp
|
| 4 |
import random
|
| 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 = set()
|
| 14 |
-
first_luck_claimed = set()
|
| 15 |
-
|
| 16 |
-
# Cache for pet data
|
| 17 |
-
pet_cache = None
|
| 18 |
-
pet_cache_expiry = 0
|
| 19 |
-
CACHE_DURATION = 300 # 5 minutes
|
| 20 |
-
|
| 21 |
-
async def fetch_and_process_pets():
|
| 22 |
-
global pet_cache, pet_cache_expiry
|
| 23 |
-
|
| 24 |
-
current_time = time.time()
|
| 25 |
-
if pet_cache and current_time < pet_cache_expiry:
|
| 26 |
-
return pet_cache
|
| 27 |
|
|
|
|
| 28 |
async def fetch_data(url):
|
| 29 |
async with aiohttp.ClientSession() as session:
|
| 30 |
async with session.get(url) as response:
|
|
@@ -32,10 +16,8 @@ async def fetch_and_process_pets():
|
|
| 32 |
return await response.json()
|
| 33 |
return None
|
| 34 |
|
| 35 |
-
rap_data
|
| 36 |
-
|
| 37 |
-
fetch_data("https://petsgo.biggamesapi.io/api/collection/Pets")
|
| 38 |
-
)
|
| 39 |
|
| 40 |
if not rap_data or not collection_data:
|
| 41 |
return None
|
|
@@ -45,49 +27,15 @@ async def fetch_and_process_pets():
|
|
| 45 |
if not pets:
|
| 46 |
return None
|
| 47 |
|
| 48 |
-
# Sort pets by difficulty (rarity)
|
| 49 |
-
sorted_pets = sorted(pets, key=lambda x: x['configData']['difficulty'])
|
| 50 |
-
|
| 51 |
-
# Divide pets into tiers
|
| 52 |
-
tier_size = len(sorted_pets) // 5
|
| 53 |
-
tiers = [sorted_pets[i:i+tier_size] for i in range(0, len(sorted_pets), tier_size)]
|
| 54 |
-
|
| 55 |
-
pet_cache = {
|
| 56 |
-
'tiers': tiers,
|
| 57 |
-
'rap_data': rap_data
|
| 58 |
-
}
|
| 59 |
-
pet_cache_expiry = current_time + CACHE_DURATION
|
| 60 |
-
return pet_cache
|
| 61 |
-
|
| 62 |
-
async def perform_roll(interaction: discord.Interaction):
|
| 63 |
-
pet_data = await fetch_and_process_pets()
|
| 64 |
-
if not pet_data:
|
| 65 |
-
return None
|
| 66 |
-
|
| 67 |
-
tiers = pet_data['tiers']
|
| 68 |
-
rap_data = pet_data['rap_data']
|
| 69 |
-
|
| 70 |
user_id = interaction.user.id
|
| 71 |
luck_multiplier = luck_multipliers.get(user_id, 1)
|
| 72 |
|
| 73 |
-
|
| 74 |
-
tier_probabilities = [0.5, 0.25, 0.15, 0.07, 0.03]
|
| 75 |
-
luck_boost = (luck_multiplier - 1) * 0.1 # 10% boost per luck level
|
| 76 |
-
for i in range(len(tier_probabilities)):
|
| 77 |
-
if i < len(tier_probabilities) - 1:
|
| 78 |
-
tier_probabilities[i] -= luck_boost
|
| 79 |
-
tier_probabilities[i+1] += luck_boost
|
| 80 |
-
|
| 81 |
-
# Ensure probabilities are non-negative and sum to 1
|
| 82 |
-
tier_probabilities = [max(0, p) for p in tier_probabilities]
|
| 83 |
-
total = sum(tier_probabilities)
|
| 84 |
-
tier_probabilities = [p / total for p in tier_probabilities]
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
| 88 |
|
| 89 |
-
|
| 90 |
-
rolled_pet = random.choice(selected_tier)
|
| 91 |
|
| 92 |
pet_rap = next((pet for pet in rap_data['data'] if pet['configData']['id'] == rolled_pet['configName']), None)
|
| 93 |
|
|
@@ -109,16 +57,16 @@ async def perform_roll(interaction: discord.Interaction):
|
|
| 109 |
return f"{difficulty} ({difficulty:,})"
|
| 110 |
|
| 111 |
embed = discord.Embed(title=f"{interaction.user.name} rolled: {rolled_pet['configData']['name']}", color=0x787878)
|
| 112 |
-
embed.add_field(name="
|
| 113 |
-
embed.add_field(name="
|
| 114 |
-
embed.add_field(name="
|
| 115 |
embed.set_thumbnail(url=thumbnail_url)
|
| 116 |
|
| 117 |
luck_text = ""
|
| 118 |
if user_id in luck_expiration:
|
| 119 |
remaining_time = int(luck_expiration[user_id] - time.time())
|
| 120 |
if remaining_time > 0:
|
| 121 |
-
luck_percentage = (luck_multiplier - 1) *
|
| 122 |
luck_text = f"\nYou have {remaining_time // 60} minutes and {remaining_time % 60} seconds of luck left! ({luck_percentage}% luck)"
|
| 123 |
else:
|
| 124 |
del luck_multipliers[user_id]
|
|
@@ -141,48 +89,7 @@ async def perform_roll(interaction: discord.Interaction):
|
|
| 141 |
view = discord.ui.View()
|
| 142 |
view.add_item(roll_again_button)
|
| 143 |
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
async def sell_pet_callback(interaction: discord.Interaction):
|
| 147 |
-
if interaction.user.id != user_id:
|
| 148 |
-
await interaction.response.send_message("You cannot sell this pet.", ephemeral=True)
|
| 149 |
-
return
|
| 150 |
-
|
| 151 |
-
sell_value = rap_value
|
| 152 |
-
user_cash[user_id] = user_cash.get(user_id, 0) + sell_value
|
| 153 |
-
await interaction.response.send_message(f"You sold the pet for ${sell_value}. Your new balance is ${user_cash[user_id]}.", ephemeral=True)
|
| 154 |
-
for item in view.children:
|
| 155 |
-
if item.custom_id == "sell_pet":
|
| 156 |
-
view.remove_item(item)
|
| 157 |
-
break
|
| 158 |
-
await interaction.message.edit(view=view)
|
| 159 |
-
|
| 160 |
-
sell_button.callback = sell_pet_callback
|
| 161 |
-
view.add_item(sell_button)
|
| 162 |
-
|
| 163 |
-
if user_id not in first_luck_claimed:
|
| 164 |
-
first_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Claim 10% Luck Forever", custom_id="first_luck")
|
| 165 |
-
|
| 166 |
-
async def first_luck_callback(interaction: discord.Interaction):
|
| 167 |
-
if interaction.user.id != user_id:
|
| 168 |
-
await interaction.response.send_message("You cannot use this button.", ephemeral=True)
|
| 169 |
-
return
|
| 170 |
-
|
| 171 |
-
luck_multipliers[user_id] = 2 # 10% luck
|
| 172 |
-
first_luck_claimed.add(user_id)
|
| 173 |
-
|
| 174 |
-
await interaction.response.send_message("You've claimed 10% luck forever!", ephemeral=True)
|
| 175 |
-
|
| 176 |
-
for item in view.children:
|
| 177 |
-
if item.custom_id == "first_luck":
|
| 178 |
-
view.remove_item(item)
|
| 179 |
-
break
|
| 180 |
-
await interaction.message.edit(view=view)
|
| 181 |
-
|
| 182 |
-
first_luck_button.callback = first_luck_callback
|
| 183 |
-
view.add_item(first_luck_button)
|
| 184 |
-
|
| 185 |
-
elif random.random() < 0.6 and luck_opportunities.get(user_id, 0) < 4:
|
| 186 |
luck_opportunities[user_id] = luck_opportunities.get(user_id, 0) + 1
|
| 187 |
increase_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Increase Luck", custom_id=f"increase_luck_{luck_opportunities[user_id]}")
|
| 188 |
|
|
@@ -191,21 +98,13 @@ async def perform_roll(interaction: discord.Interaction):
|
|
| 191 |
await interaction.response.send_message("You cannot use this button.", ephemeral=True)
|
| 192 |
return
|
| 193 |
|
| 194 |
-
if user_id in used_luck_opportunities and len(used_luck_opportunities[user_id]) >= 4:
|
| 195 |
-
await interaction.response.send_message("You have already used all your luck opportunities.", ephemeral=True)
|
| 196 |
-
return
|
| 197 |
-
|
| 198 |
current_luck = luck_multipliers.get(user_id, 1)
|
| 199 |
-
new_luck = min(current_luck +
|
| 200 |
luck_multipliers[user_id] = new_luck
|
| 201 |
luck_expiration[user_id] = time.time() + 1800
|
| 202 |
|
| 203 |
-
if user_id not in used_luck_opportunities:
|
| 204 |
-
used_luck_opportunities[user_id] = set()
|
| 205 |
-
used_luck_opportunities[user_id].add(luck_opportunities[user_id])
|
| 206 |
-
|
| 207 |
luck_percentage = (new_luck - 1) * 100
|
| 208 |
-
await interaction.response.send_message(f"Your luck has been increased to {luck_percentage
|
| 209 |
|
| 210 |
for item in view.children:
|
| 211 |
if item.custom_id == interaction.custom_id:
|
|
@@ -225,74 +124,4 @@ async def petroll(interaction: discord.Interaction):
|
|
| 225 |
if result:
|
| 226 |
await interaction.followup.send(embed=result[0], view=result[1])
|
| 227 |
else:
|
| 228 |
-
await interaction.followup.send("
|
| 229 |
-
|
| 230 |
-
@app_commands.command(name="balance", description="Check your current balance")
|
| 231 |
-
async def balance(interaction: discord.Interaction):
|
| 232 |
-
user_id = interaction.user.id
|
| 233 |
-
current_balance = user_cash.get(user_id, 0)
|
| 234 |
-
await interaction.response.send_message(f"Your current balance is ${current_balance}.", ephemeral=True)
|
| 235 |
-
|
| 236 |
-
@app_commands.command(name="dice", description="Roll the dice and bet")
|
| 237 |
-
async def dice(interaction: discord.Interaction, bet: int):
|
| 238 |
-
await roll_dice(interaction, bet)
|
| 239 |
-
|
| 240 |
-
async def roll_dice(interaction: discord.Interaction, bet: int):
|
| 241 |
-
user_id = interaction.user.id
|
| 242 |
-
balance = user_cash.get(user_id, 0)
|
| 243 |
-
|
| 244 |
-
if bet <= 0:
|
| 245 |
-
await interaction.response.send_message("Bet Higher than 0 Idiot.")
|
| 246 |
-
return
|
| 247 |
-
|
| 248 |
-
if bet > balance:
|
| 249 |
-
await interaction.response.send_message(f"You don't have enough cash. Your current balance is ${balance:.2f}")
|
| 250 |
-
return
|
| 251 |
-
|
| 252 |
-
embed = discord.Embed(title="Dice Roll", description=f"{interaction.user.name} is betting ${bet:.2f}", color=0x787878)
|
| 253 |
-
embed.add_field(name="Current Balance", value=f"${balance:.2f}", inline=False)
|
| 254 |
-
|
| 255 |
-
roll_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Roll the Dice", custom_id="roll_dice")
|
| 256 |
-
|
| 257 |
-
async def roll_dice_callback(interaction: discord.Interaction):
|
| 258 |
-
nonlocal balance
|
| 259 |
-
result = random.choice(["win", "lose"])
|
| 260 |
-
|
| 261 |
-
if result == "win":
|
| 262 |
-
winnings = bet
|
| 263 |
-
balance += winnings
|
| 264 |
-
result_text = f"You won ${winnings:.2f}!"
|
| 265 |
-
else:
|
| 266 |
-
balance -= bet
|
| 267 |
-
result_text = f"You lost ${bet:.2f}."
|
| 268 |
-
|
| 269 |
-
user_cash[user_id] = balance
|
| 270 |
-
|
| 271 |
-
embed.clear_fields()
|
| 272 |
-
embed.add_field(name="Result", value=result_text, inline=False)
|
| 273 |
-
embed.add_field(name="New Balance", value=f"${balance:.2f}", inline=False)
|
| 274 |
-
|
| 275 |
-
roll_again_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Roll Again", custom_id="roll_again")
|
| 276 |
-
|
| 277 |
-
async def roll_again_callback(interaction: discord.Interaction):
|
| 278 |
-
if interaction.user.id == user_id:
|
| 279 |
-
await roll_dice(interaction, bet)
|
| 280 |
-
else:
|
| 281 |
-
await interaction.response.send_message("you cant roll this", ephemeral=True)
|
| 282 |
-
|
| 283 |
-
roll_again_button.callback = roll_again_callback
|
| 284 |
-
|
| 285 |
-
new_view = discord.ui.View()
|
| 286 |
-
new_view.add_item(roll_again_button)
|
| 287 |
-
|
| 288 |
-
await interaction.response.edit_message(embed=embed, view=new_view)
|
| 289 |
-
|
| 290 |
-
roll_button.callback = roll_dice_callback
|
| 291 |
-
|
| 292 |
-
view = discord.ui.View()
|
| 293 |
-
view.add_item(roll_button)
|
| 294 |
-
|
| 295 |
-
if interaction.response.is_done():
|
| 296 |
-
await interaction.followup.send(embed=embed, view=view)
|
| 297 |
-
else:
|
| 298 |
-
await interaction.response.send_message(embed=embed, view=view)
|
|
|
|
| 3 |
import aiohttp
|
| 4 |
import random
|
| 5 |
import time
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
luck_multipliers = {}
|
| 8 |
luck_expiration = {}
|
| 9 |
luck_opportunities = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
async def perform_roll(interaction: discord.Interaction):
|
| 12 |
async def fetch_data(url):
|
| 13 |
async with aiohttp.ClientSession() as session:
|
| 14 |
async with session.get(url) as response:
|
|
|
|
| 16 |
return await response.json()
|
| 17 |
return None
|
| 18 |
|
| 19 |
+
rap_data = await fetch_data("https://petsgo.biggamesapi.io/api/Rap")
|
| 20 |
+
collection_data = await fetch_data("https://petsgo.biggamesapi.io/api/collection/Pets")
|
|
|
|
|
|
|
| 21 |
|
| 22 |
if not rap_data or not collection_data:
|
| 23 |
return None
|
|
|
|
| 27 |
if not pets:
|
| 28 |
return None
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
user_id = interaction.user.id
|
| 31 |
luck_multiplier = luck_multipliers.get(user_id, 1)
|
| 32 |
|
| 33 |
+
sorted_pets = sorted(pets, key=lambda x: x['configData']['difficulty'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
max_index = len(sorted_pets) - 1
|
| 36 |
+
index = int(max_index * (luck_multiplier - 1) / 9)
|
| 37 |
|
| 38 |
+
rolled_pet = random.choice(sorted_pets[:index+1])
|
|
|
|
| 39 |
|
| 40 |
pet_rap = next((pet for pet in rap_data['data'] if pet['configData']['id'] == rolled_pet['configName']), None)
|
| 41 |
|
|
|
|
| 57 |
return f"{difficulty} ({difficulty:,})"
|
| 58 |
|
| 59 |
embed = discord.Embed(title=f"{interaction.user.name} rolled: {rolled_pet['configData']['name']}", color=0x787878)
|
| 60 |
+
embed.add_field(name="value", value=f"{rap_value:,} diamonds", inline=True)
|
| 61 |
+
embed.add_field(name="difficulty", value=format_difficulty(rolled_pet['configData']['difficulty']), inline=True)
|
| 62 |
+
embed.add_field(name="category", value=rolled_pet['category'], inline=True)
|
| 63 |
embed.set_thumbnail(url=thumbnail_url)
|
| 64 |
|
| 65 |
luck_text = ""
|
| 66 |
if user_id in luck_expiration:
|
| 67 |
remaining_time = int(luck_expiration[user_id] - time.time())
|
| 68 |
if remaining_time > 0:
|
| 69 |
+
luck_percentage = (luck_multiplier - 1) * 100
|
| 70 |
luck_text = f"\nYou have {remaining_time // 60} minutes and {remaining_time % 60} seconds of luck left! ({luck_percentage}% luck)"
|
| 71 |
else:
|
| 72 |
del luck_multipliers[user_id]
|
|
|
|
| 89 |
view = discord.ui.View()
|
| 90 |
view.add_item(roll_again_button)
|
| 91 |
|
| 92 |
+
if random.random() < 0.2:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
luck_opportunities[user_id] = luck_opportunities.get(user_id, 0) + 1
|
| 94 |
increase_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Increase Luck", custom_id=f"increase_luck_{luck_opportunities[user_id]}")
|
| 95 |
|
|
|
|
| 98 |
await interaction.response.send_message("You cannot use this button.", ephemeral=True)
|
| 99 |
return
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
current_luck = luck_multipliers.get(user_id, 1)
|
| 102 |
+
new_luck = min(current_luck + 1, 10)
|
| 103 |
luck_multipliers[user_id] = new_luck
|
| 104 |
luck_expiration[user_id] = time.time() + 1800
|
| 105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
luck_percentage = (new_luck - 1) * 100
|
| 107 |
+
await interaction.response.send_message(f"Your luck has been increased to {luck_percentage}% for 30 minutes!", ephemeral=True)
|
| 108 |
|
| 109 |
for item in view.children:
|
| 110 |
if item.custom_id == interaction.custom_id:
|
|
|
|
| 124 |
if result:
|
| 125 |
await interaction.followup.send(embed=result[0], view=result[1])
|
| 126 |
else:
|
| 127 |
+
await interaction.followup.send("errer")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|