From 2d5458904a48d4537a675003465490ccb1fe34ae Mon Sep 17 00:00:00 2001 From: Kevin Rode Date: Mon, 4 Jan 2021 22:05:29 -0500 Subject: [PATCH] Re added tournament command --- the_prestige.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/the_prestige.py b/the_prestige.py index 573b9d7..525ec88 100644 --- a/the_prestige.py +++ b/the_prestige.py @@ -492,6 +492,54 @@ class ShowHistoryCommand(Command): async def execute(self, msg, command): list_task = asyncio.create_task(history_pages(msg, games.get_history())) +class StartTournamentCommand(Command): + name = "starttournament" + template = """m;starttournament + [tournament name] + [list of teams, each on a new line]""" + description = "Starts a randomly seeded tournament with up to 64 provided teams, automatically adding byes as necessary. All series have a 5 minute break between games and by default there is a 10 minute break between rounds. The current tournament format is:\nBest of 5 until the finals, which are Best of 7." + + 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 + + to_parse = command.split("\n")[0] + if "--rounddelay " in to_parse: + try: + round_delay = int(to_parse.split("--rounddelay ")[1].split(" ")[0]) + except ValueError: + await msg.channel.send("The delay between rounds should be a whole number.") + return + if round_delay < 1 or round_delay > 120: + await msg.channel.send("The delay between rounds has to be between 1 and 120 minutes.") + else: + round_delay = 10 + + tourney_name = command.split("\n")[1] + list_of_team_names = command.split("\n")[2:] + team_dic = {} + for name in list_of_team_names: + team = get_team_fuzzy_search(name.strip()) + if team == None: + await msg.channel.send(f"We couldn't find {name}. Try again?") + return + team_dic[team] = {"wins": 0} + + channel = msg.channel + await msg.delete() + + if len(team_dic) < 2: + await msg.channel.send("One team does not a tournament make.") + return + + id = random.randint(1111,9999) + + tourney = leagues.tournament(tourney_name, team_dic, id=id, secs_between_rounds = round_delay * 60) + tourney.build_bracket(random_sort = True) + + + await start_tournament_round(channel, tourney) commands = [