Files
meshcore-bot/modules/commands/reload_command.py
agessaman db0db96f7e feat: Add reload configuration functionality and update admin commands
- Introduced a new method `reload_config` to allow dynamic reloading of the configuration without restarting the bot, ensuring seamless updates to settings.
- Added a helper method `_get_radio_settings` to retrieve current radio settings for comparison during reload.
- Updated `admin_commands` in `config.ini.example` to include the new `reload` command, enabling admin users to reload configurations on-the-fly.
- Enhanced the `setup_scheduled_messages` method in the scheduler to clear existing jobs before reloading, preventing duplicates.
2026-01-16 19:55:44 -08:00

69 lines
2.0 KiB
Python

#!/usr/bin/env python3
"""
Reload Command
Allows admin users to reload the bot configuration without restarting
"""
from .base_command import BaseCommand
from ..models import MeshMessage
class ReloadCommand(BaseCommand):
"""Command for reloading bot configuration"""
# Plugin metadata
name = "reload"
keywords = ["reload", "reloadconfig", "configreload"]
description = "Reload bot configuration without restart (DM only, admin only)"
requires_dm = True
cooldown_seconds = 2
category = "admin"
def __init__(self, bot):
"""Initialize the reload command.
Args:
bot: The bot instance.
"""
super().__init__(bot)
def can_execute(self, message: MeshMessage) -> bool:
"""Check if this command can be executed (admin only)"""
if not self.requires_admin_access():
return False
return super().can_execute(message)
def requires_admin_access(self) -> bool:
"""Reload command requires admin access"""
return True
def get_help_text(self) -> str:
"""Get help text for the reload command.
Returns:
str: The help text for this command.
"""
return ("Reloads the bot configuration from config.ini without restarting.\n"
"Note: Radio/connection settings cannot be changed via reload.\n"
"If radio settings changed, restart the bot instead.\n"
"Usage: reload")
async def execute(self, message: MeshMessage) -> bool:
"""Execute the reload command.
Args:
message: The message triggering the command.
Returns:
bool: True if executed successfully, False otherwise.
"""
# Call the bot's reload_config method
success, msg = self.bot.reload_config()
if success:
await self.send_response(message, f"{msg}")
else:
await self.send_response(message, f"{msg}")
return True