diff --git a/games.py b/games.py index 8a375a4..b6763b2 100644 --- a/games.py +++ b/games.py @@ -171,7 +171,12 @@ class team(object): self.pitcher = temp_rotation[rotation_slot % len(temp_rotation)] def is_ready(self): - return (len(self.lineup) >= 1 and len(self.rotation) > 0) + try: + return (len(self.lineup) >= 1 and len(self.rotation) > 0) + except AttributeError: + self.rotation = [self.pitcher] + self.pitcher = None + return (len(self.lineup) >= 1 and len(self.rotation) > 0) def prepare_for_save(self): self.lineup_position = 0 diff --git a/the_prestige.py b/the_prestige.py index 96d2002..675ddf0 100644 --- a/the_prestige.py +++ b/the_prestige.py @@ -179,6 +179,22 @@ class StartGameCommand(Command): await msg.channel.send("We can't find one or both of those teams. Check your staging, chief.") return +class StartRandomGameCommand(Command): + name = "randomgame" + template = "m;randomgame" + description = "Starts a 9-inning game between 2 entirely random teams. Embrace chaos." + + async def execute(self, msg, command): + channel = msg.channel + await msg.delete() + await channel.send("Rolling the bones...") + teamslist = games.get_all_teams() + + game = games.game(msg.author.name, random.choice(teamslist).finalize(), random.choice(teamslist).finalize(), length=3) + + game_task = asyncio.create_task(watch_game(channel, game, user="the winds of chaos")) + await game_task + class SetupGameCommand(Command): name = "setupgame" template = "m;setupgame" @@ -488,6 +504,7 @@ commands = [ ShowAllTeamsCommand(), SearchTeamsCommand(), StartGameCommand(), + StartRandomGameCommand(), CreditCommand(), RomanCommand(), HelpCommand(), @@ -740,7 +757,10 @@ async def watch_game(channel, newgame, user = None, league = None): discrim_string = league state_init["is_league"] = True elif user is not None: - discrim_string = f"Started by {user.name}" + if isinstance(user, str): + discrim_string = f"Started by {user}" + else: + discrim_string = f"Started by {user.name}" state_init["is_league"] = False else: discrim_string = "Unclaimed game." @@ -941,38 +961,41 @@ async def team_pages(msg, all_teams, search_term=None): async def game_watcher(): while True: - try: - this_array = gamesarray.copy() - for i in range(0,len(this_array)): - game, channel, user, key = this_array[i] - if game.over and main_controller.master_games_dic[key][1]["end_delay"] <= 9: - title_string = f"{game.teams['away'].name} at {game.teams['home'].name} ended after {game.inning-1} innings" - if (game.inning - 1) > game.max_innings: #if extra innings - title_string += f" with {game.inning - (game.max_innings+1)} extra innings." - else: - title_string += "." + #try: + this_array = gamesarray.copy() + for i in range(0,len(this_array)): + game, channel, user, key = this_array[i] + if game.over and main_controller.master_games_dic[key][1]["end_delay"] <= 9: + title_string = f"{game.teams['away'].name} at {game.teams['home'].name} ended after {game.inning-1} innings" + if (game.inning - 1) > game.max_innings: #if extra innings + title_string += f" with {game.inning - (game.max_innings+1)} extra innings." + else: + title_string += "." - winning_team = game.teams['home'].name if game.teams['home'].score > game.teams['away'].score else game.teams['away'].name - winstring = f"{game.teams['away'].score} to {game.teams['home'].score}\n" - if game.victory_lap and winning_team == game.teams['home'].name: - winstring += f"{winning_team} wins with a victory lap!" - elif winning_team == game.teams['home'].name: - winstring += f"{winning_team} wins, shaming {game.teams['away'].name}!" - else: - winstring += f"{winning_team} wins!" + winning_team = game.teams['home'].name if game.teams['home'].score > game.teams['away'].score else game.teams['away'].name + winstring = f"{game.teams['away'].score} to {game.teams['home'].score}\n" + if game.victory_lap and winning_team == game.teams['home'].name: + winstring += f"{winning_team} wins with a victory lap!" + elif winning_team == game.teams['home'].name: + winstring += f"{winning_team} wins, shaming {game.teams['away'].name}!" + else: + winstring += f"{winning_team} wins!" - if user is not None: + if user is not None: + if isinstance(user, str): + await channel.send(f"A game from {user} just ended.") + else: await channel.send(f"{user.mention}'s game just ended.") - else: - await channel.send("A game started from this channel just ended.") + else: + await channel.send("A game started from this channel just ended.") - final_embed = discord.Embed(color=discord.Color.dark_purple(), title=title_string) - final_embed.add_field(name="Final score:", value=winstring) - await channel.send(embed=final_embed) - gamesarray.pop(i) - break - except: - print("something broke in game_watcher") + final_embed = discord.Embed(color=discord.Color.dark_purple(), title=title_string) + final_embed.add_field(name="Final score:", value=winstring) + await channel.send(embed=final_embed) + gamesarray.pop(i) + break + #except: + #print("something broke in game_watcher") await asyncio.sleep(6)