coollsd commited on
Commit
0b9b12e
·
verified ·
1 Parent(s): acb36ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -12
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
- @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:
@@ -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
- 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]
@@ -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 petroll(interaction)
 
 
 
 
129
 
130
  roll_again_button.callback = roll_again_callback
131
 
132
  view = discord.ui.View()
133
  view.add_item(roll_again_button)
134
 
135
- await interaction.followup.send(embed=embed, view=view)
 
 
 
 
 
 
 
 
 
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():