diff --git a/league_storage.py b/league_storage.py index 63a7fe7..dcc4555 100644 --- a/league_storage.py +++ b/league_storage.py @@ -98,7 +98,8 @@ def save_league(league): "series_length" : league.series_length, "games_per_hour" : league.games_per_hour, "owner" : league.owner, - "historic" : league.historic + "historic" : league.historic, + "season" : league.season } with open(os.path.join(data_dir, league_dir, league.name, f"{league.name}.state"), "w") as state_file: json.dump(state_dic, state_file, indent=4) @@ -154,5 +155,5 @@ def league_exists(league_name): with os.scandir(os.path.join(data_dir, league_dir)) as folder: for subfolder in folder: if league_name in subfolder.name: - return not state(league_name)["historic"] + return True return False \ No newline at end of file diff --git a/leagues.py b/leagues.py index b685d8a..791a1ec 100644 --- a/leagues.py +++ b/leagues.py @@ -12,6 +12,7 @@ class league_structure(object): self.name = name self.historic = False self.owner = None + self.season = 1 def setup(self, league_dic, division_games = 1, inter_division_games = 1, inter_league_games = 1, games_per_hour = 2): self.league = league_dic #key: subleague, value: {division : team_name} @@ -332,4 +333,7 @@ def load_league_file(league_name): this_league.game_length = state_dic["game_length"] this_league.series_length = state_dic["series_length"] this_league.owner = state_dic["owner"] + this_league.games_per_hour = state_dic["games_per_hour"] + this_league.historic = state_dic["historic"] + this_league.season = state_dic["season"] return this_league \ No newline at end of file diff --git a/main_controller.py b/main_controller.py index c66af65..d2338be 100644 --- a/main_controller.py +++ b/main_controller.py @@ -150,4 +150,4 @@ def update_loop(): state["update_pause"] -= 1 socketio.emit("states_update", game_states) - time.sleep(4) \ No newline at end of file + time.sleep(1) \ No newline at end of file diff --git a/the_prestige.py b/the_prestige.py index aad0568..ef99604 100644 --- a/the_prestige.py +++ b/the_prestige.py @@ -726,7 +726,7 @@ class StartDraftCommand(Command): return draft_message class DebugLeagueStart(Command): - name = "startleague" + name = "startdebugleague" async def execute(self, msg, command): if not league_exists("test2"): @@ -743,19 +743,50 @@ class DebugLeagueStart(Command): }, division_games=6, inter_division_games=3, inter_league_games=3, games_per_hour = 12) league.generate_schedule() leagues.save_league(league) - else: - league = leagues.load_league_file("test2") - await start_league_day(msg.channel, league, autoplay = 2) class DebugLeagueDisplay(Command): - name = "displayleague" + name = "displaydebugleague" async def execute(self, msg, command): if league_exists("test2"): league = leagues.load_league_file("test2") await msg.channel.send(embed=league.standings_embed()) +class StartLeagueCommand(Command): + name = "startleague" + template = "m;startleague [league name]" + description = """Optional flag: `--queue X` or `-q X` to play X number of series before stopping. +Plays a league with a given name, provided that league has been saved on the website.""" + async def execute(self, msg, command): + league_name = command.split("-").strip() + autoplay = None + + try: + if "--queue " in command: + autoplay = int(command.split("--queue ")[1]) + elif "-q " in command: + autoplay = int(command.split("--queue ")[1]) + if autoplay is not None and autoplay <= 0: + raise ValueError + elif autoplay is None: + autoplay = -1 + except: + await msg.channel.send("Sorry boss, the queue flag needs a natural number. Any whole number over 0 will do just fine.") + return + + if league_exists(league_name): + league = leagues.load_league_file(league_name) + if league.historic: + await msg.channel.send("That league is done and dusted, chief. Sorry.") + return + for active_league in active_leagues: + if active_league.name == league.name: + await msg.channel.send("That league is already running, boss. Patience is a virtue, you know.") + return + await start_league_day(msg.channel, league, autoplay = autoplay) + else: + await msg.channel.send("Couldn't find that league, boss. Did you save it on the website?") commands = [ IntroduceCommand(), @@ -1464,7 +1495,8 @@ async def start_league_day(channel, league, autoplay = 1): async def league_day_watcher(channel, league, games_list, filter_url, autoplay, last = False): league.active = True autoplay -= 1 - active_leagues.append(league) + if league not in active_leagues: + active_leagues.append(league) series_results = {} while league.active: