startleague command attempt
This commit is contained in:
parent
3def1378a9
commit
5826574a1d
|
@ -98,7 +98,8 @@ def save_league(league):
|
||||||
"series_length" : league.series_length,
|
"series_length" : league.series_length,
|
||||||
"games_per_hour" : league.games_per_hour,
|
"games_per_hour" : league.games_per_hour,
|
||||||
"owner" : league.owner,
|
"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:
|
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)
|
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:
|
with os.scandir(os.path.join(data_dir, league_dir)) as folder:
|
||||||
for subfolder in folder:
|
for subfolder in folder:
|
||||||
if league_name in subfolder.name:
|
if league_name in subfolder.name:
|
||||||
return not state(league_name)["historic"]
|
return True
|
||||||
return False
|
return False
|
|
@ -12,6 +12,7 @@ class league_structure(object):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.historic = False
|
self.historic = False
|
||||||
self.owner = None
|
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):
|
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}
|
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.game_length = state_dic["game_length"]
|
||||||
this_league.series_length = state_dic["series_length"]
|
this_league.series_length = state_dic["series_length"]
|
||||||
this_league.owner = state_dic["owner"]
|
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
|
return this_league
|
|
@ -150,4 +150,4 @@ def update_loop():
|
||||||
state["update_pause"] -= 1
|
state["update_pause"] -= 1
|
||||||
|
|
||||||
socketio.emit("states_update", game_states)
|
socketio.emit("states_update", game_states)
|
||||||
time.sleep(4)
|
time.sleep(1)
|
|
@ -726,7 +726,7 @@ class StartDraftCommand(Command):
|
||||||
return draft_message
|
return draft_message
|
||||||
|
|
||||||
class DebugLeagueStart(Command):
|
class DebugLeagueStart(Command):
|
||||||
name = "startleague"
|
name = "startdebugleague"
|
||||||
|
|
||||||
async def execute(self, msg, command):
|
async def execute(self, msg, command):
|
||||||
if not league_exists("test2"):
|
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)
|
}, division_games=6, inter_division_games=3, inter_league_games=3, games_per_hour = 12)
|
||||||
league.generate_schedule()
|
league.generate_schedule()
|
||||||
leagues.save_league(league)
|
leagues.save_league(league)
|
||||||
else:
|
|
||||||
league = leagues.load_league_file("test2")
|
|
||||||
await start_league_day(msg.channel, league, autoplay = 2)
|
|
||||||
|
|
||||||
class DebugLeagueDisplay(Command):
|
class DebugLeagueDisplay(Command):
|
||||||
name = "displayleague"
|
name = "displaydebugleague"
|
||||||
|
|
||||||
async def execute(self, msg, command):
|
async def execute(self, msg, command):
|
||||||
if league_exists("test2"):
|
if league_exists("test2"):
|
||||||
league = leagues.load_league_file("test2")
|
league = leagues.load_league_file("test2")
|
||||||
await msg.channel.send(embed=league.standings_embed())
|
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 = [
|
commands = [
|
||||||
IntroduceCommand(),
|
IntroduceCommand(),
|
||||||
|
@ -1464,6 +1495,7 @@ async def start_league_day(channel, league, autoplay = 1):
|
||||||
async def league_day_watcher(channel, league, games_list, filter_url, autoplay, last = False):
|
async def league_day_watcher(channel, league, games_list, filter_url, autoplay, last = False):
|
||||||
league.active = True
|
league.active = True
|
||||||
autoplay -= 1
|
autoplay -= 1
|
||||||
|
if league not in active_leagues:
|
||||||
active_leagues.append(league)
|
active_leagues.append(league)
|
||||||
series_results = {}
|
series_results = {}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user