Spaces:
Building
Building
Update app.py
Browse files
app.py
CHANGED
@@ -69,10 +69,7 @@ async def petsimgo(interaction: discord.Interaction, petname: str):
|
|
69 |
|
70 |
await interaction.followup.send(embed=embed)
|
71 |
|
72 |
-
|
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:
|
@@ -84,21 +81,18 @@ async def petroll(interaction: discord.Interaction):
|
|
84 |
collection_data = await fetch_data("https://petsgo.biggamesapi.io/api/collection/Pets")
|
85 |
|
86 |
if not rap_data or not collection_data:
|
87 |
-
|
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 |
-
|
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 |
-
|
101 |
-
return
|
102 |
|
103 |
rap_value = pet_rap['value']
|
104 |
thumbnail_id = rolled_pet['configData']['thumbnail'].split('://')[1]
|
@@ -125,14 +119,27 @@ async def petroll(interaction: discord.Interaction):
|
|
125 |
|
126 |
async def roll_again_callback(interaction: discord.Interaction):
|
127 |
await interaction.response.defer()
|
128 |
-
await
|
|
|
|
|
|
|
|
|
129 |
|
130 |
roll_again_button.callback = roll_again_callback
|
131 |
|
132 |
view = discord.ui.View()
|
133 |
view.add_item(roll_again_button)
|
134 |
|
135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
|
137 |
@bot.event
|
138 |
async def on_ready():
|
|
|
69 |
|
70 |
await interaction.followup.send(embed=embed)
|
71 |
|
72 |
+
async def perform_roll(interaction: discord.Interaction):
|
|
|
|
|
|
|
73 |
async def fetch_data(url):
|
74 |
async with aiohttp.ClientSession() as session:
|
75 |
async with session.get(url) as response:
|
|
|
81 |
collection_data = await fetch_data("https://petsgo.biggamesapi.io/api/collection/Pets")
|
82 |
|
83 |
if not rap_data or not collection_data:
|
84 |
+
return None
|
|
|
85 |
|
86 |
pets = [pet for pet in collection_data['data'] if pet['configName'] in [p['configData']['id'] for p in rap_data['data']]]
|
87 |
|
88 |
if not pets:
|
89 |
+
return None
|
|
|
90 |
|
91 |
rolled_pet = random.choice(pets)
|
92 |
pet_rap = next((pet for pet in rap_data['data'] if pet['configData']['id'] == rolled_pet['configName']), None)
|
93 |
|
94 |
if not pet_rap:
|
95 |
+
return None
|
|
|
96 |
|
97 |
rap_value = pet_rap['value']
|
98 |
thumbnail_id = rolled_pet['configData']['thumbnail'].split('://')[1]
|
|
|
119 |
|
120 |
async def roll_again_callback(interaction: discord.Interaction):
|
121 |
await interaction.response.defer()
|
122 |
+
result = await perform_roll(interaction)
|
123 |
+
if result:
|
124 |
+
await interaction.followup.send(embed=result[0], view=result[1])
|
125 |
+
else:
|
126 |
+
await interaction.followup.send("errer")
|
127 |
|
128 |
roll_again_button.callback = roll_again_callback
|
129 |
|
130 |
view = discord.ui.View()
|
131 |
view.add_item(roll_again_button)
|
132 |
|
133 |
+
return embed, view
|
134 |
+
|
135 |
+
@tree.command(name="petroll", description="Roll for a random pet")
|
136 |
+
async def petroll(interaction: discord.Interaction):
|
137 |
+
await interaction.response.defer()
|
138 |
+
result = await perform_roll(interaction)
|
139 |
+
if result:
|
140 |
+
await interaction.followup.send(embed=result[0], view=result[1])
|
141 |
+
else:
|
142 |
+
await interaction.followup.send("errer")
|
143 |
|
144 |
@bot.event
|
145 |
async def on_ready():
|