import discord from discord import app_commands import aiohttp import asyncio from fastapi import FastAPI import uvicorn app = FastAPI() intents = discord.Intents.default() intents.message_content = True bot = discord.Client(intents=intents) tree = app_commands.CommandTree(bot) @app.get("/") async def read_root(): return {"Hello": "World"} @tree.command(name="petsimgo", description="Get info on pets in PetsGo") 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 collection_data = await fetch_data("https://petsgo.biggamesapi.io/api/collection/Pets") if not collection_data: await interaction.followup.send("Error fetching pet data.") return matching_pets = [pet for pet in collection_data['data'] if petname.lower() in pet['configData']['name'].lower()] if not matching_pets: await interaction.followup.send(f"No pets found matching '{petname}'.") return if len(matching_pets) == 1: await show_pet_details(interaction, matching_pets[0]) else: pet_names = [pet['configData']['name'] for pet in matching_pets] embed = discord.Embed(title="Matching Pets", color=0x787878) embed.description = "\n".join(pet_names[:25]) # Limit to 25 results to avoid hitting Discord's character limit embed.set_footer(text=f"Found {len(pet_names)} matching pets. Please use a more specific name.") await interaction.followup.send(embed=embed) async def show_pet_details(interaction, pet_info): exists_data = await fetch_data("https://petsgo.biggamesapi.io/api/exists") rap_data = await fetch_data("https://petsgo.biggamesapi.io/api/Rap") pet_exists = next((p for p in exists_data['data'] if p['configData']['id'] == pet_info['configData']['id']), None) pet_rap = next((p for p in rap_data['data'] if p['configData']['id'] == pet_info['configData']['id']), None) if not pet_exists or not pet_rap: await interaction.followup.send("Error fetching detailed pet information.") 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) @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)