Добавлены Discord-команды: - !status — пинг к gateway, uptime, статус (embed) - !stats — серверы, каналы, пользователи (embed) Добавлены консольные команды: - status — статус бота в терминале - stats — статистика серверов в терминале Тесты: - test_commands_status.py (6 тестов) - test_commands_stats.py (4 теста) - всего: 233 теста Обновления: - README.md — новые команды в таблицах и архитектуре - ISSUES.md — высокий приоритет закрыт - admin.py — hint на !status и !stats
48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
import time
|
||
|
||
import discord
|
||
from discord.ext import commands
|
||
|
||
|
||
class Status(commands.Cog):
|
||
"""Команда !status — статус бота, пинг, uptime"""
|
||
|
||
def __init__(self):
|
||
self._start_time = time.time()
|
||
|
||
@commands.command(name="status")
|
||
async def status(self, ctx):
|
||
"""Статус бота: пинг к Discord gateway и время работы"""
|
||
latency_ms = round(ctx.bot.latency * 1000, 1)
|
||
uptime_seconds = time.time() - self._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)
|