Spaces:
Building
Building
Update app.py
Browse files
app.py
CHANGED
@@ -15,7 +15,7 @@ tree = app_commands.CommandTree(bot)
|
|
15 |
async def read_root():
|
16 |
return {"Hello": "World"}
|
17 |
|
18 |
-
@tree.command(name="petsimgo", description="
|
19 |
async def petsimgo(interaction: discord.Interaction, petname: str):
|
20 |
await interaction.response.defer()
|
21 |
|
@@ -26,26 +26,42 @@ async def petsimgo(interaction: discord.Interaction, petname: str):
|
|
26 |
return await response.json()
|
27 |
return None
|
28 |
|
29 |
-
exists_data = await fetch_data("https://petsgo.biggamesapi.io/api/exists")
|
30 |
-
rap_data = await fetch_data("https://petsgo.biggamesapi.io/api/Rap")
|
31 |
collection_data = await fetch_data("https://petsgo.biggamesapi.io/api/collection/Pets")
|
32 |
|
33 |
-
if not
|
34 |
await interaction.followup.send("errer")
|
35 |
return
|
36 |
|
37 |
-
|
38 |
-
pet_rap = next((pet for pet in rap_data['data'] if pet['configData']['id'].lower() == petname.lower()), None)
|
39 |
-
pet_info = next((pet for pet in collection_data['data'] if pet['configName'].lower() == petname.lower()), None)
|
40 |
|
41 |
-
if not
|
42 |
-
await interaction.followup.send(f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
return
|
44 |
|
45 |
exists_value = pet_exists['value']
|
46 |
rap_value = pet_rap['value']
|
47 |
thumbnail_id = pet_info['configData']['thumbnail'].split('://')[1]
|
48 |
-
|
49 |
thumbnail_url = f"https://api.rbxgleaks1.workers.dev/asset/{thumbnail_id}"
|
50 |
|
51 |
def format_difficulty(difficulty):
|
@@ -59,12 +75,12 @@ async def petsimgo(interaction: discord.Interaction, petname: str):
|
|
59 |
return f"{difficulty} ({difficulty:,})"
|
60 |
|
61 |
embed = discord.Embed(title=f"PetsGo: {pet_info['configData']['name']}", color=0x787878)
|
62 |
-
embed.add_field(name="
|
63 |
-
embed.add_field(name="
|
64 |
-
embed.add_field(name="
|
65 |
-
embed.add_field(name="
|
66 |
embed.set_thumbnail(url=thumbnail_url)
|
67 |
-
embed.set_footer(text="
|
68 |
|
69 |
await interaction.followup.send(embed=embed)
|
70 |
|
|
|
15 |
async def read_root():
|
16 |
return {"Hello": "World"}
|
17 |
|
18 |
+
@tree.command(name="petsimgo", description="Get info on pets in PetsGo")
|
19 |
async def petsimgo(interaction: discord.Interaction, petname: str):
|
20 |
await interaction.response.defer()
|
21 |
|
|
|
26 |
return await response.json()
|
27 |
return None
|
28 |
|
|
|
|
|
29 |
collection_data = await fetch_data("https://petsgo.biggamesapi.io/api/collection/Pets")
|
30 |
|
31 |
+
if not collection_data:
|
32 |
await interaction.followup.send("errer")
|
33 |
return
|
34 |
|
35 |
+
matching_pets = [pet for pet in collection_data['data'] if petname.lower() in pet['configName'].lower()]
|
|
|
|
|
36 |
|
37 |
+
if not matching_pets:
|
38 |
+
await interaction.followup.send(f"No pets found with '{petname}'.")
|
39 |
+
return
|
40 |
+
|
41 |
+
if len(matching_pets) == 1:
|
42 |
+
pet = matching_pets[0]
|
43 |
+
await show_pet_details(interaction, pet)
|
44 |
+
else:
|
45 |
+
pet_names = [pet['configData']['name'] for pet in matching_pets]
|
46 |
+
embed = discord.Embed(title="Matching Pets", color=0x787878)
|
47 |
+
embed.description = "\n".join(pet_names)
|
48 |
+
embed.set_footer(text=f"Found {len(pet_names)} matching name, the one you put does not exist.")
|
49 |
+
await interaction.followup.send(embed=embed)
|
50 |
+
|
51 |
+
async def show_pet_details(interaction, pet_info):
|
52 |
+
exists_data = await fetch_data("https://petsgo.biggamesapi.io/api/exists")
|
53 |
+
rap_data = await fetch_data("https://petsgo.biggamesapi.io/api/Rap")
|
54 |
+
|
55 |
+
pet_exists = next((p for p in exists_data['data'] if p['configData']['id'] == pet_info['configData']['id']), None)
|
56 |
+
pet_rap = next((p for p in rap_data['data'] if p['configData']['id'] == pet_info['configData']['id']), None)
|
57 |
+
|
58 |
+
if not pet_exists or not pet_rap:
|
59 |
+
await interaction.followup.send("errer")
|
60 |
return
|
61 |
|
62 |
exists_value = pet_exists['value']
|
63 |
rap_value = pet_rap['value']
|
64 |
thumbnail_id = pet_info['configData']['thumbnail'].split('://')[1]
|
|
|
65 |
thumbnail_url = f"https://api.rbxgleaks1.workers.dev/asset/{thumbnail_id}"
|
66 |
|
67 |
def format_difficulty(difficulty):
|
|
|
75 |
return f"{difficulty} ({difficulty:,})"
|
76 |
|
77 |
embed = discord.Embed(title=f"PetsGo: {pet_info['configData']['name']}", color=0x787878)
|
78 |
+
embed.add_field(name="Value", value=f"{rap_value:,} diamonds", inline=True)
|
79 |
+
embed.add_field(name="Existing", value=f"{exists_value:,}", inline=True)
|
80 |
+
embed.add_field(name="Difficulty", value=format_difficulty(pet_info['configData']['difficulty']), inline=True)
|
81 |
+
embed.add_field(name="Category", value=pet_info['category'], inline=True)
|
82 |
embed.set_thumbnail(url=thumbnail_url)
|
83 |
+
embed.set_footer(text="Best Bot Ever")
|
84 |
|
85 |
await interaction.followup.send(embed=embed)
|
86 |
|