deadzilla 91f34625a8 feat: команды !status и !stats
Добавлены 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
2026-06-12 16:19:21 +05:00

39 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import time
def status(stop_event, bot):
"""Показать статус бота: пинг и время работы"""
if stop_event.is_set():
return None
latency_ms = round(bot.latency * 1000, 1)
uptime_seconds = time.time() - getattr(bot, "_start_time", time.time())
uptime_str = _format_uptime(uptime_seconds)
print("\n" + "=" * 40)
print("Статус бота")
print("=" * 40)
print(f" Пинг: {latency_ms} мс")
print(f" Uptime: {uptime_str}")
print(f" Статус: Online")
print("=" * 40)
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)