botbotbotbot / petroll.py
coollsd's picture
Update petroll.py
704ef6b verified
raw
history blame
15.2 kB
import discord
from discord import app_commands
import aiohttp
import random
import time
import asyncio
from cash import user_cash
luck_multipliers = {}
luck_expiration = {}
luck_opportunities = {}
used_luck_opportunities = {}
first_luck_claimed = set()
auto_roll_users = set()
auto_sell_users = set()
async def perform_roll(interaction: discord.Interaction):
async def fetch_data(url):
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
if response.status == 200:
return await response.json()
return None
rap_data = await fetch_data("https://rapapi.deno.dev/")
collection_data = await fetch_data("https://petsapi.deno.dev/")
if not rap_data or not collection_data:
return None
pets = [pet for pet in collection_data['data'] if pet['configName'] in [p['configData']['id'] for p in rap_data['data']]]
if not pets:
return None
user_id = interaction.user.id
luck_multiplier = luck_multipliers.get(user_id, 1)
sorted_pets = sorted(pets, key=lambda x: x['configData']['difficulty'])
max_index = len(sorted_pets) - 1
index = int(max_index * (luck_multiplier - 1) / 9)
rolled_pet = random.choice(sorted_pets[:index+1])
pet_rap = next((pet for pet in rap_data['data'] if pet['configData']['id'] == rolled_pet['configName']), None)
if not pet_rap:
return None
rap_value = pet_rap['value']
thumbnail_id = rolled_pet['configData']['thumbnail'].split('://')[1]
thumbnail_url = f"https://api.rbxgleaks1.workers.dev/asset/{thumbnail_id}"
def format_difficulty(difficulty):
if difficulty >= 1_000_000_000:
return f"{difficulty / 1_000_000_000:.1f}B ({difficulty:,})"
elif difficulty >= 1_000_000:
return f"{difficulty / 1_000_000:.1f}M ({difficulty:,})"
elif difficulty >= 1_000:
return f"{difficulty / 1_000:.1f}K ({difficulty:,})"
else:
return f"{difficulty} ({difficulty:,})"
embed = discord.Embed(title=f"{interaction.user.name} rolled: {rolled_pet['configData']['name']}", color=0x787878)
embed.add_field(name="Value", value=f"{rap_value:,} diamonds", inline=True)
embed.add_field(name="Difficulty", value=format_difficulty(rolled_pet['configData']['difficulty']), inline=True)
embed.add_field(name="Category", value=rolled_pet['category'], inline=True)
embed.set_thumbnail(url=thumbnail_url)
luck_text = ""
if user_id in luck_expiration:
remaining_time = int(luck_expiration[user_id] - time.time())
if remaining_time > 0:
luck_percentage = (luck_multiplier - 1) * 100
luck_text = f"\nYou have {remaining_time // 60} minutes and {remaining_time % 60} seconds of luck left! ({luck_percentage}% luck)"
else:
del luck_multipliers[user_id]
del luck_expiration[user_id]
embed.set_footer(text=f"Click 'Roll Again' to roll again!{luck_text}")
roll_again_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Roll Again", custom_id="roll_again")
async def roll_again_callback(interaction: discord.Interaction):
await interaction.response.defer()
result = await perform_roll(interaction)
if result:
await interaction.followup.send(embed=result[0], view=result[1])
else:
await interaction.followup.send("An error occurred.")
roll_again_button.callback = roll_again_callback
view = discord.ui.View()
view.add_item(roll_again_button)
# Check if the user has auto-sell enabled
if user_id not in auto_sell_users:
sell_button = discord.ui.Button(style=discord.ButtonStyle.success, label=f"Sell Pet for ${rap_value}", custom_id="sell_pet")
async def sell_pet_callback(interaction: discord.Interaction):
if interaction.user.id != user_id:
await interaction.response.send_message("You cannot sell this pet.", ephemeral=True)
return
sell_value = rap_value
user_cash[user_id] = user_cash.get(user_id, 0) + sell_value
await interaction.response.send_message(f"You sold the pet for ${sell_value}. Your new balance is ${user_cash[user_id]}.", ephemeral=True)
for item in view.children:
if item.custom_id == "sell_pet":
view.remove_item(item)
break
await interaction.message.edit(view=view)
sell_button.callback = sell_pet_callback
view.add_item(sell_button)
if user_id not in first_luck_claimed:
first_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Claim 100% Luck Forever", custom_id="first_luck")
async def first_luck_callback(interaction: discord.Interaction):
if interaction.user.id != user_id:
await interaction.response.send_message("You cannot use this button.", ephemeral=True)
return
luck_multipliers[user_id] = 10 # 100% luck
first_luck_claimed.add(user_id)
await interaction.response.send_message("You've claimed 100% luck forever!", ephemeral=True)
for item in view.children:
if item.custom_id == "first_luck":
view.remove_item(item)
break
await interaction.message.edit(view=view)
first_luck_button.callback = first_luck_callback
view.add_item(first_luck_button)
elif random.random() < 0.6 or user_id not in luck_multipliers:
luck_opportunities[user_id] = luck_opportunities.get(user_id, 0) + 1
increase_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Increase Luck", custom_id=f"increase_luck_{luck_opportunities[user_id]}")
async def increase_luck_callback(interaction: discord.Interaction):
if interaction.user.id != user_id:
await interaction.response.send_message("You cannot use this button.", ephemeral=True)
return
if user_id in used_luck_opportunities and len(used_luck_opportunities[user_id]) >= 4:
await interaction.response.send_message("You have already used all your luck opportunities.", ephemeral=True)
return
current_luck = luck_multipliers.get(user_id, 1)
new_luck = min(current_luck + 1, 10)
luck_multipliers[user_id] = new_luck
luck_expiration[user_id] = time.time() + 1800
if user_id not in used_luck_opportunities:
used_luck_opportunities[user_id] = set()
used_luck_opportunities[user_id].add(luck_opportunities[user_id])
luck_percentage = (new_luck - 1) * 100
await interaction.response.send_message(f"Your luck has been increased to {luck_percentage}% for 30 minutes!", ephemeral=True)
for item in view.children:
if item.custom_id == interaction.custom_id:
view.remove_item(item)
break
await interaction.message.edit(view=view)
# Schedule the next luck opportunity
asyncio.create_task(schedule_next_luck_opportunity(interaction, user_id))
increase_luck_button.callback = increase_luck_callback
view.add_item(increase_luck_button)
auto_roll_button = discord.ui.Button(
style=discord.ButtonStyle.primary if user_id not in auto_roll_users else discord.ButtonStyle.danger,
label="Auto Roll" if user_id not in auto_roll_users else "Stop Auto Roll",
custom_id="auto_roll"
)
async def auto_roll_callback(interaction: discord.Interaction):
if interaction.user.id != user_id:
await interaction.response.send_message("You cannot use this button.", ephemeral=True)
return
if user_id in auto_roll_users:
auto_roll_users.remove(user_id)
auto_roll_button.style = discord.ButtonStyle.primary
auto_roll_button.label = "Auto Roll"
await interaction.response.send_message("Auto roll stopped.", ephemeral=True)
else:
auto_roll_users.add(user_id)
auto_roll_button.style = discord.ButtonStyle.danger
auto_roll_button.label = "Stop Auto Roll"
await interaction.response.send_message("Auto roll started. It will automatically stop after 3 minutes.", ephemeral=True)
asyncio.create_task(auto_roll(interaction))
await interaction.message.edit(view=view)
auto_roll_button.callback = auto_roll_callback
view.add_item(auto_roll_button)
auto_sell_button = discord.ui.Button(
style=discord.ButtonStyle.primary if user_id not in auto_sell_users else discord.ButtonStyle.danger,
label="Auto Pet Sell" if user_id not in auto_sell_users else "Stop Auto Pet Sell",
custom_id="auto_pet_sell"
)
async def auto_sell_callback(interaction: discord.Interaction):
if interaction.user.id != user_id:
await interaction.response.send_message("You cannot use this button.", ephemeral=True)
return
if user_id in auto_sell_users:
auto_sell_users.remove(user_id)
auto_sell_button.style = discord.ButtonStyle.primary
auto_sell_button.label = "Auto Pet Sell"
await interaction.response.send_message("Auto pet sell stopped.", ephemeral=True)
else:
auto_sell_users.add(user_id)
auto_sell_button.style = discord.ButtonStyle.danger
auto_sell_button.label = "Stop Auto Pet Sell"
await interaction.response.send_message("Auto pet sell started.", ephemeral=True)
await interaction.message.edit(view=view)
auto_sell_button.callback = auto_sell_callback
view.add_item(auto_sell_button)
# Automatically sell the pet and update the balance when auto-sell is enabled.
if user_id in auto_sell_users:
user_cash[user_id] += rap_value
embed.add_field(name="Auto Sell", value=f"Pet automatically sold for ${rap_value}. New balance: ${user_cash[user_id]}", inline=False)
return embed, view
async def schedule_next_luck_opportunity(interaction: discord.Interaction, user_id: int):
await asyncio.sleep(1800) # Wait for 30 minutes
luck_opportunities[user_id] += 1
increase_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Increase Luck", custom_id=f"increase_luck_{luck_opportunities[user_id]}")
async def increase_luck_callback(interaction: discord.Interaction):
if interaction.user.id != user_id:
await interaction.response.send_message("You cannot use this button.", ephemeral=True)
return
if user_id in used_luck_opportunities and len(used_luck_opportunities[user_id]) >= 4:
await interaction.response.send_message("You have already used all your luck opportunities.", ephemeral=True)
return
current_luck = luck_multipliers.get(user_id, 1)
new_luck = min(current_luck + 1, 10)
luck_multipliers[user_id] = new_luck
luck_expiration[user_id] += time.time() + 1800
used_luck_opportunities.setdefault(user_id, set()).add(luck_opportunities[user_id])
luck_percentage = (new_luck - 1) * 100
await interaction.response.send_message(f"Your luck has been increased to {luck_percentage}% for 30 minutes!", ephemeral=True)
view.children.remove(next(item for item in view.children if item.custom.id == increase.luck.button.custom.id))
async def schedule_next.lucK.opportunity(interaction: discord.Interaction, user.id: int):
await asyncio.sleep(1800) # Wait for thirty minutes.
luck.opportunities[user.id] += one.
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]}")
async def increase.lucK.callback(interaction:discord.interaction):
if (interaction.user.id!=user.id):
await (interaction.response.send.message)("You cannot use this button.",ephemeral equals to true.)
return.
if ((user.id)in(used.lucK.opportunities))and(len(used.lucK.opportunities[user.id])>=four):
await (interaction.response.send.message)("You have already used all your lucK opportunities.",ephemeral equals to true.)
return.
current.lucK equals to lucK.multipliers.get(user.id,one.)
new.lucK equals to min(current.lucK plus one.,ten.)
lucK.multipliers[user.id]=new.lucK.
lucK.expiration[user.id]+=time.time() plus eighteen.hundred.
used.lucK.opportunities.setdefault(user.id,set()).add(lucK.opportunities[user.id])
lucK.percentage equals to(new.lucK minus one.)times one.hundred.
await (interaction.response.send.message)(f"Your lucK has been increased to{lucK.percentage}%for thirty minutes!",ephemeral equals to true.)
view.children.remove(next(item for item in view.children.if.item.custom.id==increase.lucK.button.custom.id))
view equals to (interaction.message.components[zero])
view.add.item(increase.lucK.button).
await (interaction.message.edit)(view equals to view).
async def (auto.roll)(interaction:discord.interaction):
user id equals to (interaction.user id).
start time equals to (time.time())
while ((user id)in(auto.roll.users)):
if((time.time())minus start time)>=one.eighty):#three minutes.
auto.roll.users.remove(user id).
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.)
break.
result equals to(await perform.roll)(interaction).
if(result):
await (interaction.followup send)(embed equals to result[zero],view equals to result[one])
else:
await (interaction.followup send)("An error occurred.")
await asyncio.sleep(five)#Wait for five seconds between rolls.
@app.commands.command(name equals to "petroll",description equals to "Roll for a random pet")
async def(petroll)(interaction:discord.interaction):
await (interaction response defer)()
result equals to(await perform.roll)(interaction).
if(result):
await (interaction followup send)(embed equals to result[zero],view.equals.to.result[one])
else:
await (interaction followup send)("An error occurred.")
@app.commands.command(name.equals.to."balance",description.equals.to."Check your current balance")
async def(balance)(interaction:discord.interaction):
user id.equals.to.(interaction.user id).
current balance.equals.to.(user cash get)(user id.zero.)
await (interaction response send message)(f"Your current balance is${current.balance}.",ephemeral.equals.to.true.)
@app.commands.command(name.equals.to."dice",description.equals.to."Roll the dice and bet")
async def(dice)(interaction:discord.interaction.bet:int):
await roll dice(interaction.bet).
async def(roll dice)(interaction:discord.interaction.bet:int):
user i