Fix \!backup command not working - module loading issue

Fixed BackupCommands module not being loaded into the bot system:
- Added BackupCommands to modules/__init__.py imports and __all__ list
- Added BackupCommands to module loading in run_bot_with_reconnect.py
- Fixed constructor signature to match BaseModule requirements

All 5 backup commands now properly registered and available to admin users:
- \!backup - Create manual database backups
- \!restore - Restore from backup files
- \!backups - List available backups
- \!backup_stats - Show backup system statistics
- \!backup_cleanup - Clean up old backups based on retention policy

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
megaproxy 2025-08-01 15:03:15 +00:00
parent 3efefb6632
commit e920503dbd
3 changed files with 57 additions and 25 deletions

View file

@ -14,8 +14,8 @@ from config import ADMIN_USER
class BackupCommands(BaseModule):
"""Module for database backup management commands."""
def __init__(self, bot, database):
super().__init__(bot, database)
def __init__(self, bot, database, game_engine):
super().__init__(bot, database, game_engine)
self.backup_manager = BackupManager()
self.scheduler = BackupScheduler(self.backup_manager)
self.scheduler_task = None
@ -23,14 +23,19 @@ class BackupCommands(BaseModule):
# Setup logging
self.logger = logging.getLogger(__name__)
# Start the scheduler
self._start_scheduler()
# Initialize scheduler flag (will be started when needed)
self._scheduler_started = False
def _start_scheduler(self):
async def _start_scheduler(self):
"""Start the backup scheduler task."""
if self.scheduler_task is None or self.scheduler_task.done():
self.scheduler_task = asyncio.create_task(self.scheduler.start_scheduler())
self.logger.info("Backup scheduler started")
if not self._scheduler_started and (self.scheduler_task is None or self.scheduler_task.done()):
try:
self.scheduler_task = asyncio.create_task(self.scheduler.start_scheduler())
self._scheduler_started = True
self.logger.info("Backup scheduler started")
except RuntimeError:
# No event loop running, scheduler will be started later
self.logger.info("No event loop available, scheduler will start when commands are used")
def get_commands(self):
"""Return list of available backup commands."""
@ -41,6 +46,10 @@ class BackupCommands(BaseModule):
async def handle_command(self, channel, nickname, command, args):
"""Handle backup-related commands."""
# Start scheduler if not already running
if not self._scheduler_started:
await self._start_scheduler()
# Check if user has admin privileges for backup commands
if not await self._is_admin(nickname):
self.send_message(channel, f"{nickname}: Backup commands require admin privileges.")