From f4aaa6ed5299332748b7169f34917c5eca53dc38 Mon Sep 17 00:00:00 2001 From: Sakimori Date: Wed, 3 Feb 2021 03:36:47 -0500 Subject: [PATCH] fixes #171: teamschedule allows viewing of a single team's schedule in a league --- the_prestige.py | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/the_prestige.py b/the_prestige.py index ee6960e..b7e7711 100644 --- a/the_prestige.py +++ b/the_prestige.py @@ -989,7 +989,7 @@ class LeagueScheduleCommand(Command): description = "Sends an embed with the given league's schedule for the next 4 series." async def execute(self, msg, command): - league_name = command.strip() + league_name = command.split("\n")[0].strip() if league_exists(league_name): league = leagues.load_league_file(league_name) current_series = league.day_to_series_num(league.day) @@ -1014,6 +1014,41 @@ class LeagueScheduleCommand(Command): await msg.channel.send("That league's already finished with this season, boss.") else: await msg.channel.send("We can't find that league. Typo?") + +class LeagueTeamScheduleCommand(Command): + name = "teamschedule" + template = "m;teamschedule [league name]\n[team name]" + description = "Sends an embed with the given team's schedule in the given league for the next 7 series." + + async def execute(self, msg, command): + league_name = command.split("\n")[0].strip() + team_name = command.split("\n")[1].strip() + team = get_team_fuzzy_search(team_name) + if league_exists(league_name): + league = leagues.load_league_file(league_name) + current_series = league.day_to_series_num(league.day) + + if team.name not in league.team_names_in_league(): + await msg.channel.send("Can't find that team in that league, chief.") + return + + if str(current_series+1) in league.schedule.keys(): + sched_embed = discord.Embed(title=f"{team.name}'s Schedule for the {league.name}:", color=discord.Color.purple()) + days = [0,1,2,3,4,5,6] + for day in days: + if str(current_series+day) in league.schedule.keys(): + schedule_text = "" + for game in league.schedule[str(current_series+day)]: + if team.name in game: + schedule_text += f"**{game[0]}** @ **{game[1]}**" + if schedule_text == "": + schedule_text += "Resting" + sched_embed.add_field(name=f"Days {((current_series+day-1)*league.series_length) + 1} - {(current_series+day)*(league.series_length)}", value=schedule_text, inline = False) + await msg.channel.send(embed=sched_embed) + else: + await msg.channel.send("That league's already finished with this season, boss.") + else: + await msg.channel.send("We can't find that league. Typo?") commands = [ @@ -1045,6 +1080,7 @@ commands = [ LeagueDisplayCommand(), LeagueWildcardCommand(), LeagueScheduleCommand(), + LeagueTeamScheduleCommand(), CreditCommand(), RomanCommand(), HelpCommand(),