File size: 9,422 Bytes
d637aca 8168f57 d89b8e6 b9d31a9 d89b8e6 b9d31a9 8168f57 08da534 8168f57 b9d31a9 a704ac7 857686a 8168f57 5daa4cf 8168f57 b9d31a9 8168f57 b9d31a9 8168f57 d89b8e6 b9d31a9 857686a b9d31a9 857686a b9d31a9 07f5a87 b9d31a9 d89b8e6 8168f57 857686a b9d31a9 857686a 07f5a87 857686a 07f5a87 857686a b9d31a9 d89b8e6 b9d31a9 d89b8e6 b9d31a9 857686a b9d31a9 7d33bf6 b9d31a9 d89b8e6 b9d31a9 d89b8e6 857686a d89b8e6 857686a d89b8e6 857686a d89b8e6 b9d31a9 857686a b9d31a9 d89b8e6 07f5a87 8168f57 857686a 7d33bf6 857686a b9d31a9 7d33bf6 b9d31a9 857686a d89b8e6 8168f57 07f5a87 8168f57 81a1ac8 8168f57 07f5a87 81a1ac8 8168f57 |
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 |
import os
import requests
import discord
from discord.ext import commands
import asyncio
import re
from datetime import datetime, timedelta
from collections import defaultdict
from aiohttp import web
# Create web app
app = web.Application()
async def hello(request):
return web.Response(text="Hello World")
app.router.add_get('/', hello)
TOKEN = os.environ.get('token')
# Discord bot setup
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix='!', intents=intents)
CHANNEL_ID = 1298830206387228682
PETS_API = 'https://petsapi.deno.dev/'
EXISTS_API = 'https://existsapi.deno.dev/'
RAP_API = 'https://rapapi.deno.dev/'
pet_images = {}
pet_difficulties = {}
pet_raps = {}
hourly_hatches = defaultdict(list)
async def update_rap_values():
try:
response = requests.get(RAP_API)
if response.status_code == 200:
data = response.json()
if data['status'] == 'ok':
pet_raps.clear()
for pet_data in data['data']:
config_data = pet_data['configData']
pet_id = config_data['id']
value = pet_data['value']
is_shiny = config_data.get('sh', False)
if is_shiny:
pet_raps[f"Shiny {pet_id}"] = value
else:
pet_raps[pet_id] = value
print(f"Updated RAP values for {len(data['data'])} pets")
except Exception as e:
print(f"Error fetching RAP values: {e}")
async def get_huge_secret_pets():
try:
response = requests.get(PETS_API)
if response.status_code == 200:
data = response.json()
if data['status'] == 'ok':
huge_secret_pets = []
for pet in data['data']:
config_data = pet['configData']
if config_data.get('huge') or config_data.get('secret'):
pet_name = config_data['name']
huge_secret_pets.append(pet_name)
huge_secret_pets.append(f"Shiny {pet_name}")
difficulty = config_data.get('difficulty', 'Unknown')
pet_difficulties[pet_name] = difficulty
pet_difficulties[f"Shiny {pet_name}"] = difficulty * 100
if 'thumbnail' in config_data:
pet_images[pet_name] = config_data['thumbnail']
pet_images[f"Shiny {pet_name}"] = config_data['thumbnail']
print(f"Found {len(huge_secret_pets)} pets to track (including shiny versions)")
return huge_secret_pets
except Exception as e:
print(f"Error fetching pets list: {e}")
return []
async def send_embed_message(channel, pet_name, previous_value, current_value, is_change=False):
if is_change and current_value > previous_value:
hatches = current_value - previous_value
for _ in range(hatches):
hourly_hatches[pet_name].append(datetime.now())
pet_image_url = pet_images.get(pet_name, None)
difficulty = pet_difficulties.get(pet_name, "Unknown")
rap_value = pet_raps.get(pet_name, "No RAP")
if isinstance(rap_value, (int, float)):
rap_display = f"{rap_value:,}"
else:
rap_display = rap_value
if isinstance(difficulty, (int, float)):
difficulty_display = f"{difficulty:,}"
else:
difficulty_display = difficulty
if isinstance(current_value, (int, float)):
current_display = f"{current_value:,}"
else:
current_display = current_value
if isinstance(previous_value, (int, float)):
previous_display = f"{previous_value:,}"
else:
previous_display = previous_value
embed = discord.Embed(
title=f"π² A {pet_name} was rolled! π²",
description=f"{pet_name} exists: **{current_display}**\nDifficulty: **1 in {difficulty_display}**\nRAP Value: **{rap_display}**",
color=discord.Color.blue() if not is_change else discord.Color.orange(),
)
if pet_image_url:
if isinstance(pet_image_url, str):
if pet_image_url.startswith('rbxassetid://'):
asset_id = pet_image_url.replace('rbxassetid://', '')
asset_id = re.search(r'^\d+', asset_id).group(0)
pet_image_url = f"https://rbxgleaks.pythonanywhere.com/asset/{asset_id}"
print(f"Using image URL for {pet_name}: {pet_image_url}")
embed.set_thumbnail(url=pet_image_url)
try:
await channel.send(embed=embed)
except discord.HTTPException as e:
print(f"Failed to send embed for {pet_name}: {e}")
await channel.send(f"π² A {pet_name} was rolled! Exists: {current_display} (Previous: {previous_display})")
async def petdata(tracked_pets):
try:
response = requests.get(EXISTS_API)
if response.status_code == 200:
data = response.json()
if data['status'] == 'ok':
pet_values = {pet: 0 for pet in tracked_pets}
for pet in data['data']:
pet_id = pet['configData']['id']
is_shiny = pet['configData'].get('sh', False)
value = pet['value']
pet_name = f"Shiny {pet_id}" if is_shiny else pet_id
if pet_name in pet_values:
print(f"Found pet: {pet_name} with exist count {value}")
pet_values[pet_name] = value
return pet_values
print(f"Error code: {response.status_code}")
except Exception as e:
print(f"Error: {e}")
return None
async def main_loop():
channel = bot.get_channel(CHANNEL_ID)
if channel is None:
print("Invalid channel ID. Please check your channel ID.")
return
tracked_pets = await get_huge_secret_pets()
lastknown = {pet: None for pet in tracked_pets}
print(f"Initially tracking {len(tracked_pets)} pets")
while True:
cleanup_old_hatches()
if not tracked_pets:
tracked_pets = await get_huge_secret_pets()
lastknown.update({pet: None for pet in tracked_pets if pet not in lastknown})
await update_rap_values()
vvalues = await petdata(tracked_pets)
if vvalues is not None:
for pet, value in vvalues.items():
if lastknown[pet] is None:
print(f"Initial value for {pet}: {value}")
elif value != lastknown[pet]:
await send_embed_message(channel, pet, lastknown[pet], value, is_change=True)
lastknown[pet] = value
else:
print("Broken check")
if len(tracked_pets) > 0:
new_pets = await get_huge_secret_pets()
if set(new_pets) != set(tracked_pets):
print("Pet list updated!")
tracked_pets = new_pets
lastknown.update({pet: None for pet in tracked_pets if pet not in lastknown})
await asyncio.sleep(60)
def cleanup_old_hatches():
one_hour_ago = datetime.now() - timedelta(hours=1)
for pet in hourly_hatches:
hourly_hatches[pet] = [timestamp for timestamp in hourly_hatches[pet]
if timestamp > one_hour_ago]
@bot.command(name='lasthour')
async def last_hour_stats(ctx):
cleanup_old_hatches()
if not hourly_hatches:
await ctx.send("No pets have been hatched in the last hour.")
return
total_hatches = sum(len(hatches) for hatches in hourly_hatches.values())
embed = discord.Embed(
title="π Last Hour Hatch Statistics π",
description=f"Total hatches in the last hour: **{total_hatches}**",
color=discord.Color.green()
)
sorted_pets = sorted(
hourly_hatches.items(),
key=lambda x: len(x[1]),
reverse=True
)
for pet_name, hatches in sorted_pets:
if hatches:
count = len(hatches)
difficulty = pet_difficulties.get(pet_name, "Unknown")
rap_value = pet_raps.get(pet_name, "No RAP")
if isinstance(rap_value, (int, float)):
rap_display = f"{rap_value:,}"
else:
rap_display = rap_value
if isinstance(difficulty, (int, float)):
difficulty_display = f"{difficulty:,}"
else:
difficulty_display = difficulty
embed.add_field(
name=pet_name,
value=f"Hatches: **{count}**\nDifficulty: 1 in {difficulty_display}\nRAP: {rap_display}",
inline=True
)
embed.set_footer(text=f"Last updated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
await ctx.send(embed=embed)
@bot.event
async def on_ready():
print(f'Logged in as {bot.user.name}')
bot.loop.create_task(main_loop())
runner = web.AppRunner(app)
await runner.setup()
site = web.TCPSite(runner, '0.0.0.0', 7860)
await site.start()
print(f"Web server started on port 7860")
def run_bot():
bot.run(TOKEN)
if __name__ == "__main__":
run_bot() |