|
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) |