mirror of
https://github.com/agessaman/meshcore-bot.git
synced 2026-11-04 03:52:34 +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.
76 lines
2.3 KiB
Python
76 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Solar Command - Provides solar conditions and HF band information
|
|
"""
|
|
|
|
from ..models import MeshMessage
|
|
from ..solar_conditions import solar_conditions
|
|
from .base_command import BaseCommand
|
|
|
|
|
|
class SolarCommand(BaseCommand):
|
|
"""Command to get solar conditions.
|
|
|
|
Provides information about current solar activity (SFI, sunspots, A-index, K-index)
|
|
and improved HF band conditions.
|
|
"""
|
|
|
|
# Plugin metadata
|
|
# Read-only informational output; safe for scheduled {cmd:...} rendering.
|
|
render_safe = True
|
|
name = "solar"
|
|
enabled_attr = "solar_enabled"
|
|
keywords = ['solar']
|
|
description = "Get current solar conditions and HF band info"
|
|
category = "solar"
|
|
requires_internet = True # Requires internet access for hamqsl.com API
|
|
|
|
# Documentation
|
|
short_description = "Get current solar conditions and HF band info"
|
|
usage = "solar"
|
|
examples = ["solar"]
|
|
|
|
def __init__(self, bot):
|
|
"""Initialize the solar command.
|
|
|
|
Args:
|
|
bot: The MeshCoreBot instance.
|
|
"""
|
|
super().__init__(bot)
|
|
self.solar_enabled = self.get_config_value('Solar_Command', 'enabled', fallback=True, value_type='bool')
|
|
|
|
async def execute(self, message: MeshMessage) -> bool:
|
|
"""Execute the solar command.
|
|
|
|
Retrieves solar conditions and sends a formatted response to the user.
|
|
|
|
Args:
|
|
message: The message that triggered the command.
|
|
|
|
Returns:
|
|
bool: True if executed successfully, False otherwise.
|
|
"""
|
|
try:
|
|
# Get solar conditions (more readable format)
|
|
solar_info = solar_conditions()
|
|
|
|
# Send response (solar only, more readable)
|
|
response = self.translate('commands.solar.response', info=solar_info)
|
|
|
|
# Use the unified send_response method
|
|
return await self.send_response(message, response)
|
|
|
|
|
|
except Exception as e:
|
|
error_msg = self.translate('commands.solar.error', error=str(e))
|
|
await self.send_response(message, error_msg)
|
|
return False
|
|
|
|
def get_help_text(self) -> str:
|
|
"""Get help text for this command.
|
|
|
|
Returns:
|
|
str: The help text for this command.
|
|
"""
|
|
return self.translate('commands.solar.help')
|