coollsd commited on
Commit
07f5a87
·
verified ·
1 Parent(s): d637aca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -43
app.py CHANGED
@@ -33,29 +33,22 @@ pet_difficulties = {}
33
  pet_raps = {}
34
  hourly_hatches = defaultdict(list)
35
 
36
- # [Previous functions remain exactly the same]
37
  async def update_rap_values():
38
  try:
39
  response = requests.get(RAP_API)
40
  if response.status_code == 200:
41
  data = response.json()
42
  if data['status'] == 'ok':
43
- # Clear existing RAP values
44
  pet_raps.clear()
45
-
46
- # Process each pet in the list
47
  for pet_data in data['data']:
48
  config_data = pet_data['configData']
49
  pet_id = config_data['id']
50
  value = pet_data['value']
51
-
52
- # Check if it's a shiny pet
53
  is_shiny = config_data.get('sh', False)
54
  if is_shiny:
55
  pet_raps[f"Shiny {pet_id}"] = value
56
  else:
57
  pet_raps[pet_id] = value
58
-
59
  print(f"Updated RAP values for {len(data['data'])} pets")
60
  except Exception as e:
61
  print(f"Error fetching RAP values: {e}")
@@ -67,37 +60,26 @@ async def get_huge_secret_pets():
67
  data = response.json()
68
  if data['status'] == 'ok':
69
  huge_secret_pets = []
70
-
71
  for pet in data['data']:
72
  config_data = pet['configData']
73
  if config_data.get('huge') or config_data.get('secret'):
74
  pet_name = config_data['name']
75
  huge_secret_pets.append(pet_name)
76
  huge_secret_pets.append(f"Shiny {pet_name}")
77
-
78
- # Store difficulty value
79
  difficulty = config_data.get('difficulty', 'Unknown')
80
  pet_difficulties[pet_name] = difficulty
81
- # Shiny pets are 100x harder
82
  pet_difficulties[f"Shiny {pet_name}"] = difficulty * 100
83
-
84
  if 'thumbnail' in config_data:
85
  pet_images[pet_name] = config_data['thumbnail']
86
  pet_images[f"Shiny {pet_name}"] = config_data['thumbnail']
87
- print(f"Stored image URL for {pet_name}: {config_data['thumbnail']}")
88
-
89
  print(f"Found {len(huge_secret_pets)} pets to track (including shiny versions)")
90
  return huge_secret_pets
91
- else:
92
- print("API response status not OK")
93
- return []
94
  except Exception as e:
95
  print(f"Error fetching pets list: {e}")
96
- return []
97
 
98
  async def send_embed_message(channel, pet_name, previous_value, current_value, is_change=False):
99
  if is_change and current_value > previous_value:
100
- # Record hatch timestamp when a new pet is detected
101
  hatches = current_value - previous_value
102
  for _ in range(hatches):
103
  hourly_hatches[pet_name].append(datetime.now())
@@ -106,24 +88,21 @@ async def send_embed_message(channel, pet_name, previous_value, current_value, i
106
  difficulty = pet_difficulties.get(pet_name, "Unknown")
107
  rap_value = pet_raps.get(pet_name, "No RAP")
108
 
109
- # Format RAP value with commas
110
  if isinstance(rap_value, (int, float)):
111
  rap_display = f"{rap_value:,}"
112
  else:
113
  rap_display = rap_value
114
 
115
- # Format difficulty with commas
116
  if isinstance(difficulty, (int, float)):
117
  difficulty_display = f"{difficulty:,}"
118
  else:
119
  difficulty_display = difficulty
120
-
121
- # Format exist counts with commas
122
  if isinstance(current_value, (int, float)):
123
  current_display = f"{current_value:,}"
124
  else:
125
  current_display = current_value
126
-
127
  if isinstance(previous_value, (int, float)):
128
  previous_display = f"{previous_value:,}"
129
  else:
@@ -141,7 +120,6 @@ async def send_embed_message(channel, pet_name, previous_value, current_value, i
141
  asset_id = pet_image_url.replace('rbxassetid://', '')
142
  asset_id = re.search(r'^\d+', asset_id).group(0)
143
  pet_image_url = f"https://rbxgleaks.pythonanywhere.com/asset/{asset_id}"
144
-
145
  print(f"Using image URL for {pet_name}: {pet_image_url}")
146
  embed.set_thumbnail(url=pet_image_url)
147
 
@@ -158,17 +136,14 @@ async def petdata(tracked_pets):
158
  data = response.json()
159
  if data['status'] == 'ok':
160
  pet_values = {pet: 0 for pet in tracked_pets}
161
-
162
  for pet in data['data']:
163
  pet_id = pet['configData']['id']
164
  is_shiny = pet['configData'].get('sh', False)
165
  value = pet['value']
166
-
167
  pet_name = f"Shiny {pet_id}" if is_shiny else pet_id
168
  if pet_name in pet_values:
169
  print(f"Found pet: {pet_name} with exist count {value}")
170
  pet_values[pet_name] = value
171
-
172
  return pet_values
173
  print(f"Error code: {response.status_code}")
174
  except Exception as e:
@@ -186,9 +161,8 @@ async def main_loop():
186
  print(f"Initially tracking {len(tracked_pets)} pets")
187
 
188
  while True:
189
- cleanup_old_hatches() # Clean up old hatch records periodically
190
 
191
- # [Rest of the main_loop function remains the same]
192
  if not tracked_pets:
193
  tracked_pets = await get_huge_secret_pets()
194
  lastknown.update({pet: None for pet in tracked_pets if pet not in lastknown})
@@ -216,7 +190,6 @@ async def main_loop():
216
  await asyncio.sleep(60)
217
 
218
  def cleanup_old_hatches():
219
- """Remove hatch records older than 1 hour"""
220
  one_hour_ago = datetime.now() - timedelta(hours=1)
221
  for pet in hourly_hatches:
222
  hourly_hatches[pet] = [timestamp for timestamp in hourly_hatches[pet]
@@ -224,7 +197,6 @@ def cleanup_old_hatches():
224
 
225
  @bot.command(name='lasthour')
226
  async def last_hour_stats(ctx):
227
- """Command to show hatching statistics for the last hour"""
228
  cleanup_old_hatches()
229
 
230
  if not hourly_hatches:
@@ -239,7 +211,6 @@ async def last_hour_stats(ctx):
239
  color=discord.Color.green()
240
  )
241
 
242
- # Sort pets by number of hatches (descending)
243
  sorted_pets = sorted(
244
  hourly_hatches.items(),
245
  key=lambda x: len(x[1]),
@@ -247,12 +218,11 @@ async def last_hour_stats(ctx):
247
  )
248
 
249
  for pet_name, hatches in sorted_pets:
250
- if hatches: # Only show pets that were hatched
251
  count = len(hatches)
252
  difficulty = pet_difficulties.get(pet_name, "Unknown")
253
  rap_value = pet_raps.get(pet_name, "No RAP")
254
 
255
- # Format values with commas
256
  if isinstance(rap_value, (int, float)):
257
  rap_display = f"{rap_value:,}"
258
  else:
@@ -269,22 +239,15 @@ async def last_hour_stats(ctx):
269
  inline=True
270
  )
271
 
272
- # Add timestamp
273
  embed.set_footer(text=f"Last updated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
274
 
275
  await ctx.send(embed=embed)
276
 
277
- @bot.event
278
- async def on_ready():
279
- print(f'Logged in as {bot.user.name}')
280
- bot.loop.create_task(main_loop())
281
-
282
  @bot.event
283
  async def on_ready():
284
  print(f'Logged in as {bot.user.name}')
285
  bot.loop.create_task(main_loop())
286
 
287
- # Start the web server
288
  runner = web.AppRunner(app)
289
  await runner.setup()
290
  site = web.TCPSite(runner, '0.0.0.0', 7860)
@@ -292,7 +255,7 @@ async def on_ready():
292
  print(f"Web server started on port 7860")
293
 
294
  def run_bot():
295
- bot.run(token)
296
 
297
  if __name__ == "__main__":
298
  run_bot()
 
33
  pet_raps = {}
34
  hourly_hatches = defaultdict(list)
35
 
 
36
  async def update_rap_values():
37
  try:
38
  response = requests.get(RAP_API)
39
  if response.status_code == 200:
40
  data = response.json()
41
  if data['status'] == 'ok':
 
42
  pet_raps.clear()
 
 
43
  for pet_data in data['data']:
44
  config_data = pet_data['configData']
45
  pet_id = config_data['id']
46
  value = pet_data['value']
 
 
47
  is_shiny = config_data.get('sh', False)
48
  if is_shiny:
49
  pet_raps[f"Shiny {pet_id}"] = value
50
  else:
51
  pet_raps[pet_id] = value
 
52
  print(f"Updated RAP values for {len(data['data'])} pets")
53
  except Exception as e:
54
  print(f"Error fetching RAP values: {e}")
 
60
  data = response.json()
61
  if data['status'] == 'ok':
62
  huge_secret_pets = []
 
63
  for pet in data['data']:
64
  config_data = pet['configData']
65
  if config_data.get('huge') or config_data.get('secret'):
66
  pet_name = config_data['name']
67
  huge_secret_pets.append(pet_name)
68
  huge_secret_pets.append(f"Shiny {pet_name}")
 
 
69
  difficulty = config_data.get('difficulty', 'Unknown')
70
  pet_difficulties[pet_name] = difficulty
 
71
  pet_difficulties[f"Shiny {pet_name}"] = difficulty * 100
 
72
  if 'thumbnail' in config_data:
73
  pet_images[pet_name] = config_data['thumbnail']
74
  pet_images[f"Shiny {pet_name}"] = config_data['thumbnail']
 
 
75
  print(f"Found {len(huge_secret_pets)} pets to track (including shiny versions)")
76
  return huge_secret_pets
 
 
 
77
  except Exception as e:
78
  print(f"Error fetching pets list: {e}")
79
+ return []
80
 
81
  async def send_embed_message(channel, pet_name, previous_value, current_value, is_change=False):
82
  if is_change and current_value > previous_value:
 
83
  hatches = current_value - previous_value
84
  for _ in range(hatches):
85
  hourly_hatches[pet_name].append(datetime.now())
 
88
  difficulty = pet_difficulties.get(pet_name, "Unknown")
89
  rap_value = pet_raps.get(pet_name, "No RAP")
90
 
 
91
  if isinstance(rap_value, (int, float)):
92
  rap_display = f"{rap_value:,}"
93
  else:
94
  rap_display = rap_value
95
 
 
96
  if isinstance(difficulty, (int, float)):
97
  difficulty_display = f"{difficulty:,}"
98
  else:
99
  difficulty_display = difficulty
100
+
 
101
  if isinstance(current_value, (int, float)):
102
  current_display = f"{current_value:,}"
103
  else:
104
  current_display = current_value
105
+
106
  if isinstance(previous_value, (int, float)):
107
  previous_display = f"{previous_value:,}"
108
  else:
 
120
  asset_id = pet_image_url.replace('rbxassetid://', '')
121
  asset_id = re.search(r'^\d+', asset_id).group(0)
122
  pet_image_url = f"https://rbxgleaks.pythonanywhere.com/asset/{asset_id}"
 
123
  print(f"Using image URL for {pet_name}: {pet_image_url}")
124
  embed.set_thumbnail(url=pet_image_url)
125
 
 
136
  data = response.json()
137
  if data['status'] == 'ok':
138
  pet_values = {pet: 0 for pet in tracked_pets}
 
139
  for pet in data['data']:
140
  pet_id = pet['configData']['id']
141
  is_shiny = pet['configData'].get('sh', False)
142
  value = pet['value']
 
143
  pet_name = f"Shiny {pet_id}" if is_shiny else pet_id
144
  if pet_name in pet_values:
145
  print(f"Found pet: {pet_name} with exist count {value}")
146
  pet_values[pet_name] = value
 
147
  return pet_values
148
  print(f"Error code: {response.status_code}")
149
  except Exception as e:
 
161
  print(f"Initially tracking {len(tracked_pets)} pets")
162
 
163
  while True:
164
+ cleanup_old_hatches()
165
 
 
166
  if not tracked_pets:
167
  tracked_pets = await get_huge_secret_pets()
168
  lastknown.update({pet: None for pet in tracked_pets if pet not in lastknown})
 
190
  await asyncio.sleep(60)
191
 
192
  def cleanup_old_hatches():
 
193
  one_hour_ago = datetime.now() - timedelta(hours=1)
194
  for pet in hourly_hatches:
195
  hourly_hatches[pet] = [timestamp for timestamp in hourly_hatches[pet]
 
197
 
198
  @bot.command(name='lasthour')
199
  async def last_hour_stats(ctx):
 
200
  cleanup_old_hatches()
201
 
202
  if not hourly_hatches:
 
211
  color=discord.Color.green()
212
  )
213
 
 
214
  sorted_pets = sorted(
215
  hourly_hatches.items(),
216
  key=lambda x: len(x[1]),
 
218
  )
219
 
220
  for pet_name, hatches in sorted_pets:
221
+ if hatches:
222
  count = len(hatches)
223
  difficulty = pet_difficulties.get(pet_name, "Unknown")
224
  rap_value = pet_raps.get(pet_name, "No RAP")
225
 
 
226
  if isinstance(rap_value, (int, float)):
227
  rap_display = f"{rap_value:,}"
228
  else:
 
239
  inline=True
240
  )
241
 
 
242
  embed.set_footer(text=f"Last updated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
243
 
244
  await ctx.send(embed=embed)
245
 
 
 
 
 
 
246
  @bot.event
247
  async def on_ready():
248
  print(f'Logged in as {bot.user.name}')
249
  bot.loop.create_task(main_loop())
250
 
 
251
  runner = web.AppRunner(app)
252
  await runner.setup()
253
  site = web.TCPSite(runner, '0.0.0.0', 7860)
 
255
  print(f"Web server started on port 7860")
256
 
257
  def run_bot():
258
+ bot.run(TOKEN)
259
 
260
  if __name__ == "__main__":
261
  run_bot()