Files
meshcore-bot/modules/commands/status_command.py
T
agessaman 119fce2211 feat(command-manager): implement DM length guard and auto-splitting for oversized messages
- Added a mechanism to check the byte length of direct messages (DMs) before sending, ensuring they do not exceed the firmware's maximum limit.
- Implemented a method to split oversized messages into smaller chunks, preserving UTF-8 encoding and avoiding mid-codepoint splits.
- Enhanced logging to provide warnings when messages are auto-split, including details on the number of chunks created.
- Updated the DM sending logic to handle both single and split messages efficiently.
- Introduced a new static method for splitting text into UTF-8 chunks, improving message handling across the application.
2026-07-16 14:56:42 -07:00

74 lines
2.4 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"
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",
)
def can_execute(self, message: MeshMessage, skip_channel_check: bool = False) -> bool:
if not self.status_enabled:
return False
if not self.requires_admin_access():
return False
return super().can_execute(message, skip_channel_check=skip_channel_check)
def requires_admin_access(self) -> bool:
return True
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