coollsd commited on
Commit
51982ec
·
verified ·
1 Parent(s): f40a4ac

Update petsimgo.py

Browse files
Files changed (1) hide show
  1. petsimgo.py +127 -23
petsimgo.py CHANGED
@@ -1,11 +1,17 @@
1
  import discord
2
  from discord import app_commands
3
  import aiohttp
 
 
4
 
5
- @app_commands.command(name="petsimgo", description="get info on pet on petsgo u")
6
- async def petsimgo(interaction: discord.Interaction, petname: str):
7
- await interaction.response.defer()
 
 
 
8
 
 
9
  async def fetch_data(url):
10
  async with aiohttp.ClientSession() as session:
11
  async with session.get(url) as response:
@@ -13,26 +19,34 @@ async def petsimgo(interaction: discord.Interaction, petname: str):
13
  return await response.json()
14
  return None
15
 
16
- exists_data = await fetch_data("https://petsgo.biggamesapi.io/api/exists")
17
  rap_data = await fetch_data("https://petsgo.biggamesapi.io/api/Rap")
18
  collection_data = await fetch_data("https://petsgo.biggamesapi.io/api/collection/Pets")
19
 
20
- if not exists_data or not rap_data or not collection_data:
21
- await interaction.followup.send("error")
22
- return
 
 
 
 
23
 
24
- pet_exists = next((pet for pet in exists_data['data'] if pet['configData']['id'].lower() == petname.lower()), None)
25
- pet_rap = next((pet for pet in rap_data['data'] if pet['configData']['id'].lower() == petname.lower()), None)
26
- pet_info = next((pet for pet in collection_data['data'] if pet['configName'].lower() == petname.lower()), None)
 
 
 
 
 
 
27
 
28
- if not pet_exists or not pet_rap or not pet_info:
29
- await interaction.followup.send(f"Pet '{petname}' not found.")
30
- return
 
31
 
32
- exists_value = pet_exists['value']
33
  rap_value = pet_rap['value']
34
- thumbnail_id = pet_info['configData']['thumbnail'].split('://')[1]
35
-
36
  thumbnail_url = f"https://api.rbxgleaks1.workers.dev/asset/{thumbnail_id}"
37
 
38
  def format_difficulty(difficulty):
@@ -45,12 +59,102 @@ async def petsimgo(interaction: discord.Interaction, petname: str):
45
  else:
46
  return f"{difficulty} ({difficulty:,})"
47
 
48
- embed = discord.Embed(title=f"PetsGo: {pet_info['configData']['name']}", color=0x787878)
49
- embed.add_field(name="value", value=f"{rap_value:,} diamonds", inline=True)
50
- embed.add_field(name="existing", value=f"{exists_value:,}", inline=True)
51
- embed.add_field(name="difficulty", value=format_difficulty(pet_info['configData']['difficulty']), inline=True)
52
- embed.add_field(name="category", value=pet_info['category'], inline=True)
53
  embed.set_thumbnail(url=thumbnail_url)
54
- embed.set_footer(text="hello everyone can i please get a burrito now")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
 
56
- await interaction.followup.send(embed=embed)
 
 
 
 
 
1
  import discord
2
  from discord import app_commands
3
  import aiohttp
4
+ import random
5
+ import time
6
 
7
+ from cash import user_cash
8
+
9
+ luck_multipliers = {}
10
+ luck_expiration = {}
11
+ luck_opportunities = {}
12
+ used_luck_opportunities = set()
13
 
14
+ async def perform_roll(interaction: discord.Interaction):
15
  async def fetch_data(url):
16
  async with aiohttp.ClientSession() as session:
17
  async with session.get(url) as response:
 
19
  return await response.json()
20
  return None
21
 
 
22
  rap_data = await fetch_data("https://petsgo.biggamesapi.io/api/Rap")
23
  collection_data = await fetch_data("https://petsgo.biggamesapi.io/api/collection/Pets")
24
 
25
+ if not rap_data or not collection_data:
26
+ return None
27
+
28
+ pets = [pet for pet in collection_data['data'] if pet['configName'] in [p['configData']['id'] for p in rap_data['data']]]
29
+
30
+ if not pets:
31
+ return None
32
 
33
+ user_id = interaction.user.id
34
+ luck_multiplier = luck_multipliers.get(user_id, 1)
35
+
36
+ sorted_pets = sorted(pets, key=lambda x: x['configData']['difficulty'])
37
+
38
+ max_index = len(sorted_pets) - 1
39
+ index = int(max_index * (luck_multiplier - 1) / 9)
40
+
41
+ rolled_pet = random.choice(sorted_pets[:index+1])
42
 
43
+ pet_rap = next((pet for pet in rap_data['data'] if pet['configData']['id'] == rolled_pet['configName']), None)
44
+
45
+ if not pet_rap:
46
+ return None
47
 
 
48
  rap_value = pet_rap['value']
49
+ thumbnail_id = rolled_pet['configData']['thumbnail'].split('://')[1]
 
50
  thumbnail_url = f"https://api.rbxgleaks1.workers.dev/asset/{thumbnail_id}"
51
 
52
  def format_difficulty(difficulty):
 
59
  else:
60
  return f"{difficulty} ({difficulty:,})"
61
 
62
+ embed = discord.Embed(title=f"{interaction.user.name} rolled: {rolled_pet['configData']['name']}", color=0x787878)
63
+ embed.add_field(name="Value", value=f"{rap_value:,} diamonds", inline=True)
64
+ embed.add_field(name="Difficulty", value=format_difficulty(rolled_pet['configData']['difficulty']), inline=True)
65
+ embed.add_field(name="Category", value=rolled_pet['category'], inline=True)
 
66
  embed.set_thumbnail(url=thumbnail_url)
67
+
68
+ luck_text = ""
69
+ if user_id in luck_expiration:
70
+ remaining_time = int(luck_expiration[user_id] - time.time())
71
+ if remaining_time > 0:
72
+ luck_percentage = (luck_multiplier - 1) * 100
73
+ luck_text = f"\nYou have {remaining_time // 60} minutes and {remaining_time % 60} seconds of luck left! ({luck_percentage}% luck)"
74
+ else:
75
+ del luck_multipliers[user_id]
76
+ del luck_expiration[user_id]
77
+
78
+ embed.set_footer(text=f"Click 'Roll Again' to roll again!{luck_text}")
79
+
80
+ roll_again_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Roll Again", custom_id="roll_again")
81
+
82
+ async def roll_again_callback(interaction: discord.Interaction):
83
+ await interaction.response.defer()
84
+ result = await perform_roll(interaction)
85
+ if result:
86
+ await interaction.followup.send(embed=result[0], view=result[1])
87
+ else:
88
+ await interaction.followup.send("An error occurred.")
89
+
90
+ roll_again_button.callback = roll_again_callback
91
+
92
+ view = discord.ui.View()
93
+ view.add_item(roll_again_button)
94
+
95
+ sell_button = discord.ui.Button(style=discord.ButtonStyle.success, label=f"Sell Pet for ${rap_value}", custom_id="sell_pet")
96
+
97
+ async def sell_pet_callback(interaction: discord.Interaction):
98
+ if interaction.user.id != user_id:
99
+ await interaction.response.send_message("You cannot sell this pet.", ephemeral=True)
100
+ return
101
+
102
+ sell_value = rap_value
103
+ user_cash[user_id] = user_cash.get(user_id, 0) + sell_value
104
+ await interaction.response.send_message(f"You sold the pet for ${sell_value}. Your new balance is ${user_cash[user_id]}.", ephemeral=True)
105
+ for item in view.children:
106
+ if item.custom_id == "sell_pet":
107
+ view.remove_item(item)
108
+ break
109
+ await interaction.message.edit(view=view)
110
+
111
+ sell_button.callback = sell_pet_callback
112
+ view.add_item(sell_button)
113
+
114
+ if random.random() < 0.6 and luck_opportunities.get(user_id, 0) < 3:
115
+ luck_opportunities[user_id] = luck_opportunities.get(user_id, 0) + 1
116
+ increase_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Increase Luck", custom_id=f"increase_luck_{luck_opportunities[user_id]}")
117
+
118
+ async def increase_luck_callback(interaction: discord.Interaction):
119
+ if interaction.user.id != user_id:
120
+ await interaction.response.send_message("You cannot use this button.", ephemeral=True)
121
+ return
122
+
123
+ if user_id in used_luck_opportunities:
124
+ await interaction.response.send_message("You have already used your luck opportunity.", ephemeral=True)
125
+ return
126
+
127
+ current_luck = luck_multipliers.get(user_id, 1)
128
+ new_luck = min(current_luck + 1, 10)
129
+ luck_multipliers[user_id] = new_luck
130
+ luck_expiration[user_id] = time.time() + 1800
131
+ used_luck_opportunities.add(user_id)
132
+
133
+ luck_percentage = (new_luck - 1) * 100
134
+ await interaction.response.send_message(f"Your luck has been increased to {luck_percentage}% for 30 minutes!", ephemeral=True)
135
+
136
+ for item in view.children:
137
+ if item.custom_id == interaction.custom_id:
138
+ view.remove_item(item)
139
+ break
140
+ await interaction.message.edit(view=view)
141
+
142
+ increase_luck_button.callback = increase_luck_callback
143
+ view.add_item(increase_luck_button)
144
+
145
+ return embed, view
146
+
147
+ @app_commands.command(name="petroll", description="Roll for a random pet")
148
+ async def petroll(interaction: discord.Interaction):
149
+ await interaction.response.defer()
150
+ result = await perform_roll(interaction)
151
+ if result:
152
+ await interaction.followup.send(embed=result[0], view=result[1])
153
+ else:
154
+ await interaction.followup.send("An error occurred.")
155
 
156
+ @app_commands.command(name="balance", description="Check your current balance")
157
+ async def balance(interaction: discord.Interaction):
158
+ user_id = interaction.user.id
159
+ current_balance = user_cash.get(user_id, 0)
160
+ await interaction.response.send_message(f"Your current balance is ${current_balance}.", ephemeral=True)