import time import discord from discord.ext import commands class Status(commands.Cog): """Команда !status — статус бота, пинг, uptime""" @commands.command(name="status") async def status(self, ctx): """Статус бота: пинг к Discord gateway и время работы""" latency_ms = round(ctx.bot.latency * 1000, 1) start_time = getattr(ctx.bot, "_start_time", time.time()) uptime_seconds = time.time() - start_time uptime_str = self._format_uptime(uptime_seconds) embed = discord.Embed( title="Статус бота", colour=discord.Color.green(), ) embed.add_field(name="Пинг", value=f"{latency_ms} мс", inline=True) embed.add_field(name="Uptime", value=uptime_str, inline=True) embed.add_field(name="Статус", value="Online", inline=True) await ctx.send(embed=embed) @staticmethod def _format_uptime(total_seconds: float) -> str: """Форматировать секунды в человекочитаемый вид.""" days = int(total_seconds // 86400) hours = int((total_seconds % 86400) // 3600) minutes = int((total_seconds % 3600) // 60) seconds = int(total_seconds % 60) parts = [] if days: parts.append(f"{days}д") if hours: parts.append(f"{hours}ч") if minutes: parts.append(f"{minutes}м") parts.append(f"{seconds}с") return " ".join(parts)