Update app.py
Browse files
app.py
CHANGED
@@ -1,141 +1,7 @@
|
|
1 |
-
import requests
|
2 |
-
import discord
|
3 |
-
from discord.ext import commands
|
4 |
-
import asyncio
|
5 |
from fastapi import FastAPI
|
6 |
-
import uvicorn
|
7 |
-
import os
|
8 |
|
9 |
app = FastAPI()
|
10 |
|
11 |
-
TOKEN = os.environ.get('TOKEN')
|
12 |
-
CHANNEL_ID = 1295583330951102494
|
13 |
-
|
14 |
-
api = 'https://ps99.biggamesapi.io/api/exists'
|
15 |
-
petst = [
|
16 |
-
'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',
|
17 |
-
]
|
18 |
-
|
19 |
-
pet_images = {
|
20 |
-
'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',
|
21 |
-
'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',
|
22 |
-
'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',
|
23 |
-
'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',
|
24 |
-
'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',
|
25 |
-
'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',
|
26 |
-
}
|
27 |
-
|
28 |
-
intents = discord.Intents.default()
|
29 |
-
bot = commands.Bot(command_prefix='!', intents=intents)
|
30 |
-
|
31 |
-
async def send_embed_message(channel, pet_name, previous_value, current_value, is_change=False):
|
32 |
-
pet_image_url = pet_images.get(pet_name, None)
|
33 |
-
embed = discord.Embed(
|
34 |
-
title=f"{'🚨 New Pet has been redeemed!' if is_change else 'Current Count'}",
|
35 |
-
description=f"{pet_name} has been redeemed with a serial of: **{global_serial_count}**",
|
36 |
-
color=discord.Color.blue() if not is_change else discord.Color.orange(),
|
37 |
-
)
|
38 |
-
if pet_image_url:
|
39 |
-
embed.set_thumbnail(url=pet_image_url)
|
40 |
-
await channel.send(embed=embed)
|
41 |
-
|
42 |
-
last_known_values = {
|
43 |
-
'Huge Dino Cat': 1,
|
44 |
-
'Golden Huge Dino Cat': 0,
|
45 |
-
'Rainbow Huge Dino Cat': 0,
|
46 |
-
'Shiny Huge Dino Cat': 0,
|
47 |
-
'Golden Shiny Huge Dino Cat': 0,
|
48 |
-
'Rainbow Shiny Huge Dino Cat': 0
|
49 |
-
}
|
50 |
-
|
51 |
-
global_serial_count = 1
|
52 |
-
|
53 |
-
async def petdata():
|
54 |
-
global global_serial_count
|
55 |
-
try:
|
56 |
-
response = requests.get(api)
|
57 |
-
if response.status_code == 200:
|
58 |
-
data = response.json()
|
59 |
-
if data['status'] == 'ok':
|
60 |
-
pet_values = {pet: 0 for pet in petst}
|
61 |
-
|
62 |
-
for pet in data['data']:
|
63 |
-
pet_id = pet['configData']['id']
|
64 |
-
is_shiny = pet['configData'].get('sh', False)
|
65 |
-
pet_type = pet['configData'].get('pt', None)
|
66 |
-
value = pet['value']
|
67 |
-
|
68 |
-
if pet_type == 1 and is_shiny:
|
69 |
-
pet_name = f"Golden Shiny {pet_id}"
|
70 |
-
elif pet_type == 2 and is_shiny:
|
71 |
-
pet_name = f"Rainbow Shiny {pet_id}"
|
72 |
-
elif pet_type == 1:
|
73 |
-
pet_name = f"Golden {pet_id}"
|
74 |
-
elif pet_type == 2:
|
75 |
-
pet_name = f"Rainbow {pet_id}"
|
76 |
-
elif pet_type is None:
|
77 |
-
if is_shiny:
|
78 |
-
pet_name = f"Shiny {pet_id}"
|
79 |
-
else:
|
80 |
-
pet_name = f"{pet_id}"
|
81 |
-
|
82 |
-
if pet_name in pet_values:
|
83 |
-
print(f"Found pet: {pet_name} with exist count {value}")
|
84 |
-
|
85 |
-
pet_values[pet_name] = value
|
86 |
-
|
87 |
-
if last_known_values[pet_name] != value:
|
88 |
-
global_serial_count += 1
|
89 |
-
serial_number = global_serial_count
|
90 |
-
|
91 |
-
print(f"New redemption detected for {pet_name}. Incremented serial to {serial_number}")
|
92 |
-
|
93 |
-
last_known_values[pet_name] = value
|
94 |
-
|
95 |
-
return pet_values
|
96 |
-
print(f"Error code: {response.status_code}")
|
97 |
-
except Exception as e:
|
98 |
-
print(f"Error: {e}")
|
99 |
-
return None
|
100 |
-
|
101 |
-
async def main_loop():
|
102 |
-
lastknown = {pet: None for pet in petst}
|
103 |
-
channel = bot.get_channel(CHANNEL_ID)
|
104 |
-
if channel is None:
|
105 |
-
print("Invalid channel ID. Please check your channel ID.")
|
106 |
-
return
|
107 |
-
|
108 |
-
while True:
|
109 |
-
vvalues = await petdata()
|
110 |
-
if vvalues is not None:
|
111 |
-
for pet, value in vvalues.items():
|
112 |
-
if lastknown[pet] is None:
|
113 |
-
print(pet, value)
|
114 |
-
elif value != lastknown[pet]:
|
115 |
-
await send_embed_message(channel, pet, lastknown[pet], value, is_change=True)
|
116 |
-
lastknown[pet] = value
|
117 |
-
else:
|
118 |
-
print("Broken check")
|
119 |
-
await asyncio.sleep(60)
|
120 |
-
|
121 |
-
@bot.event
|
122 |
-
async def on_ready():
|
123 |
-
print(f'Logged in as {bot.user.name}')
|
124 |
-
bot.loop.create_task(main_loop())
|
125 |
-
|
126 |
@app.get("/")
|
127 |
-
async def
|
128 |
-
return {"
|
129 |
-
|
130 |
-
async def run_bot():
|
131 |
-
await bot.start(TOKEN)
|
132 |
-
|
133 |
-
@app.on_event("startup")
|
134 |
-
async def startup_event():
|
135 |
-
asyncio.create_task(run_bot())
|
136 |
-
|
137 |
-
if __name__ == "__main__":
|
138 |
-
print("===== Application Startup =====")
|
139 |
-
print(f"FastAPI running on http://0.0.0.0:7860")
|
140 |
-
print("Discord bot starting...")
|
141 |
-
uvicorn.run("main:app", host="0.0.0.0", port=7860)
|
|
|
|
|
|
|
|
|
|
|
1 |
from fastapi import FastAPI
|
|
|
|
|
2 |
|
3 |
app = FastAPI()
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
@app.get("/")
|
6 |
+
async def root():
|
7 |
+
return {"message": "Hello World"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|