File size: 6,126 Bytes
8323479 75abeb6 8323479 75abeb6 8323479 |
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 |
import requests
import discord
from discord.ext import commands
import asyncio
from fastapi import FastAPI
import uvicorn
import os
app = FastAPI()
TOKEN = os.environ.get('TOKEN')
CHANNEL_ID = 1295583330951102494
api = 'https://ps99.biggamesapi.io/api/exists'
petst = [
'Huge Dino Cat', 'Golden Huge Dino Cat', 'Rainbow Huge Dino Cat', 'Shiny Huge Dino Cat', 'Golden Shiny Huge Dino Cat', 'Rainbow Shiny Huge Dino Cat',
]
pet_images = {
'Huge Dino Cat': 'https://media.discordapp.net/attachments/1295832789534507089/1296209703172313178/14976397288.png?ex=671174db&is=6710235b&hm=079d37b0492d2b6451572a4a6a7c8c3721666d08415bbe956c170024aeae3c98&=&format=webp&quality=lossless&width=224&height=224',
'Golden Huge Dino Cat': 'https://media.discordapp.net/attachments/1295832789534507089/1296209702220206080/14976397095.png?ex=671174db&is=6710235b&hm=43909eb7906ce13f1d385675021e7d5d0301cde26303a957a0a8a7066cf7cca3&=&format=webp&quality=lossless&width=224&height=224',
'Rainbow Huge Dino Cat': 'https://media.discordapp.net/attachments/1295832789534507089/1296209702912528485/rb_dino.png?ex=671174db&is=6710235b&hm=ad5c03bc4ce8a7a187c6e996f179e79d2b780f6e95e836bb91ac41b14510d836&=&format=webp&quality=lossless&width=224&height=224',
'Shiny Huge Dino Cat': 'https://media.discordapp.net/attachments/1295832789534507089/1296209702572523583/shiny_dino.png?ex=671174db&is=6710235b&hm=0ba086e9cc24dc7b46fac01495ca07f6b5df0b34b5399ae7b5c3e9142c9cddf1&=&format=webp&quality=lossless&width=224&height=224',
'Golden Shiny Huge Dino Cat': 'https://media.discordapp.net/attachments/1295832789534507089/1296209701956096121/golden_shiny_dino.png?ex=671174db&is=6710235b&hm=233838fe44924ae59b72c320a2086afbadfa38a84890289e574daca84e119bc5&=&format=webp&quality=lossless&width=224&height=224',
'Rainbow Shiny Huge Dino Cat': 'https://media.discordapp.net/attachments/1295832789534507089/1296209701653975090/rb_shiny_din.png?ex=671174db&is=6710235b&hm=c81ecefdb06ddcf21c79493606bf37ad5bd4cba4c23ffa5f215f2c29aaec7293&=&format=webp&quality=lossless&width=224&height=224',
}
intents = discord.Intents.default()
bot = commands.Bot(command_prefix='!', intents=intents)
async def send_embed_message(channel, pet_name, previous_value, current_value, is_change=False):
pet_image_url = pet_images.get(pet_name, None)
embed = discord.Embed(
title=f"{'🚨 New Pet has been redeemed!' if is_change else 'Current Count'}",
description=f"{pet_name} has been redeemed with a serial of: **{global_serial_count}**",
color=discord.Color.blue() if not is_change else discord.Color.orange(),
)
if pet_image_url:
embed.set_thumbnail(url=pet_image_url)
await channel.send(embed=embed)
last_known_values = {
'Huge Dino Cat': 1,
'Golden Huge Dino Cat': 0,
'Rainbow Huge Dino Cat': 0,
'Shiny Huge Dino Cat': 0,
'Golden Shiny Huge Dino Cat': 0,
'Rainbow Shiny Huge Dino Cat': 0
}
global_serial_count = 1
async def petdata():
global global_serial_count
try:
response = requests.get(api)
if response.status_code == 200:
data = response.json()
if data['status'] == 'ok':
pet_values = {pet: 0 for pet in petst}
for pet in data['data']:
pet_id = pet['configData']['id']
is_shiny = pet['configData'].get('sh', False)
pet_type = pet['configData'].get('pt', None)
value = pet['value']
if pet_type == 1 and is_shiny:
pet_name = f"Golden Shiny {pet_id}"
elif pet_type == 2 and is_shiny:
pet_name = f"Rainbow Shiny {pet_id}"
elif pet_type == 1:
pet_name = f"Golden {pet_id}"
elif pet_type == 2:
pet_name = f"Rainbow {pet_id}"
elif pet_type is None:
if is_shiny:
pet_name = f"Shiny {pet_id}"
else:
pet_name = f"{pet_id}"
if pet_name in pet_values:
print(f"Found pet: {pet_name} with exist count {value}")
pet_values[pet_name] = value
if last_known_values[pet_name] != value:
global_serial_count += 1
serial_number = global_serial_count
print(f"New redemption detected for {pet_name}. Incremented serial to {serial_number}")
last_known_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():
lastknown = {pet: None for pet in petst}
channel = bot.get_channel(CHANNEL_ID)
if channel is None:
print("Invalid channel ID. Please check your channel ID.")
return
while True:
vvalues = await petdata()
if vvalues is not None:
for pet, value in vvalues.items():
if lastknown[pet] is None:
print(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")
await asyncio.sleep(60)
@bot.event
async def on_ready():
print(f'Logged in as {bot.user.name}')
bot.loop.create_task(main_loop())
@app.get("/")
async def read_root():
return {"Hello": "World"}
async def run_bot():
await bot.start(TOKEN)
@app.on_event("startup")
async def startup_event():
asyncio.create_task(run_bot())
if __name__ == "__main__":
print("===== Application Startup =====")
print(f"FastAPI running on http://0.0.0.0:7860")
print("Discord bot starting...")
uvicorn.run("main:app", host="0.0.0.0", port=7860) |