coollsd commited on
Commit
3093cbf
·
verified ·
1 Parent(s): a372ce3

Create petroll.py

Browse files
Files changed (1) hide show
  1. petroll.py +127 -0
petroll.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import discord
2
+ from discord import app_commands
3
+ import aiohttp
4
+ import random
5
+ import time
6
+
7
+ luck_multipliers = {}
8
+ luck_expiration = {}
9
+ luck_opportunities = {}
10
+
11
+ async def perform_roll(interaction: discord.Interaction):
12
+ async def fetch_data(url):
13
+ async with aiohttp.ClientSession() as session:
14
+ async with session.get(url) as response:
15
+ if response.status == 200:
16
+ return await response.json()
17
+ return None
18
+
19
+ rap_data = await fetch_data("https://petsgo.biggamesapi.io/api/Rap")
20
+ collection_data = await fetch_data("https://petsgo.biggamesapi.io/api/collection/Pets")
21
+
22
+ if not rap_data or not collection_data:
23
+ return None
24
+
25
+ pets = [pet for pet in collection_data['data'] if pet['configName'] in [p['configData']['id'] for p in rap_data['data']]]
26
+
27
+ if not pets:
28
+ return None
29
+
30
+ user_id = interaction.user.id
31
+ luck_multiplier = luck_multipliers.get(user_id, 1)
32
+
33
+ sorted_pets = sorted(pets, key=lambda x: x['configData']['difficulty'])
34
+
35
+ max_index = len(sorted_pets) - 1
36
+ index = int(max_index * (luck_multiplier - 1) / 9)
37
+
38
+ rolled_pet = random.choice(sorted_pets[:index+1])
39
+
40
+ pet_rap = next((pet for pet in rap_data['data'] if pet['configData']['id'] == rolled_pet['configName']), None)
41
+
42
+ if not pet_rap:
43
+ return None
44
+
45
+ rap_value = pet_rap['value']
46
+ thumbnail_id = rolled_pet['configData']['thumbnail'].split('://')[1]
47
+ thumbnail_url = f"https://api.rbxgleaks1.workers.dev/asset/{thumbnail_id}"
48
+
49
+ def format_difficulty(difficulty):
50
+ if difficulty >= 1_000_000_000:
51
+ return f"{difficulty / 1_000_000_000:.1f}B ({difficulty:,})"
52
+ elif difficulty >= 1_000_000:
53
+ return f"{difficulty / 1_000_000:.1f}M ({difficulty:,})"
54
+ elif difficulty >= 1_000:
55
+ return f"{difficulty / 1_000:.1f}K ({difficulty:,})"
56
+ else:
57
+ return f"{difficulty} ({difficulty:,})"
58
+
59
+ embed = discord.Embed(title=f"{interaction.user.name} rolled: {rolled_pet['configData']['name']}", color=0x787878)
60
+ embed.add_field(name="value", value=f"{rap_value:,} diamonds", inline=True)
61
+ embed.add_field(name="difficulty", value=format_difficulty(rolled_pet['configData']['difficulty']), inline=True)
62
+ embed.add_field(name="category", value=rolled_pet['category'], inline=True)
63
+ embed.set_thumbnail(url=thumbnail_url)
64
+
65
+ luck_text = ""
66
+ if user_id in luck_expiration:
67
+ remaining_time = int(luck_expiration[user_id] - time.time())
68
+ if remaining_time > 0:
69
+ luck_percentage = (luck_multiplier - 1) * 100
70
+ luck_text = f"\nYou have {remaining_time // 60} minutes and {remaining_time % 60} seconds of luck left! ({luck_percentage}% luck)"
71
+ else:
72
+ del luck_multipliers[user_id]
73
+ del luck_expiration[user_id]
74
+
75
+ embed.set_footer(text=f"Click 'Roll Again' to roll again!{luck_text}")
76
+
77
+ roll_again_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Roll Again", custom_id="roll_again")
78
+
79
+ async def roll_again_callback(interaction: discord.Interaction):
80
+ await interaction.response.defer()
81
+ result = await perform_roll(interaction)
82
+ if result:
83
+ await interaction.followup.send(embed=result[0], view=result[1])
84
+ else:
85
+ await interaction.followup.send("errer.")
86
+
87
+ roll_again_button.callback = roll_again_callback
88
+
89
+ view = discord.ui.View()
90
+ view.add_item(roll_again_button)
91
+
92
+ if random.random() < 0.2:
93
+ luck_opportunities[user_id] = luck_opportunities.get(user_id, 0) + 1
94
+ increase_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Increase Luck", custom_id=f"increase_luck_{luck_opportunities[user_id]}")
95
+
96
+ async def increase_luck_callback(interaction: discord.Interaction):
97
+ if interaction.user.id != user_id:
98
+ await interaction.response.send_message("cannot use", ephemeral=True)
99
+ return
100
+
101
+ current_luck = luck_multipliers.get(user_id, 1)
102
+ new_luck = min(current_luck + 1, 10)
103
+ luck_multipliers[user_id] = new_luck
104
+ luck_expiration[user_id] = time.time() + 1800
105
+
106
+ luck_percentage = (new_luck - 1) * 100
107
+ await interaction.response.send_message(f"luck increased to {luck_percentage}% for 30 minutes!", ephemeral=True)
108
+
109
+ for item in view.children:
110
+ if item.custom_id == interaction.custom_id:
111
+ view.remove_item(item)
112
+ break
113
+ await interaction.message.edit(view=view)
114
+
115
+ increase_luck_button.callback = increase_luck_callback
116
+ view.add_item(increase_luck_button)
117
+
118
+ return embed, view
119
+
120
+ @app_commands.command(name="petroll", description="Roll for a random pet")
121
+ async def petroll(interaction: discord.Interaction):
122
+ await interaction.response.defer()
123
+ result = await perform_roll(interaction)
124
+ if result:
125
+ await interaction.followup.send(embed=result[0], view=result[1])
126
+ else:
127
+ await interaction.followup.send("errer")