cleanup: remove unused weeks_ahead parameter from get_upcoming_games

The parameter was already ignored (body hardcodes range(1, 19)).
Remove from signature and the one caller that passed it.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cal Corum 2026-03-20 10:11:18 -05:00
parent 0992acf718
commit d4e7246166
2 changed files with 151 additions and 120 deletions

View File

@ -3,6 +3,7 @@ League Schedule Commands
Implements slash commands for displaying game schedules and results. Implements slash commands for displaying game schedules and results.
""" """
from typing import Optional from typing import Optional
import asyncio import asyncio
@ -22,16 +23,13 @@ class ScheduleCommands(commands.Cog):
def __init__(self, bot: commands.Bot): def __init__(self, bot: commands.Bot):
self.bot = bot self.bot = bot
self.logger = get_contextual_logger(f'{__name__}.ScheduleCommands') self.logger = get_contextual_logger(f"{__name__}.ScheduleCommands")
@discord.app_commands.command( @discord.app_commands.command(name="schedule", description="Display game schedule")
name="schedule",
description="Display game schedule"
)
@discord.app_commands.describe( @discord.app_commands.describe(
season="Season to show schedule for (defaults to current season)", season="Season to show schedule for (defaults to current season)",
week="Week number to show (optional)", week="Week number to show (optional)",
team="Team abbreviation to filter by (optional)" team="Team abbreviation to filter by (optional)",
) )
@requires_team() @requires_team()
@logged_command("/schedule") @logged_command("/schedule")
@ -40,7 +38,7 @@ class ScheduleCommands(commands.Cog):
interaction: discord.Interaction, interaction: discord.Interaction,
season: Optional[int] = None, season: Optional[int] = None,
week: Optional[int] = None, week: Optional[int] = None,
team: Optional[str] = None team: Optional[str] = None,
): ):
"""Display game schedule for a week or team.""" """Display game schedule for a week or team."""
await interaction.response.defer() await interaction.response.defer()
@ -105,7 +103,9 @@ class ScheduleCommands(commands.Cog):
# embed = await self._create_recent_results_embed(recent_games, search_season) # embed = await self._create_recent_results_embed(recent_games, search_season)
# await interaction.followup.send(embed=embed) # await interaction.followup.send(embed=embed)
async def _show_week_schedule(self, interaction: discord.Interaction, season: int, week: int): async def _show_week_schedule(
self, interaction: discord.Interaction, season: int, week: int
):
"""Show schedule for a specific week.""" """Show schedule for a specific week."""
self.logger.debug("Fetching week schedule", season=season, week=week) self.logger.debug("Fetching week schedule", season=season, week=week)
@ -113,15 +113,20 @@ class ScheduleCommands(commands.Cog):
if not games: if not games:
await interaction.followup.send( await interaction.followup.send(
f"❌ No games found for season {season}, week {week}.", f"❌ No games found for season {season}, week {week}.", ephemeral=True
ephemeral=True
) )
return return
embed = await self._create_week_schedule_embed(games, season, week) embed = await self._create_week_schedule_embed(games, season, week)
await interaction.followup.send(embed=embed) await interaction.followup.send(embed=embed)
async def _show_team_schedule(self, interaction: discord.Interaction, season: int, team: str, week: Optional[int]): async def _show_team_schedule(
self,
interaction: discord.Interaction,
season: int,
team: str,
week: Optional[int],
):
"""Show schedule for a specific team.""" """Show schedule for a specific team."""
self.logger.debug("Fetching team schedule", season=season, team=team, week=week) self.logger.debug("Fetching team schedule", season=season, team=team, week=week)
@ -129,8 +134,10 @@ class ScheduleCommands(commands.Cog):
# Show team games for specific week # Show team games for specific week
week_games = await schedule_service.get_week_schedule(season, week) week_games = await schedule_service.get_week_schedule(season, week)
team_games = [ team_games = [
game for game in week_games game
if game.away_team.abbrev.upper() == team.upper() or game.home_team.abbrev.upper() == team.upper() for game in week_games
if game.away_team.abbrev.upper() == team.upper()
or game.home_team.abbrev.upper() == team.upper()
] ]
else: else:
# Show team's recent/upcoming games (limited weeks) # Show team's recent/upcoming games (limited weeks)
@ -140,38 +147,44 @@ class ScheduleCommands(commands.Cog):
week_text = f" for week {week}" if week else "" week_text = f" for week {week}" if week else ""
await interaction.followup.send( await interaction.followup.send(
f"❌ No games found for team '{team}'{week_text} in season {season}.", f"❌ No games found for team '{team}'{week_text} in season {season}.",
ephemeral=True ephemeral=True,
) )
return return
embed = await self._create_team_schedule_embed(team_games, season, team, week) embed = await self._create_team_schedule_embed(team_games, season, team, week)
await interaction.followup.send(embed=embed) await interaction.followup.send(embed=embed)
async def _show_current_schedule(self, interaction: discord.Interaction, season: int): async def _show_current_schedule(
self, interaction: discord.Interaction, season: int
):
"""Show current schedule overview with recent and upcoming games.""" """Show current schedule overview with recent and upcoming games."""
self.logger.debug("Fetching current schedule overview", season=season) self.logger.debug("Fetching current schedule overview", season=season)
# Get both recent and upcoming games # Get both recent and upcoming games
recent_games, upcoming_games = await asyncio.gather( recent_games, upcoming_games = await asyncio.gather(
schedule_service.get_recent_games(season, weeks_back=1), schedule_service.get_recent_games(season, weeks_back=1),
schedule_service.get_upcoming_games(season, weeks_ahead=1) schedule_service.get_upcoming_games(season),
) )
if not recent_games and not upcoming_games: if not recent_games and not upcoming_games:
await interaction.followup.send( await interaction.followup.send(
f"❌ No recent or upcoming games found for season {season}.", f"❌ No recent or upcoming games found for season {season}.",
ephemeral=True ephemeral=True,
) )
return return
embed = await self._create_current_schedule_embed(recent_games, upcoming_games, season) embed = await self._create_current_schedule_embed(
recent_games, upcoming_games, season
)
await interaction.followup.send(embed=embed) await interaction.followup.send(embed=embed)
async def _create_week_schedule_embed(self, games, season: int, week: int) -> discord.Embed: async def _create_week_schedule_embed(
self, games, season: int, week: int
) -> discord.Embed:
"""Create an embed for a week's schedule.""" """Create an embed for a week's schedule."""
embed = EmbedTemplate.create_base_embed( embed = EmbedTemplate.create_base_embed(
title=f"📅 Week {week} Schedule - Season {season}", title=f"📅 Week {week} Schedule - Season {season}",
color=EmbedColors.PRIMARY color=EmbedColors.PRIMARY,
) )
# Group games by series # Group games by series
@ -184,9 +197,7 @@ class ScheduleCommands(commands.Cog):
if schedule_lines: if schedule_lines:
embed.add_field( embed.add_field(
name="Games", name="Games", value="\n\n".join(schedule_lines), inline=False
value="\n\n".join(schedule_lines),
inline=False
) )
# Add week summary # Add week summary
@ -195,18 +206,20 @@ class ScheduleCommands(commands.Cog):
embed.add_field( embed.add_field(
name="Week Progress", name="Week Progress",
value=f"{completed}/{total} games completed", value=f"{completed}/{total} games completed",
inline=True inline=True,
) )
embed.set_footer(text=f"Season {season} • Week {week}") embed.set_footer(text=f"Season {season} • Week {week}")
return embed return embed
async def _create_team_schedule_embed(self, games, season: int, team: str, week: Optional[int]) -> discord.Embed: async def _create_team_schedule_embed(
self, games, season: int, team: str, week: Optional[int]
) -> discord.Embed:
"""Create an embed for a team's schedule.""" """Create an embed for a team's schedule."""
week_text = f" - Week {week}" if week else "" week_text = f" - Week {week}" if week else ""
embed = EmbedTemplate.create_base_embed( embed = EmbedTemplate.create_base_embed(
title=f"📅 {team.upper()} Schedule{week_text} - Season {season}", title=f"📅 {team.upper()} Schedule{week_text} - Season {season}",
color=EmbedColors.PRIMARY color=EmbedColors.PRIMARY,
) )
# Separate completed and upcoming games # Separate completed and upcoming games
@ -216,18 +229,26 @@ class ScheduleCommands(commands.Cog):
if completed_games: if completed_games:
recent_lines = [] recent_lines = []
for game in completed_games[-5:]: # Last 5 games for game in completed_games[-5:]: # Last 5 games
result = "W" if game.winner and game.winner.abbrev.upper() == team.upper() else "L" result = (
"W"
if game.winner and game.winner.abbrev.upper() == team.upper()
else "L"
)
if game.home_team.abbrev.upper() == team.upper(): if game.home_team.abbrev.upper() == team.upper():
# Team was home # Team was home
recent_lines.append(f"Week {game.week}: {result} vs {game.away_team.abbrev} ({game.score_display})") recent_lines.append(
f"Week {game.week}: {result} vs {game.away_team.abbrev} ({game.score_display})"
)
else: else:
# Team was away # Team was away
recent_lines.append(f"Week {game.week}: {result} @ {game.home_team.abbrev} ({game.score_display})") recent_lines.append(
f"Week {game.week}: {result} @ {game.home_team.abbrev} ({game.score_display})"
)
embed.add_field( embed.add_field(
name="Recent Results", name="Recent Results",
value="\n".join(recent_lines) if recent_lines else "No recent games", value="\n".join(recent_lines) if recent_lines else "No recent games",
inline=False inline=False,
) )
if upcoming_games: if upcoming_games:
@ -235,25 +256,32 @@ class ScheduleCommands(commands.Cog):
for game in upcoming_games[:5]: # Next 5 games for game in upcoming_games[:5]: # Next 5 games
if game.home_team.abbrev.upper() == team.upper(): if game.home_team.abbrev.upper() == team.upper():
# Team is home # Team is home
upcoming_lines.append(f"Week {game.week}: vs {game.away_team.abbrev}") upcoming_lines.append(
f"Week {game.week}: vs {game.away_team.abbrev}"
)
else: else:
# Team is away # Team is away
upcoming_lines.append(f"Week {game.week}: @ {game.home_team.abbrev}") upcoming_lines.append(
f"Week {game.week}: @ {game.home_team.abbrev}"
)
embed.add_field( embed.add_field(
name="Upcoming Games", name="Upcoming Games",
value="\n".join(upcoming_lines) if upcoming_lines else "No upcoming games", value=(
inline=False "\n".join(upcoming_lines) if upcoming_lines else "No upcoming games"
),
inline=False,
) )
embed.set_footer(text=f"Season {season}{team.upper()}") embed.set_footer(text=f"Season {season}{team.upper()}")
return embed return embed
async def _create_week_results_embed(self, games, season: int, week: int) -> discord.Embed: async def _create_week_results_embed(
self, games, season: int, week: int
) -> discord.Embed:
"""Create an embed for week results.""" """Create an embed for week results."""
embed = EmbedTemplate.create_base_embed( embed = EmbedTemplate.create_base_embed(
title=f"🏆 Week {week} Results - Season {season}", title=f"🏆 Week {week} Results - Season {season}", color=EmbedColors.SUCCESS
color=EmbedColors.SUCCESS
) )
# Group by series and show results # Group by series and show results
@ -262,8 +290,12 @@ class ScheduleCommands(commands.Cog):
results_lines = [] results_lines = []
for (team1, team2), series in series_games.items(): for (team1, team2), series in series_games.items():
# Count wins for each team # Count wins for each team
team1_wins = len([g for g in series if g.winner and g.winner.abbrev == team1]) team1_wins = len(
team2_wins = len([g for g in series if g.winner and g.winner.abbrev == team2]) [g for g in series if g.winner and g.winner.abbrev == team1]
)
team2_wins = len(
[g for g in series if g.winner and g.winner.abbrev == team2]
)
# Series result # Series result
series_result = f"**{team1} {team1_wins}-{team2_wins} {team2}**" series_result = f"**{team1} {team1_wins}-{team2_wins} {team2}**"
@ -272,25 +304,26 @@ class ScheduleCommands(commands.Cog):
game_details = [] game_details = []
for game in series: for game in series:
if game.series_game_display: if game.series_game_display:
game_details.append(f"{game.series_game_display}: {game.matchup_display}") game_details.append(
f"{game.series_game_display}: {game.matchup_display}"
)
results_lines.append(f"{series_result}\n" + "\n".join(game_details)) results_lines.append(f"{series_result}\n" + "\n".join(game_details))
if results_lines: if results_lines:
embed.add_field( embed.add_field(
name="Series Results", name="Series Results", value="\n\n".join(results_lines), inline=False
value="\n\n".join(results_lines),
inline=False
) )
embed.set_footer(text=f"Season {season} • Week {week}{len(games)} games completed") embed.set_footer(
text=f"Season {season} • Week {week}{len(games)} games completed"
)
return embed return embed
async def _create_recent_results_embed(self, games, season: int) -> discord.Embed: async def _create_recent_results_embed(self, games, season: int) -> discord.Embed:
"""Create an embed for recent results.""" """Create an embed for recent results."""
embed = EmbedTemplate.create_base_embed( embed = EmbedTemplate.create_base_embed(
title=f"🏆 Recent Results - Season {season}", title=f"🏆 Recent Results - Season {season}", color=EmbedColors.SUCCESS
color=EmbedColors.SUCCESS
) )
# Show most recent games # Show most recent games
@ -300,19 +333,18 @@ class ScheduleCommands(commands.Cog):
if recent_lines: if recent_lines:
embed.add_field( embed.add_field(
name="Latest Games", name="Latest Games", value="\n".join(recent_lines), inline=False
value="\n".join(recent_lines),
inline=False
) )
embed.set_footer(text=f"Season {season} • Last {len(games)} completed games") embed.set_footer(text=f"Season {season} • Last {len(games)} completed games")
return embed return embed
async def _create_current_schedule_embed(self, recent_games, upcoming_games, season: int) -> discord.Embed: async def _create_current_schedule_embed(
self, recent_games, upcoming_games, season: int
) -> discord.Embed:
"""Create an embed for current schedule overview.""" """Create an embed for current schedule overview."""
embed = EmbedTemplate.create_base_embed( embed = EmbedTemplate.create_base_embed(
title=f"📅 Current Schedule - Season {season}", title=f"📅 Current Schedule - Season {season}", color=EmbedColors.INFO
color=EmbedColors.INFO
) )
if recent_games: if recent_games:
@ -321,9 +353,7 @@ class ScheduleCommands(commands.Cog):
recent_lines.append(f"Week {game.week}: {game.matchup_display}") recent_lines.append(f"Week {game.week}: {game.matchup_display}")
embed.add_field( embed.add_field(
name="Recent Results", name="Recent Results", value="\n".join(recent_lines), inline=False
value="\n".join(recent_lines),
inline=False
) )
if upcoming_games: if upcoming_games:
@ -332,9 +362,7 @@ class ScheduleCommands(commands.Cog):
upcoming_lines.append(f"Week {game.week}: {game.matchup_display}") upcoming_lines.append(f"Week {game.week}: {game.matchup_display}")
embed.add_field( embed.add_field(
name="Upcoming Games", name="Upcoming Games", value="\n".join(upcoming_lines), inline=False
value="\n".join(upcoming_lines),
inline=False
) )
embed.set_footer(text=f"Season {season}") embed.set_footer(text=f"Season {season}")
@ -344,7 +372,11 @@ class ScheduleCommands(commands.Cog):
"""Format a series summary.""" """Format a series summary."""
lines = [] lines = []
for game in series: for game in series:
game_display = f"{game.series_game_display}: {game.matchup_display}" if game.series_game_display else game.matchup_display game_display = (
f"{game.series_game_display}: {game.matchup_display}"
if game.series_game_display
else game.matchup_display
)
lines.append(game_display) lines.append(game_display)
return "\n".join(lines) if lines else "No games" return "\n".join(lines) if lines else "No games"

View File

@ -156,13 +156,12 @@ class ScheduleService:
logger.error(f"Error getting recent games: {e}") logger.error(f"Error getting recent games: {e}")
return [] return []
async def get_upcoming_games(self, season: int, weeks_ahead: int = 6) -> List[Game]: async def get_upcoming_games(self, season: int) -> List[Game]:
""" """
Get upcoming scheduled games by scanning multiple weeks. Get upcoming scheduled games by scanning all weeks.
Args: Args:
season: Season number season: Season number
weeks_ahead: Number of weeks to scan ahead (default 6)
Returns: Returns:
List of upcoming Game instances List of upcoming Game instances