added m;randomgame
This commit is contained in:
parent
92cd4a1858
commit
a2a6e9d7bb
5
games.py
5
games.py
|
@ -171,6 +171,11 @@ 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):
|
||||||
|
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)
|
return (len(self.lineup) >= 1 and len(self.rotation) > 0)
|
||||||
|
|
||||||
def prepare_for_save(self):
|
def prepare_for_save(self):
|
||||||
|
|
|
@ -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,6 +757,9 @@ 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:
|
||||||
|
if isinstance(user, str):
|
||||||
|
discrim_string = f"Started by {user}"
|
||||||
|
else:
|
||||||
discrim_string = f"Started by {user.name}"
|
discrim_string = f"Started by {user.name}"
|
||||||
state_init["is_league"] = False
|
state_init["is_league"] = False
|
||||||
else:
|
else:
|
||||||
|
@ -941,7 +961,7 @@ 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]
|
||||||
|
@ -962,6 +982,9 @@ async def game_watcher():
|
||||||
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.")
|
||||||
|
@ -971,8 +994,8 @@ async def game_watcher():
|
||||||
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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user