New schedule command
This commit is contained in:
parent
86eab613aa
commit
44c5438afb
186
cogs/players.py
186
cogs/players.py
@ -836,6 +836,9 @@ class Players(commands.Cog):
|
|||||||
|
|
||||||
@commands.command(name='schedule', help='This week and next')
|
@commands.command(name='schedule', help='This week and next')
|
||||||
async def schedule_command(self, ctx, week: Optional[int] = None):
|
async def schedule_command(self, ctx, week: Optional[int] = None):
|
||||||
|
await ctx.send(f'This command has been deprecated, please use `/schedule`')
|
||||||
|
return
|
||||||
|
|
||||||
current = await db_get('current')
|
current = await db_get('current')
|
||||||
|
|
||||||
if week is not None:
|
if week is not None:
|
||||||
@ -956,6 +959,171 @@ class Players(commands.Cog):
|
|||||||
)
|
)
|
||||||
await ctx.send(content=None, embed=embed)
|
await ctx.send(content=None, embed=embed)
|
||||||
|
|
||||||
|
@app_commands.command(name='schedule', description='View league schedules')
|
||||||
|
@app_commands.describe(
|
||||||
|
season='Optional: Defaults to current season',
|
||||||
|
team_abbrev='Optional: View schedule for this specifc team',
|
||||||
|
week_num='Optional: View schedule for this specific week'
|
||||||
|
)
|
||||||
|
@app_commands.checks.has_any_role(SBA_PLAYERS_ROLE_NAME)
|
||||||
|
async def schedule_slash(self, interaction: discord.Interaction, team_abbrev: str = None, week_num: int = None, season: int = SBA_SEASON):
|
||||||
|
await interaction.response.defer()
|
||||||
|
current = await db_get('current')
|
||||||
|
|
||||||
|
this_team = None
|
||||||
|
param_list = [('season', season)]
|
||||||
|
|
||||||
|
if team_abbrev is not None:
|
||||||
|
this_team = await get_team_by_abbrev(team_abbrev=team_abbrev, season=season)
|
||||||
|
if this_team is None:
|
||||||
|
await interaction.edit_original_response(
|
||||||
|
content=f'I, uh, I don\'t, um...I don\'t quite know ~~how to answer that~~ who {team_abbrev} is.'
|
||||||
|
)
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
param_list.append(('team1_id', this_team['id']))
|
||||||
|
|
||||||
|
if week_num is not None:
|
||||||
|
param_list.append(('week', week_num))
|
||||||
|
|
||||||
|
g_query = await db_get('games', params=param_list)
|
||||||
|
if g_query['count'] == 0:
|
||||||
|
await interaction.edit_original_response(
|
||||||
|
content=f'Hm. I don\'t see any games then.'
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
if team_abbrev is not None:
|
||||||
|
title = f'{this_team["lname"]} Schedule'
|
||||||
|
embed = get_team_embed(title=title, team=this_team)
|
||||||
|
|
||||||
|
else:
|
||||||
|
title = 'SBa Schedule'
|
||||||
|
embed = get_team_embed(title=title)
|
||||||
|
|
||||||
|
if week_num is not None:
|
||||||
|
embed.description = f'Week {week_num}'
|
||||||
|
|
||||||
|
embed.add_field(
|
||||||
|
name='Full Schedule',
|
||||||
|
value=SBA_SCHEDULE_URL,
|
||||||
|
inline=False
|
||||||
|
)
|
||||||
|
|
||||||
|
# Full league schedule
|
||||||
|
if team_abbrev is None:
|
||||||
|
all_games = {}
|
||||||
|
games_played = 0
|
||||||
|
|
||||||
|
for x in g_query['games']:
|
||||||
|
if x['away_score'] is not None:
|
||||||
|
games_played += 1
|
||||||
|
|
||||||
|
game_id = f'{x["away_team"]["id"]}-{x["home_team"]["id"]}'
|
||||||
|
if game_id not in all_games:
|
||||||
|
all_games[game_id] = {
|
||||||
|
'away_wins': 0, 'home_wins': 0, 'away_team': x["away_team"], 'home_team': x["home_team"]
|
||||||
|
}
|
||||||
|
|
||||||
|
if x['away_score'] is not None:
|
||||||
|
if x['away_score'] > x['home_score']:
|
||||||
|
all_games[game_id]['away_wins'] += 1
|
||||||
|
else:
|
||||||
|
all_games[game_id]['home_wins'] += 1
|
||||||
|
|
||||||
|
for x in all_games.values():
|
||||||
|
away_record = await db_get(f'standings/team/{x["away_team"]["id"]}')
|
||||||
|
home_record = await db_get(f'standings/team/{x["home_team"]["id"]}')
|
||||||
|
|
||||||
|
this_line = f'({x["away_wins"]}) [{x["away_team"]["lname"]: >4}]({SBA_BASE_URL}/teams/{current["season"]}/{x["away_team"]["abbrev"]}) ({away_record["wins"]}-{away_record["losses"]})\n@\n({x["home_wins"]}) [{x["home_team"]["lname"]: <4}]({SBA_BASE_URL}/teams/{current["season"]}/{x["home_team"]["abbrev"]}) ({home_record["wins"]}-{home_record["losses"]})\n\n'
|
||||||
|
|
||||||
|
logger.info(f'standings_slash - this_line:\n{this_line}')
|
||||||
|
embed.add_field(
|
||||||
|
# name=f'{await team_emoji(interaction, x["away_team"])} {x["away_team"]["abbrev"]} @ {x["home_team"]["abbrev"]} {await team_emoji(interaction, x["home_team"])}',
|
||||||
|
name='_____',
|
||||||
|
value=this_line,
|
||||||
|
inline=False
|
||||||
|
)
|
||||||
|
|
||||||
|
# string_this_week += this_line
|
||||||
|
# logger.info(f'Adding to string_this_week:\n{this_line}')
|
||||||
|
|
||||||
|
embed.description = f'{games_played} / {"32" if current["week_num"] <= 18 else "??"}'
|
||||||
|
await interaction.edit_original_response(
|
||||||
|
content=None,
|
||||||
|
embed=embed
|
||||||
|
)
|
||||||
|
|
||||||
|
else:
|
||||||
|
if week_num is not None:
|
||||||
|
count = 1
|
||||||
|
for game in g_query['games']:
|
||||||
|
if game['game_num'] is not None:
|
||||||
|
game_title = f'Game {game["game_num"]}'
|
||||||
|
if game['away_score'] > game['home_score']:
|
||||||
|
away_hype = '**'
|
||||||
|
home_hype = ''
|
||||||
|
else:
|
||||||
|
away_hype = ''
|
||||||
|
home_hype = '**'
|
||||||
|
|
||||||
|
game_string = f'{away_hype}{game["away_team"]["abbrev"]} {game["away_score"]}{away_hype} @ {game["home_score"]} {home_hype}{game["home_team"]["abbrev"]}{home_hype}\nAway Manager: [{game["away_manager"]["name"]}]({SBA_BASE_URL}/managers/{game["away_manager"]["name"]})\nHome Manager: [{game["home_manager"]["name"]}]({SBA_BASE_URL}/managers/{game["home_manager"]["name"]})\n[Scorecard]({game["scorecard_url"]})'
|
||||||
|
|
||||||
|
else:
|
||||||
|
game_title = f'Game {count}'
|
||||||
|
game_string = f'{game["away_team"]["abbrev"]} @ {game["home_team"]["abbrev"]}\n-# Not played, yet'
|
||||||
|
|
||||||
|
embed.add_field(
|
||||||
|
name=game_title,
|
||||||
|
value=game_string,
|
||||||
|
inline=False
|
||||||
|
)
|
||||||
|
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
await interaction.edit_original_response(
|
||||||
|
content=None,
|
||||||
|
embed=embed
|
||||||
|
)
|
||||||
|
|
||||||
|
else:
|
||||||
|
all_weeks = {}
|
||||||
|
|
||||||
|
for game in g_query['games']:
|
||||||
|
if game['week'] not in all_weeks:
|
||||||
|
all_weeks[game['week']] = [game]
|
||||||
|
else:
|
||||||
|
all_weeks[game['week']].append(game)
|
||||||
|
|
||||||
|
sorted_dict = {key: all_weeks[key] for key in sorted(all_weeks)}
|
||||||
|
for week in sorted_dict:
|
||||||
|
week_string = ''
|
||||||
|
for game in all_weeks[week]:
|
||||||
|
if game['away_team'] == this_team:
|
||||||
|
week_string += f'at {game["home_team"]["abbrev"]}'
|
||||||
|
|
||||||
|
if game['away_score'] is not None:
|
||||||
|
week_string += f' ({"L" if game["home_score"] > game["away_score"] else "W"} {game["away_score"]}-{game["home_score"]})'
|
||||||
|
|
||||||
|
else:
|
||||||
|
week_string += f'vs {game["away_team"]["abbrev"]}'
|
||||||
|
|
||||||
|
if game['home_score'] is not None:
|
||||||
|
week_string += f' ({"L" if game["home_score"] < game["away_score"] else "W"} {game["home_score"]}-{game["away_score"]})'
|
||||||
|
|
||||||
|
week_string += '\n'
|
||||||
|
|
||||||
|
embed.add_field(
|
||||||
|
name=f'Week {week}',
|
||||||
|
value=week_string
|
||||||
|
)
|
||||||
|
|
||||||
|
await interaction.edit_original_response(
|
||||||
|
content=None,
|
||||||
|
embed=embed
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@commands.command(name='weather', help='Roll ballpark weather')
|
@commands.command(name='weather', help='Roll ballpark weather')
|
||||||
async def weather_command(self, ctx, team_abbrev=None):
|
async def weather_command(self, ctx, team_abbrev=None):
|
||||||
current = await db_get('current')
|
current = await db_get('current')
|
||||||
@ -983,19 +1151,19 @@ class Players(commands.Cog):
|
|||||||
|
|
||||||
async def get_division_standings(self, current) -> discord.Embed:
|
async def get_division_standings(self, current) -> discord.Embed:
|
||||||
d1_query = await db_get('standings', params=[
|
d1_query = await db_get('standings', params=[
|
||||||
('season', current['season']), ('division_abbrev', 'SWW')
|
('season', current['season']), ('division_abbrev', 'SD')
|
||||||
])
|
])
|
||||||
div_one = d1_query['standings']
|
div_one = d1_query['standings']
|
||||||
d2_query = await db_get('standings', params=[
|
d2_query = await db_get('standings', params=[
|
||||||
('season', current['season']), ('division_abbrev', 'BBVW')
|
('season', current['season']), ('division_abbrev', 'DC')
|
||||||
])
|
])
|
||||||
div_two = d2_query['standings']
|
div_two = d2_query['standings']
|
||||||
d3_query = await db_get('standings', params=[
|
d3_query = await db_get('standings', params=[
|
||||||
('season', current['season']), ('division_abbrev', 'WN')
|
('season', current['season']), ('division_abbrev', 'FIP')
|
||||||
])
|
])
|
||||||
div_three = d3_query['standings']
|
div_three = d3_query['standings']
|
||||||
d4_query = await db_get('standings', params=[
|
d4_query = await db_get('standings', params=[
|
||||||
('season', current['season']), ('division_abbrev', 'PP')
|
('season', current['season']), ('division_abbrev', 'DOC')
|
||||||
])
|
])
|
||||||
div_four = d4_query['standings']
|
div_four = d4_query['standings']
|
||||||
|
|
||||||
@ -1025,10 +1193,10 @@ class Players(commands.Cog):
|
|||||||
f'{progress["games_played"]}/{progress["game_count"]} games played',
|
f'{progress["games_played"]}/{progress["game_count"]} games played',
|
||||||
color=0xB70000)
|
color=0xB70000)
|
||||||
embed.add_field(name=f'**Full Standings**', value=SBA_STANDINGS_URL, inline=False)
|
embed.add_field(name=f'**Full Standings**', value=SBA_STANDINGS_URL, inline=False)
|
||||||
embed.add_field(name=f'**Ice Cream**', value=div_one_standings, inline=False)
|
embed.add_field(name=f'**Snow Day**', value=div_one_standings, inline=False)
|
||||||
embed.add_field(name=f'**Hobgoblins**', value=div_two_standings, inline=False)
|
embed.add_field(name=f'**Dinger Central**', value=div_two_standings, inline=False)
|
||||||
embed.add_field(name=f'**Dinger Central**', value=div_three_standings, inline=False)
|
embed.add_field(name=f'**Just the FIP**', value=div_three_standings, inline=False)
|
||||||
embed.add_field(name=f'**Milkshakes**', value=div_four_standings, inline=False)
|
embed.add_field(name=f'**Division of Cook**', value=div_four_standings, inline=False)
|
||||||
|
|
||||||
return embed
|
return embed
|
||||||
|
|
||||||
@ -1058,7 +1226,7 @@ class Players(commands.Cog):
|
|||||||
f'{progress["games_played"]}/{progress["game_count"]} games played',
|
f'{progress["games_played"]}/{progress["game_count"]} games played',
|
||||||
color=0xB70000)
|
color=0xB70000)
|
||||||
embed.add_field(name=f'**Full Standings**', value=SBA_STANDINGS_URL, inline=False)
|
embed.add_field(name=f'**Full Standings**', value=SBA_STANDINGS_URL, inline=False)
|
||||||
embed.add_field(name=f'**AL Wildcard**', value=al_wildcard, inline=False)
|
embed.add_field(name=f'**Wildcard**', value=al_wildcard, inline=False)
|
||||||
# embed.add_field(name=f'**NL Wildcard**', value=nl_wildcard, inline=False)
|
# embed.add_field(name=f'**NL Wildcard**', value=nl_wildcard, inline=False)
|
||||||
|
|
||||||
return embed
|
return embed
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user