Files
meshcore-bot/modules/commands/version_command.py
T
agessaman a1d11b6f83 refactor(commands): let BaseCommand check each command's enable switch
32 commands overrode can_execute only to return False while their own <name>_enabled flag was off and otherwise defer to the base. BaseCommand now has an enabled_attr class attribute naming that flag, which can_execute checks first. Each command keeps reading its flag exactly as before (same section, default and legacy aliases), and code and tests that set help_enabled, webviewer_enabled and the like still work, since the flag is read at call time.

Only overrides that were exactly 'if not self.<flag>: return False; return super().can_execute(...)' were converted, checked by AST. Commands with extra conditions (wx's delegate, joke's dark-joke DM rule, admin-only and DM-only checks, dadjoke's reversed order) keep their overrides. Several of the removed overrides called super().can_execute(message) without passing skip_channel_check; nothing calls them with it set, so honoring it now changes nothing.
2026-10-01 02:09:22 -07:00

50 lines
1.4 KiB
Python

#!/usr/bin/env python3
"""
Version command for the MeshCore Bot.
Returns the currently running bot version string.
"""
from typing import Any
from ..models import MeshMessage
from ..version_info import resolve_application_version
from .base_command import BaseCommand
class VersionCommand(BaseCommand):
"""Handles the version/ver command."""
# Read-only informational output; safe for scheduled {cmd:...} rendering.
render_safe = True
name = "version"
enabled_attr = "version_enabled"
keywords = ["version", "ver"]
description = "Show the running bot version."
category = "basic"
short_description = "Show running bot version"
usage = "version"
examples = ["version", "ver"]
def __init__(self, bot: Any):
super().__init__(bot)
self.version_enabled = self.get_config_value(
"Version_Command",
"enabled",
fallback=True,
value_type="bool",
)
def get_help_text(self) -> str:
return self.description
async def execute(self, message: MeshMessage) -> bool:
version_value = getattr(self.bot, "bot_version", None)
if not version_value:
version_value = resolve_application_version().get("display", "unknown")
sender = message.sender_id or "Unknown"
response = f"@[{sender}] Bot version: {version_value}"
return await self.send_response(message, response)