added m;leagueschedule

This commit is contained in:
Sakimori 2021-01-15 04:27:20 -05:00
parent 5eec52db62
commit af7112367d
2 changed files with 52 additions and 14 deletions

View File

@ -233,6 +233,8 @@ class league_structure(object):
teams.sort(key=sorter, reverse=True)
return teams
def season_length(self):
return self.constraints["division_games"]*(len(random.choice(random.choice(league))-1)) + self.constraints["inter_div_games"] + self.constraints["inter_league_games"]
def standings_embed(self):
this_embed = Embed(color=Color.purple(), title=self.name)
@ -242,7 +244,6 @@ class league_structure(object):
for subleague in iter(self.league.keys()):
this_embed.add_field(name="Subleague:", value=f"**{subleague}**", inline = False)
for division in iter(self.league[subleague].keys()):
this_embed.add_field(name="Division:", value=f"**{division}**", inline = False)
teams = self.division_standings(self.league[subleague][division], standings)
for index in range(0, len(teams)):
@ -251,14 +252,16 @@ class league_structure(object):
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:
this_embed.add_field(name=this_team[0].name, value=f"{this_team[1]} - {this_team[2]} WR: {round(this_team[1]/(this_team[1]+this_team[2]), 3)} GB: {this_team[4]}", inline = False)
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:
this_embed.add_field(name=this_team[0].name, value=f"{this_team[1]} - {this_team[2]} WR: - GB: {this_team[4]}", inline = False)
teams_string += f"**{this_team[0].name}\n**{this_team[1]} - {this_team[2]} WR: - GB: {this_team[4]}\n\n"
this_embed.set_footer(text=f"Standings as of day {self.day-1}")
this_embed.add_field(name=f"{division} 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):
@ -267,14 +270,13 @@ class league_structure(object):
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}
for subleague in iter(self.league.keys()):
this_embed.add_field(name="Subleague:", value=f"**{subleague}**", inline = False)
subleague_array = []
for division in iter(self.league[subleague].keys()):
this_div = [this_team for this_team, wins, losses, diff, gb in self.division_standings(self.league[subleague][division], standings)[self.constraints["division_leaders"]:]]
subleague_array += this_div
teams = self.division_standings(subleague_array, standings)
teams_string = ""
for index in range(0, len(teams)):
if index == self.constraints["wild_cards"] - 1:
teams[index][4] = "-"
@ -284,9 +286,11 @@ class league_structure(object):
for this_team in teams:
if this_team[2] != 0 or this_team[1] != 0:
this_embed.add_field(name=this_team[0].name, value=f"{this_team[1]} - {this_team[2]} WR: {round(this_team[1]/(this_team[1]+this_team[2]), 3)} GB: {this_team[4]}", inline = False)
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:
this_embed.add_field(name=this_team[0].name, value=f"{this_team[1]} - {this_team[2]} WR: - GB: {this_team[4]}", inline = False)
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"{subleague} League:", value=teams_string, inline = False)
this_embed.set_footer(text=f"Wildcard standings as of day {self.day-1}")
return this_embed
@ -313,7 +317,7 @@ class league_structure(object):
for this_team, wins, losses, diff, gb in division_leaders + wildcard_leaders:
team_dic[this_team] = {"wins" : wins}
subleague_tournament = tournament(f"{self.name} {subleague} Championship Series", team_dic, secs_between_games=int(3600/self.games_per_hour), secs_between_rounds=int(7200/self.games_per_hour))
subleague_tournament = tournament(f"{self.name} {subleague} Championship Series", team_dic, series_length=3, finals_series_length=5, secs_between_games=int(3600/self.games_per_hour), secs_between_rounds=int(7200/self.games_per_hour))
subleague_tournament.build_bracket(by_wins = True)
subleague_tournament.league = self
tournaments.append(subleague_tournament)

View File

@ -764,6 +764,10 @@ class StartLeagueCommand(Command):
Plays a league with a given name, provided that league has been saved on the website. The games per hour sets how often the games will start. (e.g. GPH 2 will start games at X:00 and X:30)"""
async def execute(self, msg, command):
if config()["game_freeze"]:
await msg.channel.send("Patch incoming. We're not allowing new games right now.")
return
league_name = command.split("-")[0].split("\n")[0].strip()
autoplay = None
@ -851,6 +855,33 @@ class LeaguePauseCommand(Command):
if active_league.name == league_name:
active_league.autoplay = 0
await msg.channel.send(f"Loud and clear, chief. {league_name} will stop after this series is over.")
class LeagueScheduleCommand(Command):
name = "leagueschedule"
template = "m;leagueschedule [league name]"
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()
if league_exists(league_name):
league = leagues.load_league_file(league_name)
current_series = league.day_to_series_num(league.day)
if str(current_series+1) in league.schedule.keys():
sched_embed = discord.Embed(title=f"{league.name}'s Schedule:")
days = [0,1,2,3]
for day in days:
if str(current_series+day) in league.schedule.keys():
schedule_text = ""
for game in league.schedule[str(current_series+day)]:
schedule_text += f"**{game[0]}** @ **{game[1]}**\n"
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 = [
IntroduceCommand(),
CountActiveGamesCommand(),
@ -875,6 +906,7 @@ commands = [
LeaguePauseCommand(),
LeagueDisplayCommand(),
LeagueWildcardCommand(),
LeagueScheduleCommand(),
StartRandomGameCommand(),
CreditCommand(),
RomanCommand(),
@ -1162,7 +1194,6 @@ async def start_tournament_round(channel, tourney, seeding = None):
if tourney.league is not None:
team_a.set_pitcher(rotation_slot = tourney.league.day)
team_b.set_pitcher(rotation_slot = tourney.league.day)
league.day += 1
this_game = games.game(team_a.finalize(), team_b.finalize(), length = tourney.game_length)
this_game, state_init = prepare_game(this_game)
@ -1199,7 +1230,7 @@ async def continue_tournament_series(tourney, queue, games_list, wins_in_series)
if tourney.league is not None:
away_team.set_pitcher(rotation_slot = tourney.league.day)
home_team.set_pitcher(rotation_slot = tourney.league.day)
league.day += 1
this_game = games.game(away_team.finalize(), home_team.finalize(), length = tourney.game_length)
this_game, state_init = prepare_game(this_game)
@ -1261,7 +1292,8 @@ async def tourney_round_watcher(channel, tourney, games_list, filter_url, finals
except:
print("something went wrong in tourney_watcher")
await asyncio.sleep(4)
if tourney.league is not None:
tourney.league.day += 1
if len(queued_games) > 0:
@ -1751,9 +1783,11 @@ async def league_day_watcher(channel, league, games_list, filter_url, last = Fal
if league.autoplay == 0: #if number of series to autoplay has been reached
if league.autoplay == 0 or config()["game_freeze"]: #if number of series to autoplay has been reached
await channel.send(embed=league.standings_embed())
await channel.send(f"The {league.name} is no longer autoplaying.")
if config()["game_freeze"]:
await channel.send("Patch incoming.")
leagues.save_league(league)
active_leagues.pop(active_leagues.index(league))
return