|
4 | 4 | import discord |
5 | 5 | from src.api.dashboard.auth_routes import get_current_user |
6 | 6 | from typing import List, Optional |
7 | | -from datetime import datetime, timedelta |
| 7 | +from datetime import datetime, timedelta, timezone |
8 | 8 | import time |
9 | 9 | # Falls du Schemas nutzt: from .schemas import ServerStatus, UserInfo |
10 | 10 |
|
@@ -45,8 +45,15 @@ async def get_stats(request: Request): |
45 | 45 | raise HTTPException(status_code=503, detail="Bot-Verbindung nicht verfügbar") |
46 | 46 |
|
47 | 47 | try: |
48 | | - # Berechne Uptime (in Sekunden seit dem letzten Ready-Event) |
49 | | - uptime_seconds = (discord.utils.utcnow() - bot_instance.start_time).total_seconds() if hasattr(bot_instance, 'start_time') else 0 |
| 48 | + # Berechne Uptime (Robust gegen Naive/Aware-Mix) |
| 49 | + now = discord.utils.utcnow() |
| 50 | + start = getattr(bot_instance, 'start_time', now) |
| 51 | + |
| 52 | + # Sicherstellen, dass beide aware sind |
| 53 | + if start.tzinfo is None: |
| 54 | + start = start.replace(tzinfo=timezone.utc) |
| 55 | + |
| 56 | + uptime_seconds = (now - start).total_seconds() |
50 | 57 | uptime_minutes, remainder = divmod(int(uptime_seconds), 60) |
51 | 58 | uptime_hours, uptime_minutes = divmod(uptime_minutes, 60) |
52 | 59 | uptime_days, uptime_hours = divmod(uptime_hours, 24) |
@@ -383,5 +390,5 @@ async def get_mega_data(guild_id: int, user: dict = Depends(get_current_user)): |
383 | 390 | dashboard_main_router.include_router(auth_router) |
384 | 391 | dashboard_main_router.include_router(settings_router) |
385 | 392 | dashboard_main_router.include_router(user_router) |
386 | | -dashboard_main_router.include_router(router_public) |
| 393 | +# dashboard_main_router.include_router(router_public) # Move to main.py for root access |
387 | 394 |
|
0 commit comments