coollsd commited on
Commit
7cd896c
·
verified ·
1 Parent(s): ae2fb85

Update ccc.py

Browse files
Files changed (1) hide show
  1. ccc.py +82 -44
ccc.py CHANGED
@@ -3,6 +3,8 @@ import discord
3
  from discord.ext import commands
4
  import asyncio
5
  import re
 
 
6
  import os
7
 
8
  TOKEN = os.environ['TOKEN']
@@ -18,6 +20,23 @@ bot = commands.Bot(command_prefix='!', intents=intents)
18
  pet_images = {}
19
  pet_difficulties = {}
20
  pet_raps = {}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  async def update_rap_values():
23
  try:
@@ -25,26 +44,43 @@ async def update_rap_values():
25
  if response.status_code == 200:
26
  data = response.json()
27
  if data['status'] == 'ok':
28
- # Clear existing RAP values
29
  pet_raps.clear()
30
-
31
- # Process each pet in the list
32
  for pet_data in data['data']:
33
  config_data = pet_data['configData']
34
  pet_id = config_data['id']
35
  value = pet_data['value']
36
-
37
- # Check if it's a shiny pet
38
  is_shiny = config_data.get('sh', False)
39
  if is_shiny:
40
  pet_raps[f"Shiny {pet_id}"] = value
41
  else:
42
  pet_raps[pet_id] = value
43
-
44
  print(f"Updated RAP values for {len(data['data'])} pets")
45
  except Exception as e:
46
  print(f"Error fetching RAP values: {e}")
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  async def get_huge_secret_pets():
49
  try:
50
  response = requests.get(PETS_API)
@@ -60,10 +96,8 @@ async def get_huge_secret_pets():
60
  huge_secret_pets.append(pet_name)
61
  huge_secret_pets.append(f"Shiny {pet_name}")
62
 
63
- # Store difficulty value
64
  difficulty = config_data.get('difficulty', 'Unknown')
65
  pet_difficulties[pet_name] = difficulty
66
- # Shiny pets are 100x harder
67
  pet_difficulties[f"Shiny {pet_name}"] = difficulty * 100
68
 
69
  if 'thumbnail' in config_data:
@@ -71,50 +105,50 @@ async def get_huge_secret_pets():
71
  pet_images[f"Shiny {pet_name}"] = config_data['thumbnail']
72
  print(f"Stored image URL for {pet_name}: {config_data['thumbnail']}")
73
 
 
 
 
 
74
  print(f"Found {len(huge_secret_pets)} pets to track (including shiny versions)")
75
  return huge_secret_pets
76
- else:
77
- print("API response status not OK")
78
- return [] # Return empty list instead of None
79
- except Exception as e:
80
- print(f"Error fetching pets list: {e}")
81
- return [] # Return empty list instead of None
82
  except Exception as e:
83
  print(f"Error fetching pets list: {e}")
84
- return []
85
 
86
  async def send_embed_message(channel, pet_name, previous_value, current_value, is_change=False):
87
  pet_image_url = pet_images.get(pet_name, None)
88
  difficulty = pet_difficulties.get(pet_name, "Unknown")
89
  rap_value = pet_raps.get(pet_name, "No RAP")
 
90
 
91
- # Format RAP value with commas
92
- if isinstance(rap_value, (int, float)):
93
- rap_display = f"{rap_value:,}"
94
- else:
95
- rap_display = rap_value
 
96
 
97
- # Format difficulty with commas
98
- if isinstance(difficulty, (int, float)):
99
- difficulty_display = f"{difficulty:,}"
100
- else:
101
- difficulty_display = difficulty
102
-
103
- # Format exist counts with commas
104
- if isinstance(current_value, (int, float)):
105
- current_display = f"{current_value:,}"
106
- else:
107
- current_display = current_value
108
-
109
- if isinstance(previous_value, (int, float)):
110
- previous_display = f"{previous_value:,}"
111
  else:
112
- previous_display = previous_value
 
 
113
 
114
  embed = discord.Embed(
115
- title=f"🎲 A {pet_name} was rolled! 🎲",
116
- description=f"{pet_name} exists: **{current_display}**\nDifficulty: **1 in {difficulty_display}**\nRAP Value: **{rap_display}**",
117
- color=discord.Color.blue() if not is_change else discord.Color.orange(),
 
 
 
118
  )
119
 
120
  if pet_image_url:
@@ -164,7 +198,7 @@ async def main_loop():
164
  return
165
 
166
  tracked_pets = await get_huge_secret_pets()
167
- if not tracked_pets: # If we get an empty list, wait and retry
168
  print("No pets fetched, retrying in 60 seconds...")
169
  await asyncio.sleep(60)
170
  return
@@ -175,10 +209,9 @@ async def main_loop():
175
  while True:
176
  try:
177
  if not tracked_pets:
178
- tracked_pets = await get_huge_secret_pets() or [] # Ensure we always have a list
179
  lastknown.update({pet: None for pet in tracked_pets if pet not in lastknown})
180
 
181
- # Update RAP values periodically
182
  await update_rap_values()
183
 
184
  vvalues = await petdata(tracked_pets)
@@ -187,13 +220,18 @@ async def main_loop():
187
  if lastknown[pet] is None:
188
  print(f"Initial value for {pet}: {value}")
189
  elif value != lastknown[pet]:
 
 
 
 
 
190
  await send_embed_message(channel, pet, lastknown[pet], value, is_change=True)
191
  lastknown[pet] = value
192
  else:
193
  print("Broken check")
194
 
195
- new_pets = await get_huge_secret_pets() or [] # Ensure we always have a list
196
- if new_pets and set(new_pets) != set(tracked_pets): # Only compare if new_pets is not empty
197
  print("Pet list updated!")
198
  tracked_pets = new_pets
199
  lastknown.update({pet: None for pet in tracked_pets if pet not in lastknown})
@@ -202,7 +240,7 @@ async def main_loop():
202
 
203
  except Exception as e:
204
  print(f"Error in main loop: {e}")
205
- await asyncio.sleep(60) # Wait before retrying if there's an error
206
 
207
  @bot.event
208
  async def on_ready():
 
3
  from discord.ext import commands
4
  import asyncio
5
  import re
6
+ from collections import deque
7
+ from datetime import datetime, timedelta
8
  import os
9
 
10
  TOKEN = os.environ['TOKEN']
 
20
  pet_images = {}
21
  pet_difficulties = {}
22
  pet_raps = {}
23
+ pet_changes = {}
24
+
25
+ def format_number(number):
26
+ if not isinstance(number, (int, float)):
27
+ return str(number)
28
+
29
+ abs_number = abs(number)
30
+ if abs_number < 1000:
31
+ return str(number)
32
+ elif abs_number < 1000000:
33
+ return f"{number/1000:.1f}K"
34
+ elif abs_number < 1000000000:
35
+ return f"{number/1000000:.1f}M"
36
+ elif abs_number < 1000000000000:
37
+ return f"{number/1000000000:.1f}B"
38
+ else:
39
+ return f"{number/1000000000000:.1f}T"
40
 
41
  async def update_rap_values():
42
  try:
 
44
  if response.status_code == 200:
45
  data = response.json()
46
  if data['status'] == 'ok':
 
47
  pet_raps.clear()
 
 
48
  for pet_data in data['data']:
49
  config_data = pet_data['configData']
50
  pet_id = config_data['id']
51
  value = pet_data['value']
 
 
52
  is_shiny = config_data.get('sh', False)
53
  if is_shiny:
54
  pet_raps[f"Shiny {pet_id}"] = value
55
  else:
56
  pet_raps[pet_id] = value
 
57
  print(f"Updated RAP values for {len(data['data'])} pets")
58
  except Exception as e:
59
  print(f"Error fetching RAP values: {e}")
60
 
61
+ def calculate_hourly_rate(pet_name):
62
+ if pet_name not in pet_changes:
63
+ return 0
64
+
65
+ changes = pet_changes[pet_name]
66
+ if not changes:
67
+ return 0
68
+
69
+ current_time = datetime.now()
70
+ one_hour_ago = current_time - timedelta(hours=1)
71
+
72
+ recent_changes = [change for change in changes if change['timestamp'] > one_hour_ago]
73
+
74
+ if not recent_changes:
75
+ return 0
76
+
77
+ if len(recent_changes) >= 2:
78
+ earliest_value = recent_changes[0]['value']
79
+ latest_value = recent_changes[-1]['value']
80
+ return latest_value - earliest_value
81
+
82
+ return 1
83
+
84
  async def get_huge_secret_pets():
85
  try:
86
  response = requests.get(PETS_API)
 
96
  huge_secret_pets.append(pet_name)
97
  huge_secret_pets.append(f"Shiny {pet_name}")
98
 
 
99
  difficulty = config_data.get('difficulty', 'Unknown')
100
  pet_difficulties[pet_name] = difficulty
 
101
  pet_difficulties[f"Shiny {pet_name}"] = difficulty * 100
102
 
103
  if 'thumbnail' in config_data:
 
105
  pet_images[f"Shiny {pet_name}"] = config_data['thumbnail']
106
  print(f"Stored image URL for {pet_name}: {config_data['thumbnail']}")
107
 
108
+ for pet_name in huge_secret_pets:
109
+ if pet_name not in pet_changes:
110
+ pet_changes[pet_name] = deque(maxlen=100)
111
+
112
  print(f"Found {len(huge_secret_pets)} pets to track (including shiny versions)")
113
  return huge_secret_pets
 
 
 
 
 
 
114
  except Exception as e:
115
  print(f"Error fetching pets list: {e}")
116
+ return []
117
 
118
  async def send_embed_message(channel, pet_name, previous_value, current_value, is_change=False):
119
  pet_image_url = pet_images.get(pet_name, None)
120
  difficulty = pet_difficulties.get(pet_name, "Unknown")
121
  rap_value = pet_raps.get(pet_name, "No RAP")
122
+ hourly_rate = calculate_hourly_rate(pet_name)
123
 
124
+ # Format values with abbreviations
125
+ difficulty_display = format_number(difficulty) if isinstance(difficulty, (int, float)) else difficulty
126
+ rap_display = format_number(rap_value) if isinstance(rap_value, (int, float)) else rap_value
127
+ current_display = format_number(current_value) if isinstance(current_value, (int, float)) else current_value
128
+ previous_display = format_number(previous_value) if isinstance(previous_value, (int, float)) else previous_value
129
+ hourly_rate_display = format_number(hourly_rate) if isinstance(hourly_rate, (int, float)) else hourly_rate
130
 
131
+ # Check if the pet is shiny
132
+ is_shiny = pet_name.startswith("Shiny ")
133
+
134
+ # Format the title based on whether the pet is shiny
135
+ if is_shiny:
136
+ # For shiny pets: use sparkles and format "SHINY" in bold and italic
137
+ base_name = pet_name.replace("Shiny ", "")
138
+ title = f"✨ ***SHINY*** {base_name} was rolled! ✨"
139
+ embed_color = discord.Color.from_rgb(255, 255, 255) # White color for shiny pets
 
 
 
 
 
140
  else:
141
+ # For regular pets: use dice emoji
142
+ title = f"🎲 A {pet_name} was rolled! 🎲"
143
+ embed_color = discord.Color.blue() if not is_change else discord.Color.orange()
144
 
145
  embed = discord.Embed(
146
+ title=title,
147
+ description=f"{pet_name} exists: **{current_display}**\n"
148
+ f"Difficulty: **1 in {difficulty_display}**\n"
149
+ f"RAP Value: **{rap_display}**\n"
150
+ f"Hourly Rate: **{hourly_rate_display}** per hour",
151
+ color=embed_color
152
  )
153
 
154
  if pet_image_url:
 
198
  return
199
 
200
  tracked_pets = await get_huge_secret_pets()
201
+ if not tracked_pets:
202
  print("No pets fetched, retrying in 60 seconds...")
203
  await asyncio.sleep(60)
204
  return
 
209
  while True:
210
  try:
211
  if not tracked_pets:
212
+ tracked_pets = await get_huge_secret_pets() or []
213
  lastknown.update({pet: None for pet in tracked_pets if pet not in lastknown})
214
 
 
215
  await update_rap_values()
216
 
217
  vvalues = await petdata(tracked_pets)
 
220
  if lastknown[pet] is None:
221
  print(f"Initial value for {pet}: {value}")
222
  elif value != lastknown[pet]:
223
+ pet_changes[pet].append({
224
+ 'timestamp': datetime.now(),
225
+ 'value': value,
226
+ 'previous': lastknown[pet]
227
+ })
228
  await send_embed_message(channel, pet, lastknown[pet], value, is_change=True)
229
  lastknown[pet] = value
230
  else:
231
  print("Broken check")
232
 
233
+ new_pets = await get_huge_secret_pets() or []
234
+ if new_pets and set(new_pets) != set(tracked_pets):
235
  print("Pet list updated!")
236
  tracked_pets = new_pets
237
  lastknown.update({pet: None for pet in tracked_pets if pet not in lastknown})
 
240
 
241
  except Exception as e:
242
  print(f"Error in main loop: {e}")
243
+ await asyncio.sleep(60)
244
 
245
  @bot.event
246
  async def on_ready():