Clean up IRC command architecture and eliminate redundancy

Major cleanup of the modular command system:

**Legacy Code Removal:**
- Removed all legacy command handlers from src/bot.py (74 lines)
- Eliminated outdated command implementations superseded by modular system
- Maintained backward compatibility while cleaning up codebase

**Duplicate Command Consolidation:**
- Removed duplicate status/uptime/ping commands from admin.py
- Kept comprehensive implementations in connection_monitor.py
- Eliminated 3 redundant commands and ~70 lines of duplicate code

**Admin System Standardization:**
- Updated backup_commands.py to use central ADMIN_USER from config.py
- Updated connection_monitor.py to use central ADMIN_USER from config.py
- Removed hardcoded admin user lists across modules
- Ensured consistent admin privilege checking system-wide

**Benefits:**
- Cleaner, more maintainable command structure
- No duplicate functionality across modules
- Consistent admin configuration management
- Reduced codebase size while maintaining all functionality
- Better separation of concerns in modular architecture

This cleanup addresses technical debt identified in the command audit
and prepares the codebase for future development.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
megaproxy 2025-07-17 17:00:06 +00:00
parent 5293da2921
commit 86902c6b83
4 changed files with 27 additions and 180 deletions

View file

@ -21,7 +21,7 @@ class Admin(BaseModule):
"""Handles admin-only commands like reload"""
def get_commands(self):
return ["reload", "rate_stats", "rate_user", "rate_unban", "rate_reset", "weather", "setweather", "spawnevent", "startevent", "status", "uptime", "ping", "heal"]
return ["reload", "rate_stats", "rate_user", "rate_unban", "rate_reset", "weather", "setweather", "spawnevent", "startevent", "heal"]
async def handle_command(self, channel, nickname, command, args):
if command == "reload":
@ -42,12 +42,6 @@ class Admin(BaseModule):
await self.cmd_spawnevent(channel, nickname, args)
elif command == "startevent":
await self.cmd_startevent(channel, nickname, args)
elif command == "status":
await self.cmd_status(channel, nickname)
elif command == "uptime":
await self.cmd_uptime(channel, nickname)
elif command == "ping":
await self.cmd_ping(channel, nickname)
elif command == "heal":
await self.cmd_heal(channel, nickname)
@ -311,18 +305,24 @@ class Admin(BaseModule):
# Set weather for specific location
location_name = location_arg if len(args) == 2 else " ".join(args[:-1])
success = await self.database.set_weather_for_location(
result = await self.database.set_weather_for_location(
location_name, weather_type, end_time.isoformat(),
weather_config.get("spawn_modifier", 1.0),
",".join(weather_config.get("affected_types", []))
)
if success:
if result.get("success"):
self.send_message(channel,
f"🌤️ {nickname}: Set {weather_type} weather for {location_name}! "
f"Duration: {duration} minutes, Modifier: {weather_config.get('spawn_modifier', 1.0)}x")
# Announce weather change if it actually changed
if result.get("changed"):
await self.game_engine.announce_weather_change(
location_name, result.get("previous_weather"), weather_type, "admin"
)
else:
self.send_message(channel, f"{nickname}: Failed to set weather for '{location_name}'. Location may not exist.")
self.send_message(channel, f"{nickname}: Failed to set weather for '{location_name}'. {result.get('error', 'Location may not exist.')}")
except FileNotFoundError:
self.send_message(channel, f"{nickname}: ❌ Weather configuration file not found.")
@ -409,61 +409,6 @@ class Admin(BaseModule):
except Exception as e:
self.send_message(channel, f"{nickname}: ❌ Error starting event: {str(e)}")
async def cmd_status(self, channel, nickname):
"""Show bot connection status (available to all users)"""
try:
# Check if connection manager exists
if hasattr(self.bot, 'connection_manager') and self.bot.connection_manager:
stats = self.bot.connection_manager.get_connection_stats()
connected = stats.get('connected', False)
state = stats.get('state', 'unknown')
status_emoji = "🟢" if connected else "🔴"
self.send_message(channel, f"{status_emoji} {nickname}: Bot status - {state.upper()}")
else:
self.send_message(channel, f"🟢 {nickname}: Bot is running")
except Exception as e:
self.send_message(channel, f"{nickname}: ❌ Error getting status: {str(e)}")
async def cmd_uptime(self, channel, nickname):
"""Show bot uptime (available to all users)"""
try:
# Check if bot has startup time
if hasattr(self.bot, 'startup_time'):
import datetime
uptime = datetime.datetime.now() - self.bot.startup_time
days = uptime.days
hours, remainder = divmod(uptime.seconds, 3600)
minutes, seconds = divmod(remainder, 60)
if days > 0:
uptime_str = f"{days}d {hours}h {minutes}m"
elif hours > 0:
uptime_str = f"{hours}h {minutes}m"
else:
uptime_str = f"{minutes}m {seconds}s"
self.send_message(channel, f"⏱️ {nickname}: Bot uptime - {uptime_str}")
else:
self.send_message(channel, f"⏱️ {nickname}: Bot is running (uptime unknown)")
except Exception as e:
self.send_message(channel, f"{nickname}: ❌ Error getting uptime: {str(e)}")
async def cmd_ping(self, channel, nickname):
"""Test bot responsiveness (available to all users)"""
try:
import time
start_time = time.time()
# Simple responsiveness test
response_time = (time.time() - start_time) * 1000 # Convert to milliseconds
self.send_message(channel, f"🏓 {nickname}: Pong! Response time: {response_time:.1f}ms")
except Exception as e:
self.send_message(channel, f"{nickname}: ❌ Error with ping: {str(e)}")
async def cmd_heal(self, channel, nickname):
"""Heal active pets (available to all users with 1-hour cooldown)"""