Spaces:
Building
Building
File size: 11,808 Bytes
8067274 e306b36 68c299b ddc70fe 8067274 e306b36 8067274 ddc70fe 715b5f9 fe6a770 ddc70fe e306b36 4b66121 8067274 4b66121 8067274 4b66121 68c299b 3bc9cf3 4b66121 3bc9cf3 4b66121 8067274 4b66121 8067274 4b66121 8067274 4b66121 8067274 0b9b12e 68c299b 0b9b12e 68c299b 0b9b12e 68c299b ddc70fe a935b4b 01be262 8f50208 f7609fd 7708c7e 8f50208 1cc1637 68c299b 0b9b12e 68c299b ddc70fe 68c299b ddc70fe 8f50208 f7609fd ddc70fe 68c299b ddc70fe 68c299b acb36ac 0b9b12e 01be262 68c299b 715b5f9 ddc70fe fd8f27d a935b4b fd8f27d d8a441d f7609fd d8a441d f7609fd d8a441d f7609fd 715b5f9 ddc70fe 0b9b12e 68c299b 8e6a929 fe6a770 8e6a929 fe6a770 7ab4e04 fe6a770 7ab4e04 fe6a770 7ab4e04 fe6a770 7ab4e04 fe6a770 7ab4e04 fe6a770 8e6a929 8067274 e306b36 d1838af e306b36 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
import discord
from discord import app_commands
import aiohttp
import asyncio
from fastapi import FastAPI
import uvicorn
import random
import time
app = FastAPI()
intents = discord.Intents.default()
intents.message_content = True
bot = discord.Client(intents=intents)
tree = app_commands.CommandTree(bot)
luck_multipliers = {}
luck_expiration = {}
luck_opportunities = {}
user_cash = {}
@app.get("/")
async def read_root():
return {"Hello": "World"}
@tree.command(name="petsimgo", description="get info on pet on petsgo u")
async def petsimgo(interaction: discord.Interaction, petname: str):
await interaction.response.defer()
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
exists_data = await fetch_data("https://petsgo.biggamesapi.io/api/exists")
rap_data = await fetch_data("https://petsgo.biggamesapi.io/api/Rap")
collection_data = await fetch_data("https://petsgo.biggamesapi.io/api/collection/Pets")
if not exists_data or not rap_data or not collection_data:
await interaction.followup.send("error")
return
pet_exists = next((pet for pet in exists_data['data'] if pet['configData']['id'].lower() == petname.lower()), None)
pet_rap = next((pet for pet in rap_data['data'] if pet['configData']['id'].lower() == petname.lower()), None)
pet_info = next((pet for pet in collection_data['data'] if pet['configName'].lower() == petname.lower()), None)
if not pet_exists or not pet_rap or not pet_info:
await interaction.followup.send(f"Pet '{petname}' not found.")
return
exists_value = pet_exists['value']
rap_value = pet_rap['value']
thumbnail_id = pet_info['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"PetsGo: {pet_info['configData']['name']}", color=0x787878)
embed.add_field(name="value", value=f"{rap_value:,} diamonds", inline=True)
embed.add_field(name="existing", value=f"{exists_value:,}", inline=True)
embed.add_field(name="difficulty", value=format_difficulty(pet_info['configData']['difficulty']), inline=True)
embed.add_field(name="category", value=pet_info['category'], inline=True)
embed.set_thumbnail(url=thumbnail_url)
embed.set_footer(text="hello everyone can i please get a burrito now")
await interaction.followup.send(embed=embed)
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://petsgo.biggamesapi.io/api/Rap")
collection_data = await fetch_data("https://petsgo.biggamesapi.io/api/collection/Pets")
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("errer.")
roll_again_button.callback = roll_again_callback
view = discord.ui.View()
view.add_item(roll_again_button)
if random.random() < 0.2:
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("cannot use", 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
luck_percentage = (new_luck - 1) * 100
await interaction.response.send_message(f"luck 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)
increase_luck_button.callback = increase_luck_callback
view.add_item(increase_luck_button)
return embed, view
@tree.command(name="petroll", description="Roll for a random pet")
async def petroll(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("errer")
@tree.command(name="cash", description="Check your current cash balance or claim free cash")
async def cash(interaction: discord.Interaction):
user_id = interaction.user.id
balance = user_cash.get(user_id, 0)
if balance == 0:
user_cash[user_id] = 100
balance = 100
message = "You've claimed your free $100! Your current balance is $100.00"
else:
message = f"Your current balance is ${balance:.2f}"
embed = discord.Embed(title="Cash Balance", description=message, color=0x00ff00)
embed.set_footer(text="Use /dice to bet your cash!")
await interaction.response.send_message(embed=embed)
@tree.command(name="dice", description="Roll the dice and bet")
async def dice(interaction: discord.Interaction, bet: int):
user_id = interaction.user.id
balance = user_cash.get(user_id, 0)
if bet <= 0:
await interaction.response.send_message("Your bet must be greater than 0.")
return
if bet > balance:
await interaction.response.send_message(f"You don't have enough cash. Your current balance is ${balance:.2f}")
return
embed = discord.Embed(title="Dice Roll", description=f"{interaction.user.name} is betting ${bet:.2f}", color=0x00ff00)
embed.add_field(name="Current Balance", value=f"${balance:.2f}", inline=False)
roll_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Roll the Dice", custom_id="roll_dice")
async def roll_dice_callback(interaction: discord.Interaction):
nonlocal balance
result = random.choice(["win", "lose"])
if result == "win":
winnings = bet
balance += winnings
result_text = f"You won ${winnings:.2f}!"
else:
balance -= bet
result_text = f"You lost ${bet:.2f}."
user_cash[user_id] = balance
embed.clear_fields()
embed.add_field(name="Result", value=result_text, inline=False)
embed.add_field(name="New Balance", value=f"${balance:.2f}", inline=False)
roll_again_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Roll Again", custom_id="roll_again")
roll_again_button.callback = lambda i: dice(i, bet)
new_view = discord.ui.View()
new_view.add_item(roll_again_button)
await interaction.response.edit_message(embed=embed, view=new_view)
roll_button.callback = roll_dice_callback
view = discord.ui.View()
view.add_item(roll_button)
await interaction.response.send_message(embed=embed, view=view)
@tree.command(name="admincash", description="Admin command to add cash to a specific user")
async def admincash(interaction: discord.Interaction, user: discord.User, amount: int):
if interaction.user.id != 696434794174611477:
await interaction.response.send_message("You are not authorized to use this command.", ephemeral=True)
return
user_cash[user.id] = user_cash.get(user.id, 0) + amount
new_balance = user_cash[user.id]
embed = discord.Embed(title="Admin Cash Added", description=f"Added ${amount:.2f} to {user.name}'s balance", color=0x00ff00)
embed.add_field(name="New Balance", value=f"${new_balance:.2f}", inline=False)
await interaction.response.send_message(embed=embed)
@bot.event
async def on_ready():
await tree.sync()
print(f"{bot.user} is now online!")
async def run_bot():
await bot.start("MTI5MjkxMDYzMjg3MzQ5MjU4Mw.GbVmvy.8kEhPZyNLrACzBWYEorT7UqNRME7gp6Lvz6lg8")
@app.on_event("startup")
async def startup_event():
asyncio.create_task(run_bot())
if __name__ == "__main__":
uvicorn.run("app:app", host="0.0.0.0", port=7860) |