Fix: Delete graph image if server not running
All checks were successful
Docker Build and Push (Multi-architecture) / build-and-push (push) Successful in 36s

This commit is contained in:
2025-09-28 18:41:50 +00:00
parent ca9e88f1e2
commit ce4887bae3

View File

@@ -765,7 +765,7 @@ class PterodactylBot(commands.Bot):
embed.add_field(name=" Status", value="✅ `Active`", inline=True)
# Add resource usage if server is running
if current_state.lower() == "running":
if current_state.lower() != "offline":
# Current usage
cpu_usage = round(resource_attributes.get('resources', {}).get('cpu_absolute', 0), 2)
memory_usage = round(resource_attributes.get('resources', {}).get('memory_bytes', 0) / (1024 ** 2), 2)
@@ -952,8 +952,8 @@ class PterodactylBot(commands.Bot):
# 4. Force update every 10 minutes for running servers (for uptime counter)
elif (current_state == 'running' and
(last_force_update is None or
current_time - last_force_update >= 600)): # 10 minutes = 600 seconds
(last_force_update is None or
current_time - last_force_update >= 600)): # 10 minutes = 600 seconds
logger.debug(f"Executing 10-minute force update for running server {server_name}")
needs_update = True
# Update the last force update time
@@ -972,20 +972,28 @@ class PterodactylBot(commands.Bot):
# Fetch and update the existing message
message = await channel.fetch_message(int(location['message_id']))
# Generate and attach graph images if available
# Check if server is transitioning to offline/stopping state
# and remove image attachment if present
files = []
server_graphs = self.metrics_manager.get_server_graphs(server_id)
if server_graphs and server_graphs.has_sufficient_data:
# Generate CPU graph
# Only include graph images if server is running AND has sufficient data
if (current_state == 'running' and
server_graphs and
server_graphs.has_sufficient_data):
# Generate metrics graph
combined_graph = server_graphs.generate_combined_graph()
if combined_graph:
files.append(discord.File(combined_graph, filename=f"metrics_graph_{server_id}.png"))
# Update message with embed, view, and graph files
if files:
await message.edit(embed=embed, view=view, attachments=files)
logger.debug(f"Including metrics graph for running server {server_name}")
else:
await message.edit(embed=embed, view=view)
# Server is offline/stopping - ensure no image is attached
logger.debug(f"Server {server_name} is {current_state}, removing image attachment if present")
# We'll update without files to remove any existing attachments
# Update message with embed, view, and files (empty files list removes attachments)
await message.edit(embed=embed, view=view, attachments=files)
update_count += 1
logger.debug(f"Updated status for {server_name}")