diff --git a/leagues.py b/leagues.py index 893943d..8e6c0eb 100644 --- a/leagues.py +++ b/leagues.py @@ -331,6 +331,30 @@ class league_structure(object): this_embed.set_footer(text=f"Standings as of day {self.day-1} / {self.season_length()}") return this_embed + def standings_embed_div(self, division, div_name): + this_embed = Embed(color=Color.purple(), title=f"{self.name} Season {self.season}") + standings = {} + for team_name, wins, losses, run_diff in league_db.get_standings(self.name): + standings[team_name] = {"wins" : wins, "losses" : losses, "run_diff" : run_diff} + teams = self.division_standings(division, standings) + + for index in range(0, len(teams)): + if index == self.constraints["division_leaders"] - 1: + teams[index][4] = "-" + else: + games_behind = ((teams[self.constraints["division_leaders"] - 1][1] - teams[index][1]) + (teams[index][2] - teams[self.constraints["division_leaders"] - 1][2]))/2 + teams[index][4] = games_behind + teams_string = "" + for this_team in teams: + if this_team[2] != 0 or this_team[1] != 0: + teams_string += f"**{this_team[0].name}\n**{this_team[1]} - {this_team[2]} WR: {round(this_team[1]/(this_team[1]+this_team[2]), 3)} GB: {this_team[4]}\n\n" + else: + teams_string += f"**{this_team[0].name}\n**{this_team[1]} - {this_team[2]} WR: - GB: {this_team[4]}\n\n" + + this_embed.add_field(name=f"{div_name} Division:", value=teams_string, inline = False) + this_embed.set_footer(text=f"Standings as of day {self.day-1} / {self.season_length()}") + return this_embed + def wildcard_embed(self): this_embed = Embed(color=Color.purple(), title=f"{self.name} Wildcard Race") standings = {} diff --git a/the_prestige.py b/the_prestige.py index 461ce8f..fe1c37f 100644 --- a/the_prestige.py +++ b/the_prestige.py @@ -877,6 +877,33 @@ class LeagueDisplayCommand(Command): else: await msg.channel.send("Can't find that league, boss.") +class LeagueDivisionDisplayCommand(Command): + name = "divisionstandings" + template = "m;divisionstandings [league name]\n[team name]" + description = "Displays the current standings for the given division in the given league." + + async def execute(self, msg, command): + if league_exists(command.split("\n")[0].strip()): + league = leagues.load_league_file(command.split("\n")[0].strip()) + division_name = command.split("\n")[1].strip() + division = None + for subleague in iter(league.league.keys()): + for div in iter(league.league[subleague].keys()): + if div == division_name: + division = league.league[subleague][div] + if division is None: + await msg.channel.send("Chief, that division doesn't exist in that league.") + return + + try: + await msg.channel.send(embed=league.standings_embed_div(division, division_name)) + except ValueError: + await msg.channel.send("Give us a proper number, boss.") + #except TypeError: + #await msg.channel.send("That season hasn't been played yet, chief.") + else: + await msg.channel.send("Can't find that league, boss.") + class LeagueWildcardCommand(Command): name = "leaguewildcard" template = "m;leaguewildcard [league name]" @@ -1046,6 +1073,7 @@ commands = [ StartLeagueCommand(), LeaguePauseCommand(), LeagueDisplayCommand(), + LeagueDivisionDisplayCommand(), LeagueWildcardCommand(), LeagueScheduleCommand(), LeagueTeamScheduleCommand(), @@ -1054,8 +1082,6 @@ commands = [ HelpCommand(), StartDraftCommand(), DraftPlayerCommand(), - DebugLeagueStart(), - DebugLeagueDisplay() ] client = discord.Client()