Spaces:
Building
Building
Update petroll.py
Browse files- petroll.py +33 -29
petroll.py
CHANGED
@@ -5,8 +5,9 @@ import random
|
|
5 |
import time
|
6 |
import asyncio
|
7 |
|
8 |
-
from cash import user_cash
|
9 |
|
|
|
10 |
luck_multipliers = {}
|
11 |
luck_expiration = {}
|
12 |
luck_opportunities = {}
|
@@ -14,6 +15,7 @@ used_luck_opportunities = {}
|
|
14 |
first_luck_claimed = set()
|
15 |
auto_roll_users = set()
|
16 |
auto_sell_users = set()
|
|
|
17 |
|
18 |
async def perform_roll(interaction: discord.Interaction):
|
19 |
async def fetch_data(url):
|
@@ -81,6 +83,10 @@ async def perform_roll(interaction: discord.Interaction):
|
|
81 |
|
82 |
embed.set_footer(text=f"Click 'Roll Again' to roll again!{luck_text}")
|
83 |
|
|
|
|
|
|
|
|
|
84 |
roll_again_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Roll Again", custom_id="roll_again")
|
85 |
|
86 |
async def roll_again_callback(interaction: discord.Interaction):
|
@@ -90,12 +96,11 @@ async def perform_roll(interaction: discord.Interaction):
|
|
90 |
await interaction.followup.send(embed=result[0], view=result[1])
|
91 |
else:
|
92 |
await interaction.followup.send("An error occurred.")
|
93 |
-
|
94 |
roll_again_button.callback = roll_again_callback
|
95 |
-
|
96 |
-
view = discord.ui.View()
|
97 |
view.add_item(roll_again_button)
|
98 |
|
|
|
99 |
sell_button = discord.ui.Button(style=discord.ButtonStyle.success, label=f"Sell Pet for ${rap_value}", custom_id="sell_pet")
|
100 |
|
101 |
async def sell_pet_callback(interaction: discord.Interaction):
|
@@ -106,18 +111,20 @@ async def perform_roll(interaction: discord.Interaction):
|
|
106 |
sell_value = rap_value
|
107 |
user_cash[user_id] = user_cash.get(user_id, 0) + sell_value
|
108 |
await interaction.response.send_message(f"You sold the pet for ${sell_value}. Your new balance is ${user_cash[user_id]}.", ephemeral=True)
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
await interaction.message.edit(view=view)
|
114 |
|
115 |
sell_button.callback = sell_pet_callback
|
116 |
|
117 |
-
# Add sell button only if auto-sell is not enabled
|
118 |
-
if user_id not in auto_sell_users:
|
119 |
view.add_item(sell_button)
|
|
|
120 |
|
|
|
121 |
if user_id not in first_luck_claimed:
|
122 |
first_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Claim 100% Luck Forever", custom_id="first_luck")
|
123 |
|
@@ -131,10 +138,7 @@ async def perform_roll(interaction: discord.Interaction):
|
|
131 |
|
132 |
await interaction.response.send_message("You've claimed 100% luck forever!", ephemeral=True)
|
133 |
|
134 |
-
|
135 |
-
if item.custom_id == "first_luck":
|
136 |
-
view.remove_item(item)
|
137 |
-
break
|
138 |
await interaction.message.edit(view=view)
|
139 |
|
140 |
first_luck_button.callback = first_luck_callback
|
@@ -156,7 +160,7 @@ async def perform_roll(interaction: discord.Interaction):
|
|
156 |
current_luck = luck_multipliers.get(user_id, 1)
|
157 |
new_luck = min(current_luck + 1, 10)
|
158 |
luck_multipliers[user_id] = new_luck
|
159 |
-
luck_expiration[user_id] = time.time() + 1800
|
160 |
|
161 |
if user_id not in used_luck_opportunities:
|
162 |
used_luck_opportunities[user_id] = set()
|
@@ -165,10 +169,7 @@ async def perform_roll(interaction: discord.Interaction):
|
|
165 |
luck_percentage = (new_luck - 1) * 100
|
166 |
await interaction.response.send_message(f"Your luck has been increased to {luck_percentage}% for 30 minutes!", ephemeral=True)
|
167 |
|
168 |
-
|
169 |
-
if item.custom_id == interaction.custom_id:
|
170 |
-
view.remove_item(item)
|
171 |
-
break
|
172 |
await interaction.message.edit(view=view)
|
173 |
|
174 |
# Schedule the next luck opportunity
|
@@ -177,6 +178,7 @@ async def perform_roll(interaction: discord.Interaction):
|
|
177 |
increase_luck_button.callback = increase_luck_callback
|
178 |
view.add_item(increase_luck_button)
|
179 |
|
|
|
180 |
auto_roll_button = discord.ui.Button(
|
181 |
style=discord.ButtonStyle.primary if user_id not in auto_roll_users else discord.ButtonStyle.danger,
|
182 |
label="Auto Roll" if user_id not in auto_roll_users else "Stop Auto Roll",
|
@@ -199,12 +201,13 @@ async def perform_roll(interaction: discord.Interaction):
|
|
199 |
auto_roll_button.label = "Stop Auto Roll"
|
200 |
await interaction.response.send_message("Auto roll started. It will automatically stop after 3 minutes.", ephemeral=True)
|
201 |
asyncio.create_task(auto_roll(interaction))
|
202 |
-
|
203 |
await interaction.message.edit(view=view)
|
204 |
|
205 |
auto_roll_button.callback = auto_roll_callback
|
206 |
view.add_item(auto_roll_button)
|
207 |
|
|
|
208 |
auto_sell_button = discord.ui.Button(
|
209 |
style=discord.ButtonStyle.primary if user_id not in auto_sell_users else discord.ButtonStyle.danger,
|
210 |
label="Auto Pet Sell" if user_id not in auto_sell_users else "Stop Auto Pet Sell",
|
@@ -221,21 +224,24 @@ async def perform_roll(interaction: discord.Interaction):
|
|
221 |
auto_sell_button.style = discord.ButtonStyle.primary
|
222 |
auto_sell_button.label = "Auto Pet Sell"
|
223 |
await interaction.response.send_message("Auto pet sell stopped.", ephemeral=True)
|
224 |
-
#
|
|
|
|
|
225 |
view.add_item(sell_button)
|
226 |
else:
|
227 |
auto_sell_users.add(user_id)
|
228 |
auto_sell_button.style = discord.ButtonStyle.danger
|
229 |
auto_sell_button.label = "Stop Auto Pet Sell"
|
230 |
-
await interaction.response.send_message("Auto pet sell started.", ephemeral=True)
|
231 |
# Remove the sell button to prevent manual selling
|
232 |
view.remove_item(sell_button)
|
233 |
-
|
234 |
await interaction.message.edit(view=view)
|
235 |
|
236 |
auto_sell_button.callback = auto_sell_callback
|
237 |
view.add_item(auto_sell_button)
|
238 |
|
|
|
239 |
if user_id in auto_sell_users:
|
240 |
user_cash[user_id] = user_cash.get(user_id, 0) + rap_value
|
241 |
embed.add_field(name="Auto Sell", value=f"Pet automatically sold for ${rap_value}. New balance: ${user_cash[user_id]}", inline=False)
|
@@ -259,7 +265,7 @@ async def schedule_next_luck_opportunity(interaction: discord.Interaction, user_
|
|
259 |
current_luck = luck_multipliers.get(user_id, 1)
|
260 |
new_luck = min(current_luck + 1, 10)
|
261 |
luck_multipliers[user_id] = new_luck
|
262 |
-
luck_expiration[user_id] = time.time() + 1800
|
263 |
|
264 |
if user_id not in used_luck_opportunities:
|
265 |
used_luck_opportunities[user_id] = set()
|
@@ -268,11 +274,9 @@ async def schedule_next_luck_opportunity(interaction: discord.Interaction, user_
|
|
268 |
luck_percentage = (new_luck - 1) * 100
|
269 |
await interaction.response.send_message(f"Your luck has been increased to {luck_percentage}% for 30 minutes!", ephemeral=True)
|
270 |
|
|
|
271 |
view = interaction.message.components[0]
|
272 |
-
|
273 |
-
if item.custom_id == interaction.custom_id:
|
274 |
-
view.remove_item(item)
|
275 |
-
break
|
276 |
await interaction.message.edit(view=view)
|
277 |
|
278 |
# Schedule the next luck opportunity
|
@@ -290,7 +294,7 @@ async def auto_roll(interaction: discord.Interaction):
|
|
290 |
while user_id in auto_roll_users:
|
291 |
if time.time() - start_time >= 180: # 3 minutes
|
292 |
auto_roll_users.remove(user_id)
|
293 |
-
await interaction.followup.send("
|
294 |
break
|
295 |
|
296 |
result = await perform_roll(interaction)
|
|
|
5 |
import time
|
6 |
import asyncio
|
7 |
|
8 |
+
from cash import user_cash # Ensure you have a 'cash.py' with a 'user_cash' dictionary
|
9 |
|
10 |
+
# Dictionaries to manage user states
|
11 |
luck_multipliers = {}
|
12 |
luck_expiration = {}
|
13 |
luck_opportunities = {}
|
|
|
15 |
first_luck_claimed = set()
|
16 |
auto_roll_users = set()
|
17 |
auto_sell_users = set()
|
18 |
+
can_manual_sell = set() # Tracks users who can perform a manual sell
|
19 |
|
20 |
async def perform_roll(interaction: discord.Interaction):
|
21 |
async def fetch_data(url):
|
|
|
83 |
|
84 |
embed.set_footer(text=f"Click 'Roll Again' to roll again!{luck_text}")
|
85 |
|
86 |
+
# Create buttons
|
87 |
+
view = discord.ui.View()
|
88 |
+
|
89 |
+
# Roll Again Button
|
90 |
roll_again_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Roll Again", custom_id="roll_again")
|
91 |
|
92 |
async def roll_again_callback(interaction: discord.Interaction):
|
|
|
96 |
await interaction.followup.send(embed=result[0], view=result[1])
|
97 |
else:
|
98 |
await interaction.followup.send("An error occurred.")
|
99 |
+
|
100 |
roll_again_button.callback = roll_again_callback
|
|
|
|
|
101 |
view.add_item(roll_again_button)
|
102 |
|
103 |
+
# Sell Button
|
104 |
sell_button = discord.ui.Button(style=discord.ButtonStyle.success, label=f"Sell Pet for ${rap_value}", custom_id="sell_pet")
|
105 |
|
106 |
async def sell_pet_callback(interaction: discord.Interaction):
|
|
|
111 |
sell_value = rap_value
|
112 |
user_cash[user_id] = user_cash.get(user_id, 0) + sell_value
|
113 |
await interaction.response.send_message(f"You sold the pet for ${sell_value}. Your new balance is ${user_cash[user_id]}.", ephemeral=True)
|
114 |
+
|
115 |
+
# Disable further manual selling until auto-sell is toggled
|
116 |
+
can_manual_sell.discard(user_id)
|
117 |
+
view.remove_item(sell_button)
|
118 |
await interaction.message.edit(view=view)
|
119 |
|
120 |
sell_button.callback = sell_pet_callback
|
121 |
|
122 |
+
# Add sell button only if auto-sell is not enabled and user can perform a manual sell
|
123 |
+
if user_id not in auto_sell_users and user_id not in can_manual_sell:
|
124 |
view.add_item(sell_button)
|
125 |
+
can_manual_sell.add(user_id)
|
126 |
|
127 |
+
# First Luck Button
|
128 |
if user_id not in first_luck_claimed:
|
129 |
first_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Claim 100% Luck Forever", custom_id="first_luck")
|
130 |
|
|
|
138 |
|
139 |
await interaction.response.send_message("You've claimed 100% luck forever!", ephemeral=True)
|
140 |
|
141 |
+
view.remove_item(first_luck_button)
|
|
|
|
|
|
|
142 |
await interaction.message.edit(view=view)
|
143 |
|
144 |
first_luck_button.callback = first_luck_callback
|
|
|
160 |
current_luck = luck_multipliers.get(user_id, 1)
|
161 |
new_luck = min(current_luck + 1, 10)
|
162 |
luck_multipliers[user_id] = new_luck
|
163 |
+
luck_expiration[user_id] = time.time() + 1800 # 30 minutes
|
164 |
|
165 |
if user_id not in used_luck_opportunities:
|
166 |
used_luck_opportunities[user_id] = set()
|
|
|
169 |
luck_percentage = (new_luck - 1) * 100
|
170 |
await interaction.response.send_message(f"Your luck has been increased to {luck_percentage}% for 30 minutes!", ephemeral=True)
|
171 |
|
172 |
+
view.remove_item(increase_luck_button)
|
|
|
|
|
|
|
173 |
await interaction.message.edit(view=view)
|
174 |
|
175 |
# Schedule the next luck opportunity
|
|
|
178 |
increase_luck_button.callback = increase_luck_callback
|
179 |
view.add_item(increase_luck_button)
|
180 |
|
181 |
+
# Auto Roll Button
|
182 |
auto_roll_button = discord.ui.Button(
|
183 |
style=discord.ButtonStyle.primary if user_id not in auto_roll_users else discord.ButtonStyle.danger,
|
184 |
label="Auto Roll" if user_id not in auto_roll_users else "Stop Auto Roll",
|
|
|
201 |
auto_roll_button.label = "Stop Auto Roll"
|
202 |
await interaction.response.send_message("Auto roll started. It will automatically stop after 3 minutes.", ephemeral=True)
|
203 |
asyncio.create_task(auto_roll(interaction))
|
204 |
+
|
205 |
await interaction.message.edit(view=view)
|
206 |
|
207 |
auto_roll_button.callback = auto_roll_callback
|
208 |
view.add_item(auto_roll_button)
|
209 |
|
210 |
+
# Auto Sell Button
|
211 |
auto_sell_button = discord.ui.Button(
|
212 |
style=discord.ButtonStyle.primary if user_id not in auto_sell_users else discord.ButtonStyle.danger,
|
213 |
label="Auto Pet Sell" if user_id not in auto_sell_users else "Stop Auto Pet Sell",
|
|
|
224 |
auto_sell_button.style = discord.ButtonStyle.primary
|
225 |
auto_sell_button.label = "Auto Pet Sell"
|
226 |
await interaction.response.send_message("Auto pet sell stopped.", ephemeral=True)
|
227 |
+
# Allow one manual sell after stopping auto-sell
|
228 |
+
can_manual_sell.add(user_id)
|
229 |
+
# Add sell button back if appropriate
|
230 |
view.add_item(sell_button)
|
231 |
else:
|
232 |
auto_sell_users.add(user_id)
|
233 |
auto_sell_button.style = discord.ButtonStyle.danger
|
234 |
auto_sell_button.label = "Stop Auto Pet Sell"
|
235 |
+
await interaction.response.send_message("Auto pet sell started. You cannot manually sell pets while auto-sell is enabled.", ephemeral=True)
|
236 |
# Remove the sell button to prevent manual selling
|
237 |
view.remove_item(sell_button)
|
238 |
+
|
239 |
await interaction.message.edit(view=view)
|
240 |
|
241 |
auto_sell_button.callback = auto_sell_callback
|
242 |
view.add_item(auto_sell_button)
|
243 |
|
244 |
+
# Handle Auto Sell: Automatically sell the pet if auto-sell is enabled
|
245 |
if user_id in auto_sell_users:
|
246 |
user_cash[user_id] = user_cash.get(user_id, 0) + rap_value
|
247 |
embed.add_field(name="Auto Sell", value=f"Pet automatically sold for ${rap_value}. New balance: ${user_cash[user_id]}", inline=False)
|
|
|
265 |
current_luck = luck_multipliers.get(user_id, 1)
|
266 |
new_luck = min(current_luck + 1, 10)
|
267 |
luck_multipliers[user_id] = new_luck
|
268 |
+
luck_expiration[user_id] = time.time() + 1800 # 30 minutes
|
269 |
|
270 |
if user_id not in used_luck_opportunities:
|
271 |
used_luck_opportunities[user_id] = set()
|
|
|
274 |
luck_percentage = (new_luck - 1) * 100
|
275 |
await interaction.response.send_message(f"Your luck has been increased to {luck_percentage}% for 30 minutes!", ephemeral=True)
|
276 |
|
277 |
+
# Remove the used button
|
278 |
view = interaction.message.components[0]
|
279 |
+
view.remove_item(increase_luck_button)
|
|
|
|
|
|
|
280 |
await interaction.message.edit(view=view)
|
281 |
|
282 |
# Schedule the next luck opportunity
|
|
|
294 |
while user_id in auto_roll_users:
|
295 |
if time.time() - start_time >= 180: # 3 minutes
|
296 |
auto_roll_users.remove(user_id)
|
297 |
+
await interaction.followup.send("auto roll stopped, to turn it on again roll and turn it on again", ephemeral=True)
|
298 |
break
|
299 |
|
300 |
result = await perform_roll(interaction)
|