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
@ -19,19 +20,16 @@ from views.embeds import EmbedColors, EmbedTemplate
class ScheduleCommands(commands.Cog): class ScheduleCommands(commands.Cog):
"""League schedule command handlers.""" """League schedule command handlers."""
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,13 +38,13 @@ 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()
search_season = season or get_config().sba_season search_season = season or get_config().sba_season
if team: if team:
# Show team schedule # Show team schedule
await self._show_team_schedule(interaction, search_season, team, week) await self._show_team_schedule(interaction, search_season, team, week)
@ -56,7 +54,7 @@ class ScheduleCommands(commands.Cog):
else: else:
# Show recent/upcoming games # Show recent/upcoming games
await self._show_current_schedule(interaction, search_season) await self._show_current_schedule(interaction, search_season)
# @discord.app_commands.command( # @discord.app_commands.command(
# name="results", # name="results",
# description="Display recent game results" # description="Display recent game results"
@ -74,282 +72,316 @@ class ScheduleCommands(commands.Cog):
# ): # ):
# """Display recent game results.""" # """Display recent game results."""
# await interaction.response.defer() # await interaction.response.defer()
# search_season = season or get_config().sba_season # search_season = season or get_config().sba_season
# if week: # if week:
# # Show specific week results # # Show specific week results
# games = await schedule_service.get_week_schedule(search_season, week) # games = await schedule_service.get_week_schedule(search_season, week)
# completed_games = [game for game in games if game.is_completed] # completed_games = [game for game in games if game.is_completed]
# if not completed_games: # if not completed_games:
# await interaction.followup.send( # await interaction.followup.send(
# f"❌ No completed games found for season {search_season}, week {week}.", # f"❌ No completed games found for season {search_season}, week {week}.",
# ephemeral=True # ephemeral=True
# ) # )
# return # return
# embed = await self._create_week_results_embed(completed_games, search_season, week) # embed = await self._create_week_results_embed(completed_games, search_season, week)
# await interaction.followup.send(embed=embed) # await interaction.followup.send(embed=embed)
# else: # else:
# # Show recent results # # Show recent results
# recent_games = await schedule_service.get_recent_games(search_season) # recent_games = await schedule_service.get_recent_games(search_season)
# if not recent_games: # if not recent_games:
# await interaction.followup.send( # await interaction.followup.send(
# f"❌ No recent games found for season {search_season}.", # f"❌ No recent games found for season {search_season}.",
# ephemeral=True # ephemeral=True
# ) # )
# return # return
# 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)
games = await schedule_service.get_week_schedule(season, week) games = await schedule_service.get_week_schedule(season, week)
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)
if week: if week:
# 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)
team_games = await schedule_service.get_team_schedule(season, team, weeks=4) team_games = await schedule_service.get_team_schedule(season, team, weeks=4)
if not team_games: if not team_games:
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
series_games = schedule_service.group_games_by_series(games) series_games = schedule_service.group_games_by_series(games)
schedule_lines = [] schedule_lines = []
for (team1, team2), series in series_games.items(): for (team1, team2), series in series_games.items():
series_summary = await self._format_series_summary(series) series_summary = await self._format_series_summary(series)
schedule_lines.append(f"**{team1} vs {team2}**\n{series_summary}") schedule_lines.append(f"**{team1} vs {team2}**\n{series_summary}")
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
completed = len([g for g in games if g.is_completed]) completed = len([g for g in games if g.is_completed])
total = len(games) total = len(games)
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
completed_games = [g for g in games if g.is_completed] completed_games = [g for g in games if g.is_completed]
upcoming_games = [g for g in games if not g.is_completed] upcoming_games = [g for g in games if not g.is_completed]
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:
upcoming_lines = [] upcoming_lines = []
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
series_games = schedule_service.group_games_by_series(games) series_games = schedule_service.group_games_by_series(games)
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}**"
# Individual games # Individual games
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
recent_lines = [] recent_lines = []
for game in games[:10]: # Show last 10 games for game in games[:10]: # Show last 10 games
recent_lines.append(f"Week {game.week}: {game.matchup_display}") recent_lines.append(f"Week {game.week}: {game.matchup_display}")
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:
recent_lines = [] recent_lines = []
for game in recent_games[:5]: for game in recent_games[:5]:
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:
upcoming_lines = [] upcoming_lines = []
for game in upcoming_games[:5]: for game in upcoming_games[:5]:
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}")
return embed return embed
async def _format_series_summary(self, series) -> str: async def _format_series_summary(self, series) -> str:
"""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"
async def setup(bot: commands.Bot): async def setup(bot: commands.Bot):
"""Load the schedule commands cog.""" """Load the schedule commands cog."""
await bot.add_cog(ScheduleCommands(bot)) await bot.add_cog(ScheduleCommands(bot))

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