Files
meshcore-bot/modules/commands/sun_command.py
T
agessaman 7aba432b54 refactor(commands): every bundled get_help_text takes message=None
S4. BaseCommand and the 40 bundled overrides that took no argument now take `message: MeshMessage | None = None`, matching joke and rain, which already use the message. None of the 40 bodies read it, so their help text is unchanged. help and command_manager keep their TypeError retry, since local plugins may still implement get_help_text(self). For bundled commands the retry no longer runs: `help <command>` calls get_help_text(message) once instead of failing and calling it again. A new test pins the signature for every bundled command class. The offline smoke run against the real config produces the same help text for all 46 commands.
2026-10-03 22:28:45 -07:00

72 lines
2.1 KiB
Python

#!/usr/bin/env python3
"""
Sun Command - Provides sunrise/sunset information
"""
from ..models import MeshMessage
from ..solar_conditions import get_sun
from .base_command import BaseCommand
class SunCommand(BaseCommand):
"""Command to get sun information.
Calculates and displays sunrise and sunset times for the bot's configured location
or a default location.
"""
# Plugin metadata
# Read-only informational output; safe for scheduled {cmd:...} rendering.
render_safe = True
name = "sun"
honors_skip_channel_check = False
enabled_attr = "sun_enabled"
keywords = ['sun']
description = "Get sunrise/sunset times"
category = "solar"
# Documentation
short_description = "Get sunrise and sunset times"
usage = "sun"
examples = ["sun"]
def __init__(self, bot):
"""Initialize the sun command.
Args:
bot: The MeshCoreBot instance.
"""
super().__init__(bot)
self.sun_enabled = self.get_config_value('Sun_Command', 'enabled', fallback=True, value_type='bool')
async def execute(self, message: MeshMessage) -> bool:
"""Execute the sun command.
Calculates sun events and sends the information to the user.
Args:
message: The message that triggered the command.
Returns:
bool: True if executed successfully, False otherwise.
"""
try:
# Get sun information using default location
sun_info = get_sun()
# Send response using unified method
response = self.translate('commands.sun.response', info=sun_info)
return await self.send_response(message, response)
except Exception as e:
error_msg = self.translate('commands.sun.error', error=str(e))
return await self.send_response(message, error_msg)
def get_help_text(self, message: MeshMessage | None = None) -> str:
"""Get help text for this command.
Returns:
str: The help text for this command.
"""
return self.translate('commands.sun.help')