added m;randomgame

This commit is contained in:
Sakimori 2021-01-03 17:59:13 -05:00
parent 92cd4a1858
commit a2a6e9d7bb
2 changed files with 58 additions and 30 deletions

View File

@ -171,7 +171,12 @@ class team(object):
self.pitcher = temp_rotation[rotation_slot % len(temp_rotation)] self.pitcher = temp_rotation[rotation_slot % len(temp_rotation)]
def is_ready(self): 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): def prepare_for_save(self):
self.lineup_position = 0 self.lineup_position = 0

View File

@ -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.") await msg.channel.send("We can't find one or both of those teams. Check your staging, chief.")
return 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): class SetupGameCommand(Command):
name = "setupgame" name = "setupgame"
template = "m;setupgame" template = "m;setupgame"
@ -488,6 +504,7 @@ commands = [
ShowAllTeamsCommand(), ShowAllTeamsCommand(),
SearchTeamsCommand(), SearchTeamsCommand(),
StartGameCommand(), StartGameCommand(),
StartRandomGameCommand(),
CreditCommand(), CreditCommand(),
RomanCommand(), RomanCommand(),
HelpCommand(), HelpCommand(),
@ -740,7 +757,10 @@ async def watch_game(channel, newgame, user = None, league = None):
discrim_string = league discrim_string = league
state_init["is_league"] = True state_init["is_league"] = True
elif user is not None: 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 state_init["is_league"] = False
else: else:
discrim_string = "Unclaimed game." discrim_string = "Unclaimed game."
@ -941,38 +961,41 @@ async def team_pages(msg, all_teams, search_term=None):
async def game_watcher(): async def game_watcher():
while True: while True:
try: #try:
this_array = gamesarray.copy() this_array = gamesarray.copy()
for i in range(0,len(this_array)): for i in range(0,len(this_array)):
game, channel, user, key = this_array[i] game, channel, user, key = this_array[i]
if game.over and main_controller.master_games_dic[key][1]["end_delay"] <= 9: 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" 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 if (game.inning - 1) > game.max_innings: #if extra innings
title_string += f" with {game.inning - (game.max_innings+1)} extra innings." title_string += f" with {game.inning - (game.max_innings+1)} extra innings."
else: else:
title_string += "." title_string += "."
winning_team = game.teams['home'].name if game.teams['home'].score > game.teams['away'].score else game.teams['away'].name 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" winstring = f"{game.teams['away'].score} to {game.teams['home'].score}\n"
if game.victory_lap and winning_team == game.teams['home'].name: if game.victory_lap and winning_team == game.teams['home'].name:
winstring += f"{winning_team} wins with a victory lap!" winstring += f"{winning_team} wins with a victory lap!"
elif winning_team == game.teams['home'].name: elif winning_team == game.teams['home'].name:
winstring += f"{winning_team} wins, shaming {game.teams['away'].name}!" winstring += f"{winning_team} wins, shaming {game.teams['away'].name}!"
else: else:
winstring += f"{winning_team} wins!" 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.") await channel.send(f"{user.mention}'s game just ended.")
else: else:
await channel.send("A game started from this channel just ended.") 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 = discord.Embed(color=discord.Color.dark_purple(), title=title_string)
final_embed.add_field(name="Final score:", value=winstring) final_embed.add_field(name="Final score:", value=winstring)
await channel.send(embed=final_embed) await channel.send(embed=final_embed)
gamesarray.pop(i) gamesarray.pop(i)
break break
except: #except:
print("something broke in game_watcher") #print("something broke in game_watcher")
await asyncio.sleep(6) await asyncio.sleep(6)