Files
Mace-AIO-Discord-Bot---With…/bot/api/routes/bot.py
TheOnlyMace 4f57cccea5
Some checks failed
CI / Bot (Python) (push) Successful in 12s
CI / Dashboard (Next.js) (push) Failing after 9s
Add Discord sharding support and related configurations
Enhance the bot's architecture by introducing sharding capabilities, allowing for better scalability and performance. Update environment files to include sharding options, and modify the bot's core logic to handle shard connections and latencies. Implement shard-specific logging and API synchronization, ensuring that only the primary shard performs certain tasks. Update API schemas and routes to reflect shard information, improving the overall status reporting and monitoring of the bot's performance across multiple shards.
2026-07-21 23:09:35 +02:00

60 lines
2.8 KiB
Python

# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ +-+-+-+-+-+-+-+-+ ║
# ║ |H|e|x|a|H|o|s|t| ║
# ║ +-+-+-+-+-+-+-+-+ ║
# ║ ║
# ║ © 2026 HexaHost — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/hexahost ║
# ║ github ── https://github.com/theoneandonlymace ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
from fastapi import APIRouter, Depends
from api.dependencies import get_bot
from api.schemas import BotInfo, BotStatus
from typing import TYPE_CHECKING
from utils.config import *
if TYPE_CHECKING:
from core.axiom import Axiom
router = APIRouter()
@router.get("/status", response_model=BotStatus, summary="Get bot status", description="Returns real-time health metrics, latency, and scale information.")
async def get_status(bot: "Axiom" = Depends(get_bot)):
"""
Returns the live status of the bot.
"""
shard_ids = list(bot.shards.keys()) if bot.shards else ([0] if bot.shard_count else [])
shard_latencies = [
{"id": sid, "latency_ms": round(lat * 1000, 2)}
for sid, lat in (bot.latencies or [])
]
return BotStatus(
user=str(bot.user),
id=str(bot.user.id) if bot.user else None,
latency=bot.latency * 1000,
guild_count=len(bot.guilds),
user_count=sum(g.member_count or 0 for g in bot.guilds),
shards=bot.shard_count,
shard_ids=shard_ids,
shard_latencies=shard_latencies,
)
@router.get("/info", response_model=BotInfo, summary="Get bot info", description="Returns general information about the bot including command count and user reach.")
async def get_bot_info(bot: "Axiom" = Depends(get_bot)):
"""
Get general information about the Discord bot.
"""
return BotInfo(
name=bot.user.name if bot.user else BRAND_NAME,
id=str(bot.user.id) if bot.user else None,
guilds=len(bot.guilds),
users=sum(g.member_count or 0 for g in bot.guilds),
commands=len(bot.commands),
latency=f"{round(bot.latency * 1000, 2)}ms"
)