major-domo-v2/commands/teams/__init__.py
Cal Corum 8897b7fa5e CLAUDE: Add logged_command decorator and migrate Discord commands to reduce boilerplate
- Add @logged_command decorator in utils/decorators.py to eliminate try/catch/finally boilerplate
- Migrate all Discord commands to use new decorator pattern:
  * commands/league/info.py - /league command
  * commands/players/info.py - /player command
  * commands/teams/info.py - /team and /teams commands
  * commands/teams/roster.py - /roster command
- Fix PyLance type issues by making model IDs required for database entities
- Update Player and Team models to require id field since they come from database
- Fix test cases to provide required id values
- Add comprehensive test coverage for decorator functionality
- Add migration guide for applying decorator to additional commands
- Reduce codebase by ~100 lines of repetitive logging boilerplate

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-15 14:56:42 -05:00

52 lines
1.5 KiB
Python

"""
Team command package for Discord Bot v2.0
Provides team-related slash commands for the SBA league.
"""
import logging
from typing import List, Tuple, Type
import discord
from discord.ext import commands
from .info import TeamInfoCommands
from .roster import TeamRosterCommands
logger = logging.getLogger(f'{__name__}.setup_teams')
async def setup_teams(bot: commands.Bot) -> Tuple[int, int, List[str]]:
"""
Set up team command modules.
Returns:
Tuple of (successful_loads, failed_loads, failed_modules)
"""
team_cogs: List[Tuple[str, Type[commands.Cog]]] = [
("TeamInfoCommands", TeamInfoCommands),
("TeamRosterCommands", TeamRosterCommands),
]
successful = 0
failed = 0
failed_modules = []
for cog_name, cog_class in team_cogs:
try:
await bot.add_cog(cog_class(bot))
logger.info(f"✅ Loaded team command module: {cog_name}")
successful += 1
except Exception as e:
logger.error(f"❌ Failed to load team command module {cog_name}: {e}")
failed += 1
failed_modules.append(cog_name)
# Log summary
if failed == 0:
logger.info(f"🎉 All {successful} team command modules loaded successfully")
else:
logger.warning(f"⚠️ Team commands loaded with issues: {successful} successful, {failed} failed")
if failed_modules:
logger.warning(f"Failed modules: {', '.join(failed_modules)}")
return successful, failed, failed_modules