Добавлены 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
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
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)
|