mirror of
https://github.com/agessaman/meshcore-bot.git
synced 2026-11-03 03:22:28 +00:00
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.
71 lines
2.0 KiB
Python
71 lines
2.0 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"
|
|
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) -> str:
|
|
"""Get help text for this command.
|
|
|
|
Returns:
|
|
str: The help text for this command.
|
|
"""
|
|
return self.translate('commands.sun.help')
|