coollsd commited on
Commit
68c299b
·
verified ·
1 Parent(s): 4b66121

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -1
app.py CHANGED
@@ -4,6 +4,7 @@ import aiohttp
4
  import asyncio
5
  from fastapi import FastAPI
6
  import uvicorn
 
7
 
8
  app = FastAPI()
9
  intents = discord.Intents.default()
@@ -31,7 +32,7 @@ async def petsimgo(interaction: discord.Interaction, petname: str):
31
  collection_data = await fetch_data("https://petsgo.biggamesapi.io/api/collection/Pets")
32
 
33
  if not exists_data or not rap_data or not collection_data:
34
- await interaction.followup.send("errer")
35
  return
36
 
37
  pet_exists = next((pet for pet in exists_data['data'] if pet['configData']['id'].lower() == petname.lower()), None)
@@ -68,6 +69,70 @@ async def petsimgo(interaction: discord.Interaction, petname: str):
68
 
69
  await interaction.followup.send(embed=embed)
70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  @bot.event
72
  async def on_ready():
73
  await tree.sync()
 
4
  import asyncio
5
  from fastapi import FastAPI
6
  import uvicorn
7
+ import random
8
 
9
  app = FastAPI()
10
  intents = discord.Intents.default()
 
32
  collection_data = await fetch_data("https://petsgo.biggamesapi.io/api/collection/Pets")
33
 
34
  if not exists_data or not rap_data or not collection_data:
35
+ await interaction.followup.send("error")
36
  return
37
 
38
  pet_exists = next((pet for pet in exists_data['data'] if pet['configData']['id'].lower() == petname.lower()), None)
 
69
 
70
  await interaction.followup.send(embed=embed)
71
 
72
+ @tree.command(name="petroll", description="Roll for a random pet")
73
+ async def petroll(interaction: discord.Interaction):
74
+ await interaction.response.defer()
75
+
76
+ async def fetch_data(url):
77
+ async with aiohttp.ClientSession() as session:
78
+ async with session.get(url) as response:
79
+ if response.status == 200:
80
+ return await response.json()
81
+ return None
82
+
83
+ rap_data = await fetch_data("https://petsgo.biggamesapi.io/api/Rap")
84
+ collection_data = await fetch_data("https://petsgo.biggamesapi.io/api/collection/Pets")
85
+
86
+ if not rap_data or not collection_data:
87
+ await interaction.followup.send("error")
88
+ return
89
+
90
+ pets = [pet for pet in collection_data['data'] if pet['configName'] in [p['configData']['id'] for p in rap_data['data']]]
91
+
92
+ if not pets:
93
+ await interaction.followup.send("No pets available to roll.")
94
+ return
95
+
96
+ rolled_pet = random.choice(pets)
97
+ pet_rap = next((pet for pet in rap_data['data'] if pet['configData']['id'] == rolled_pet['configName']), None)
98
+
99
+ if not pet_rap:
100
+ await interaction.followup.send("Error retrieving pet information.")
101
+ return
102
+
103
+ rap_value = pet_rap['value']
104
+ thumbnail_id = rolled_pet['configData']['thumbnail'].split('://')[1]
105
+ thumbnail_url = f"https://api.rbxgleaks1.workers.dev/asset/{thumbnail_id}"
106
+
107
+ def format_difficulty(difficulty):
108
+ if difficulty >= 1_000_000_000:
109
+ return f"{difficulty / 1_000_000_000:.1f}B ({difficulty:,})"
110
+ elif difficulty >= 1_000_000:
111
+ return f"{difficulty / 1_000_000:.1f}M ({difficulty:,})"
112
+ elif difficulty >= 1_000:
113
+ return f"{difficulty / 1_000:.1f}K ({difficulty:,})"
114
+ else:
115
+ return f"{difficulty} ({difficulty:,})"
116
+
117
+ embed = discord.Embed(title=f"You rolled: {rolled_pet['configData']['name']}", color=0x787878)
118
+ embed.add_field(name="value", value=f"{rap_value:,} diamonds", inline=True)
119
+ embed.add_field(name="difficulty", value=format_difficulty(rolled_pet['configData']['difficulty']), inline=True)
120
+ embed.add_field(name="category", value=rolled_pet['category'], inline=True)
121
+ embed.set_thumbnail(url=thumbnail_url)
122
+ embed.set_footer(text="Click 'Roll Again' to roll again!")
123
+
124
+ roll_again_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Roll Again", custom_id="roll_again")
125
+
126
+ async def roll_again_callback(interaction: discord.Interaction):
127
+ await petroll(interaction)
128
+
129
+ roll_again_button.callback = roll_again_callback
130
+
131
+ view = discord.ui.View()
132
+ view.add_item(roll_again_button)
133
+
134
+ await interaction.followup.send(embed=embed, view=view)
135
+
136
  @bot.event
137
  async def on_ready():
138
  await tree.sync()