Files
meshcore-bot/modules/commands/status_command.py
agessaman 0d9c8850e3 refactor(commands): mark always-admin commands with admin_only
reload, channelpause, status and feed overrode requires_admin_access() to return True, then checked 'if not self.requires_admin_access(): return False' in their own can_execute, which could never fire. BaseCommand gains an admin_only class attribute that requires_admin_access() honors before consulting [Admin_ACL] admin_commands; the four commands set it and lose both overrides. status and feed move their enable switch onto enabled_attr. requires_admin_access() is unchanged for every other caller, including local plugins and the website generator.
2026-10-01 02:12:20 -07:00

66 lines
2.0 KiB
Python

#!/usr/bin/env python3
"""
Status command
DM-only admin command that reports bot runtime status in a single response.
"""
from __future__ import annotations
from datetime import datetime, timezone
from typing import Any
from ..models import MeshMessage
from .base_command import BaseCommand
class StatusCommand(BaseCommand):
"""Report high-level runtime status for operators."""
name = "status"
admin_only = True
enabled_attr = "status_enabled"
keywords = ["status"]
description = "Show runtime status (DM only, admin only)"
requires_dm = True
cooldown_seconds = 2
category = "admin"
short_description = "Show runtime status for operators"
usage = "status"
examples = ["status", "!status"]
parameters: list[dict[str, str]] = []
def __init__(self, bot: Any):
super().__init__(bot)
self.status_enabled = self.get_config_value(
"Status_Command",
"enabled",
fallback=True,
value_type="bool",
)
async def execute(self, message: MeshMessage) -> bool:
now = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M UTC")
connected = bool(getattr(self.bot, "connected", False))
radio_zombie = bool(getattr(self.bot, "is_radio_zombie", False))
radio_offline = bool(getattr(self.bot, "is_radio_offline", False))
web_running = False
integration = getattr(self.bot, "web_viewer_integration", None)
if integration is not None:
web_running = bool(getattr(integration, "running", False))
paused = not bool(getattr(self.bot, "channel_responses_enabled", True))
# Keep under DM budget (158 UTF-8 bytes); long labels caused ERR_CODE_TABLE_FULL.
status_text = (
f"Status {now}\n"
f"connected: {connected}\n"
f"radio_zombie: {radio_zombie}\n"
f"radio_offline: {radio_offline}\n"
f"ch_paused: {paused}\n"
f"web: {web_running}"
)
await self.send_response(message, status_text)
return True