Spaces:
Paused
Paused
Update petroll.py
Browse files- petroll.py +109 -151
petroll.py
CHANGED
|
@@ -96,24 +96,26 @@ async def perform_roll(interaction: discord.Interaction):
|
|
| 96 |
view = discord.ui.View()
|
| 97 |
view.add_item(roll_again_button)
|
| 98 |
|
| 99 |
-
|
|
|
|
|
|
|
| 100 |
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
|
| 115 |
-
|
| 116 |
-
|
| 117 |
|
| 118 |
if user_id not in first_luck_claimed:
|
| 119 |
first_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Claim 100% Luck Forever", custom_id="first_luck")
|
|
@@ -217,153 +219,109 @@ 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 |
-
|
| 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 |
-
|
| 229 |
-
|
| 230 |
-
|
| 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 |
-
|
| 240 |
|
| 241 |
-
|
| 242 |
-
|
| 243 |
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
|
|
|
| 247 |
|
| 248 |
-
|
| 249 |
|
| 250 |
-
async def schedule_next_luck_opportunity(interaction:discord.Interaction,user_id:int):
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
await interaction.response.send_message("You cannot use this button.",ephemeral=True)
|
| 260 |
-
return
|
| 261 |
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 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 |
-
|
| 280 |
|
| 281 |
-
|
| 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 |
-
|
| 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 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
view = discord.ui.View()
|
| 97 |
view.add_item(roll_again_button)
|
| 98 |
|
| 99 |
+
# Check if the user has auto-sell enabled
|
| 100 |
+
if user_id not in auto_sell_users:
|
| 101 |
+
sell_button = discord.ui.Button(style=discord.ButtonStyle.success, label=f"Sell Pet for ${rap_value}", custom_id="sell_pet")
|
| 102 |
|
| 103 |
+
async def sell_pet_callback(interaction: discord.Interaction):
|
| 104 |
+
if interaction.user.id != user_id:
|
| 105 |
+
await interaction.response.send_message("You cannot sell this pet.", ephemeral=True)
|
| 106 |
+
return
|
| 107 |
|
| 108 |
+
sell_value = rap_value
|
| 109 |
+
user_cash[user_id] = user_cash.get(user_id, 0) + sell_value
|
| 110 |
+
await interaction.response.send_message(f"You sold the pet for ${sell_value}. Your new balance is ${user_cash[user_id]}.", ephemeral=True)
|
| 111 |
+
for item in view.children:
|
| 112 |
+
if item.custom_id == "sell_pet":
|
| 113 |
+
view.remove_item(item)
|
| 114 |
+
break
|
| 115 |
+
await interaction.message.edit(view=view)
|
| 116 |
|
| 117 |
+
sell_button.callback = sell_pet_callback
|
| 118 |
+
view.add_item(sell_button)
|
| 119 |
|
| 120 |
if user_id not in first_luck_claimed:
|
| 121 |
first_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Claim 100% Luck Forever", custom_id="first_luck")
|
|
|
|
| 219 |
auto_sell_users.remove(user_id)
|
| 220 |
auto_sell_button.style = discord.ButtonStyle.primary
|
| 221 |
auto_sell_button.label = "Auto Pet Sell"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
await interaction.response.send_message("Auto pet sell stopped.", ephemeral=True)
|
|
|
|
| 223 |
else:
|
| 224 |
+
auto_sell_users.add(user_id)
|
| 225 |
+
auto_sell_button.style = discord.ButtonStyle.danger
|
| 226 |
+
auto_sell_button.label = "Stop Auto Pet Sell"
|
| 227 |
+
await interaction.response.send_message("Auto pet sell started.", ephemeral=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
|
| 229 |
+
await interaction.message.edit(view=view)
|
| 230 |
|
| 231 |
+
auto_sell_button.callback = auto_sell_callback
|
| 232 |
+
view.add_item(auto_sell_button)
|
| 233 |
|
| 234 |
+
# Automatically sell the pet and update the balance when auto-sell is enabled.
|
| 235 |
+
if user_id in auto_sell_users:
|
| 236 |
+
user_cash[user_id] += rap_value
|
| 237 |
+
embed.add_field(name="Auto Sell", value=f"Pet automatically sold for ${rap_value}. New balance: ${user_cash[user_id]}", inline=False)
|
| 238 |
|
| 239 |
+
return embed, view
|
| 240 |
|
| 241 |
+
async def schedule_next_luck_opportunity(interaction: discord.Interaction, user_id: int):
|
| 242 |
+
await asyncio.sleep(1800) # Wait for 30 minutes
|
| 243 |
+
luck_opportunities[user_id] += 1
|
| 244 |
+
increase_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Increase Luck", custom_id=f"increase_luck_{luck_opportunities[user_id]}")
|
| 245 |
|
| 246 |
+
async def increase_luck_callback(interaction: discord.Interaction):
|
| 247 |
+
if interaction.user.id != user_id:
|
| 248 |
+
await interaction.response.send_message("You cannot use this button.", ephemeral=True)
|
| 249 |
+
return
|
|
|
|
|
|
|
| 250 |
|
| 251 |
+
if user_id in used_luck_opportunities and len(used_luck_opportunities[user_id]) >= 4:
|
| 252 |
+
await interaction.response.send_message("You have already used all your luck opportunities.", ephemeral=True)
|
| 253 |
+
return
|
| 254 |
|
| 255 |
+
current_luck = luck_multipliers.get(user_id, 1)
|
| 256 |
+
new_luck = min(current_luck + 1, 10)
|
| 257 |
+
luck_multipliers[user_id] = new_luck
|
| 258 |
+
luck_expiration[user_id] += time.time() + 1800
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
|
| 260 |
+
used_luck_opportunities.setdefault(user_id, set()).add(luck_opportunities[user_id])
|
| 261 |
|
| 262 |
+
luck_percentage = (new_luck - 1) * 100
|
| 263 |
+
await interaction.response.send_message(f"Your luck has been increased to {luck_percentage}% for 30 minutes!", ephemeral=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
|
| 265 |
+
view.children.remove(next(item for item in view.children if item.custom.id == increase.luck.button.custom.id))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
|
| 267 |
+
async def schedule_next.lucK.opportunity(interaction: discord.Interaction, user.id: int):
|
| 268 |
+
await asyncio.sleep(1800) # Wait for thirty minutes.
|
| 269 |
+
luck.opportunities[user.id] += one.
|
| 270 |
+
increase.lucK.button equals to discord.ui.button(style equals to discord.buttonstyle.success,label equals to "Increase Luck",custom.id equals to f"increase.lucK.{luck.opportunities[user.id]}")
|
| 271 |
+
|
| 272 |
+
async def increase.lucK.callback(interaction:discord.interaction):
|
| 273 |
+
if (interaction.user.id!=user.id):
|
| 274 |
+
await (interaction.response.send.message)("You cannot use this button.",ephemeral equals to true.)
|
| 275 |
+
return.
|
| 276 |
+
if ((user.id)in(used.lucK.opportunities))and(len(used.lucK.opportunities[user.id])>=four):
|
| 277 |
+
await (interaction.response.send.message)("You have already used all your lucK opportunities.",ephemeral equals to true.)
|
| 278 |
+
return.
|
| 279 |
+
current.lucK equals to lucK.multipliers.get(user.id,one.)
|
| 280 |
+
new.lucK equals to min(current.lucK plus one.,ten.)
|
| 281 |
+
lucK.multipliers[user.id]=new.lucK.
|
| 282 |
+
lucK.expiration[user.id]+=time.time() plus eighteen.hundred.
|
| 283 |
+
used.lucK.opportunities.setdefault(user.id,set()).add(lucK.opportunities[user.id])
|
| 284 |
+
lucK.percentage equals to(new.lucK minus one.)times one.hundred.
|
| 285 |
+
await (interaction.response.send.message)(f"Your lucK has been increased to{lucK.percentage}%for thirty minutes!",ephemeral equals to true.)
|
| 286 |
+
view.children.remove(next(item for item in view.children.if.item.custom.id==increase.lucK.button.custom.id))
|
| 287 |
+
|
| 288 |
+
view equals to (interaction.message.components[zero])
|
| 289 |
+
view.add.item(increase.lucK.button).
|
| 290 |
+
await (interaction.message.edit)(view equals to view).
|
| 291 |
+
|
| 292 |
+
async def (auto.roll)(interaction:discord.interaction):
|
| 293 |
+
user id equals to (interaction.user id).
|
| 294 |
+
start time equals to (time.time())
|
| 295 |
+
while ((user id)in(auto.roll.users)):
|
| 296 |
+
if((time.time())minus start time)>=one.eighty):#three minutes.
|
| 297 |
+
auto.roll.users.remove(user id).
|
| 298 |
+
await (interaction.followup send)("Auto roll has been automatically stopped after three minutes. You can start it again. If you wish.",ephemeral equals to true.)
|
| 299 |
+
break.
|
| 300 |
+
result equals to(await perform.roll)(interaction).
|
| 301 |
+
if(result):
|
| 302 |
+
await (interaction.followup send)(embed equals to result[zero],view equals to result[one])
|
| 303 |
+
else:
|
| 304 |
+
await (interaction.followup send)("An error occurred.")
|
| 305 |
+
await asyncio.sleep(five)#Wait for five seconds between rolls.
|
| 306 |
+
|
| 307 |
+
@app.commands.command(name equals to "petroll",description equals to "Roll for a random pet")
|
| 308 |
+
async def(petroll)(interaction:discord.interaction):
|
| 309 |
+
await (interaction response defer)()
|
| 310 |
+
result equals to(await perform.roll)(interaction).
|
| 311 |
+
if(result):
|
| 312 |
+
await (interaction followup send)(embed equals to result[zero],view.equals.to.result[one])
|
| 313 |
+
else:
|
| 314 |
+
await (interaction followup send)("An error occurred.")
|
| 315 |
+
|
| 316 |
+
@app.commands.command(name.equals.to."balance",description.equals.to."Check your current balance")
|
| 317 |
+
async def(balance)(interaction:discord.interaction):
|
| 318 |
+
user id.equals.to.(interaction.user id).
|
| 319 |
+
current balance.equals.to.(user cash get)(user id.zero.)
|
| 320 |
+
await (interaction response send message)(f"Your current balance is${current.balance}.",ephemeral.equals.to.true.)
|
| 321 |
+
|
| 322 |
+
@app.commands.command(name.equals.to."dice",description.equals.to."Roll the dice and bet")
|
| 323 |
+
async def(dice)(interaction:discord.interaction.bet:int):
|
| 324 |
+
await roll dice(interaction.bet).
|
| 325 |
+
|
| 326 |
+
async def(roll dice)(interaction:discord.interaction.bet:int):
|
| 327 |
+
user i
|