Spaces:
Building
Building
Update petroll.py
Browse files- petroll.py +125 -72
petroll.py
CHANGED
@@ -217,96 +217,149 @@ async def perform_roll(interaction: discord.Interaction):
|
|
217 |
auto_sell_users.remove(user_id)
|
218 |
auto_sell_button.style = discord.ButtonStyle.primary
|
219 |
auto_sell_button.label = "Auto Pet Sell"
|
|
|
|
|
|
|
|
|
220 |
await interaction.response.send_message("Auto pet sell stopped.", ephemeral=True)
|
|
|
221 |
else:
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
|
227 |
-
|
228 |
|
229 |
-
|
230 |
-
|
231 |
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
|
236 |
-
|
237 |
|
238 |
-
async def schedule_next_luck_opportunity(interaction:
|
239 |
-
|
240 |
-
luck_opportunities[user_id] = luck_opportunities.get(user_id, 0) + 1
|
241 |
-
increase_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Increase Luck", custom_id=f"increase_luck_{luck_opportunities[user_id]}")
|
242 |
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
|
|
|
|
|
|
|
|
247 |
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
luck_expiration[user_id] = time.time() + 1800
|
256 |
|
257 |
-
|
258 |
-
used_luck_opportunities[user_id] = set()
|
259 |
-
used_luck_opportunities[user_id].add(luck_opportunities[user_id])
|
260 |
|
261 |
-
|
262 |
-
await interaction.response.send_message(f"Your luck has been increased to {luck_percentage}% for 30 minutes!", ephemeral=True)
|
263 |
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
270 |
|
271 |
-
|
272 |
-
|
|
|
|
|
273 |
|
274 |
-
|
275 |
|
276 |
-
|
277 |
-
view.add_item(increase_luck_button)
|
278 |
-
await interaction.message.edit(view=view)
|
279 |
|
280 |
-
async def
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
await interaction.followup.send("Auto roll has been automatically stopped after 3 minutes. You can start it again if you wish.", ephemeral=True)
|
287 |
-
break
|
288 |
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
310 |
|
311 |
@app_commands.command(name="dice", description="Roll the dice and bet")
|
312 |
async def dice(interaction: discord.Interaction, bet: int):
|
|
|
217 |
auto_sell_users.remove(user_id)
|
218 |
auto_sell_button.style = discord.ButtonStyle.primary
|
219 |
auto_sell_button.label = "Auto Pet Sell"
|
220 |
+
|
221 |
+
# Re-add the sell button when stopping auto-sell
|
222 |
+
sell_button.disabled=False
|
223 |
+
|
224 |
await interaction.response.send_message("Auto pet sell stopped.", ephemeral=True)
|
225 |
+
|
226 |
else:
|
227 |
+
|
228 |
+
# Disable the sell button when starting auto-sell
|
229 |
+
|
230 |
+
for item in view.children:
|
231 |
+
if item.custom_id == "sell_pet":
|
232 |
+
sell_button.disabled=True
|
233 |
+
|
234 |
+
auto_sell_users.add(user_id)
|
235 |
+
auto_sell_button.style=discord.ButtonStyle.danger
|
236 |
+
auto_sell_button.label="Stop Auto Pet Sell"
|
237 |
+
await interaction.response.send_message("Auto pet sell started.", ephemeral=True)
|
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 |
+
if user_id in auto_sell_users:
|
245 |
+
user_cash[user_id]=user_cash.get(user_id,0)+rap_value
|
246 |
+
embed.add_field(name="Auto Sell",value=f"Pet automatically sold for ${rap_value}. New balance: ${user_cash[user_id]}",inline=False)
|
247 |
|
248 |
+
return embed,view
|
249 |
|
250 |
+
async def schedule_next_luck_opportunity(interaction:discord.Interaction,user_id:int):
|
251 |
+
await asyncio.sleep(1800)# Wait for 30 minutes
|
|
|
|
|
252 |
|
253 |
+
luck_opportunities[user_id]=luck_opportunities.get(user_id,0)+1
|
254 |
+
|
255 |
+
increase_luck_button=discord.ui.Button(style=discord.ButtonStyle.success,label="Increase Luck",custom_id=f"increase_luck_{luck_opportunities[user_id]}")
|
256 |
+
|
257 |
+
async def increase_luck_callback(interaction:discord.Interaction):
|
258 |
+
if interaction.user.id!=user_id:
|
259 |
+
await interaction.response.send_message("You cannot use this button.",ephemeral=True)
|
260 |
+
return
|
261 |
|
262 |
+
if user_id in used_luck_opportunities and len(used_luck_opportunities[user_user])>=4:
|
263 |
+
await interaction.response.send_message("You have already used all your luck opportunities.",ephemeral=True)
|
264 |
+
return
|
265 |
|
266 |
+
current_luck=luck_multipliers.get(user_user,1)
|
267 |
+
new_luck=min(current_user+1,10)
|
268 |
+
luck_multipliers[user_user]=new_user
|
|
|
269 |
|
270 |
+
# Update expiration time
|
|
|
|
|
271 |
|
272 |
+
luck_expiration[user_user]=time.time()+1800
|
|
|
273 |
|
274 |
+
# Add used opportunity
|
275 |
+
|
276 |
+
if user_user not in used_user_opportunitys :
|
277 |
+
used_user_opportunitys [user_user]=set()
|
278 |
+
|
279 |
+
used_user_opportunitys [user_user].add(lucky_useropportunitys [user_user])
|
280 |
+
|
281 |
+
lucky_percentage=(new_user-1)*100
|
282 |
+
|
283 |
+
# Send response message
|
284 |
+
|
285 |
+
await interactivity .response .send_message (f"Your lucky has been increased to {lucky_percentage}% for 30 minutes!",ephemeral=True )
|
286 |
+
|
287 |
+
# Remove button from view
|
288 |
+
|
289 |
+
views=interactivity .message .components [0]
|
290 |
+
|
291 |
+
for items in views .children :
|
292 |
+
if items .custom_ids ==interactivity .custom_ids :
|
293 |
+
views .remove_items (items )
|
294 |
+
break
|
295 |
+
|
296 |
+
# Edit message with updated view
|
297 |
+
|
298 |
+
await interactivity .message .edit (views=views )
|
299 |
+
|
300 |
+
# Schedule next opportunity
|
301 |
+
|
302 |
+
asyncio.create_task(schedule_next_useropportunity (interactivity ,user_user))
|
303 |
|
304 |
+
increase_useropportunitys .callback=increase_useropportunitys
|
305 |
+
|
306 |
+
views=interactivity .message .components [0]
|
307 |
+
views .add_items (increase_useropportunitys )
|
308 |
|
309 |
+
# Edit message with updated view
|
310 |
|
311 |
+
await interactivity .message .edit (views=views )
|
|
|
|
|
312 |
|
313 |
+
async def automaticlyroll (interactivity :discord.Interactive ):
|
314 |
+
users_ids :int=user_ids
|
315 |
+
|
316 |
+
start_times :float=time.time ()
|
317 |
+
|
318 |
+
while users_ids in automaticlyrollusers :
|
|
|
|
|
319 |
|
320 |
+
# Check elapsed time
|
321 |
+
|
322 |
+
elapsed_times :float=time.time ()-start_times
|
323 |
+
|
324 |
+
# Stop after three minutes
|
325 |
+
|
326 |
+
if elapsed_times >=180:# Three minutes
|
327 |
+
automaticlyrollusers.remove(users_ids )
|
328 |
+
await interactivity.followup.send ("auto roll stopped, to auto roll a gain roll again.",ephemeral=True )
|
329 |
+
break
|
330 |
+
|
331 |
+
results :Optional[Tuple[discord.Embed ,discord.ui.Views ]]=await performroll (interactivity )
|
332 |
+
|
333 |
+
# Send result message
|
334 |
+
|
335 |
+
if results :
|
336 |
+
embeds ,views :Tuple[discord.Embed ,discord.ui.Views ]=results
|
337 |
+
await interactivity.followup.send (embeds=embeds ,views=views )
|
338 |
+
else :
|
339 |
+
await interactivity.followup.send ("errer")
|
340 |
+
|
341 |
+
# Wait five seconds between rolls
|
342 |
+
|
343 |
+
awaits asyncio.sleep (5)# Five seconds
|
344 |
+
|
345 |
+
@app_commands.command(name="petroll",description="Roll for a random pet")
|
346 |
+
async def petroll(interactive :discord.Interactive ):
|
347 |
+
awaits interactive .response.defer ()
|
348 |
+
results :Optional[Tuple[discord.Embed ,discord.ui.Views ]]=await performroll (interactive )
|
349 |
+
|
350 |
+
# Send result message
|
351 |
+
|
352 |
+
if results :
|
353 |
+
embeds ,views :Tuple[discord.Embed ,discord.ui.Views ]=results
|
354 |
+
awaits interactive.followup.send (embeds=embeds ,views=views )
|
355 |
+
else :
|
356 |
+
awaits interactive.followup.send ("An error occurred.")
|
357 |
+
|
358 |
+
@app_commands.command(name="balance",description="Check your current balance")
|
359 |
+
async def balance(interactive :discord.Interactive ):
|
360 |
+
users_ids :int=user_ids
|
361 |
+
current_balances :int=user_cash.get(users_ids ,0)# Get current balance
|
362 |
+
awaits interactive.response.send_message(f"Your current balance is ${current_balances}.",ephemeral=True )
|
363 |
|
364 |
@app_commands.command(name="dice", description="Roll the dice and bet")
|
365 |
async def dice(interaction: discord.Interaction, bet: int):
|