Branch addition #1
@ -12,42 +12,20 @@ from game.process_guess import ProcessGuess
|
|||||||
|
|
||||||
|
|
||||||
class EndGameManager(BaseGameManager):
|
class EndGameManager(BaseGameManager):
|
||||||
"""Commands that run at the end of a game"""
|
"""Commands that run at the end of a play"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.commands.append(("resolve", self.stop))
|
self.commands.append(("resolve", self.stop))
|
||||||
|
|
||||||
def __stop_args__(self):
|
|
||||||
pieces = self.message.content.split()
|
|
||||||
|
|
||||||
if len(pieces) == 2:
|
|
||||||
return pieces[1], False, None, None
|
|
||||||
|
|
||||||
if len(pieces) == 4:
|
|
||||||
return pieces[1], True, pieces[2], pieces[3]
|
|
||||||
|
|
||||||
return None, False, None, None
|
|
||||||
|
|
||||||
async def update_pitch_value(self):
|
async def update_pitch_value(self):
|
||||||
"""Update game state database for closing arguments"""
|
"""Update game state database for closing arguments"""
|
||||||
# Determine arguments
|
pitch_value = self.message.content.split()[1]
|
||||||
pitch_value, has_batter, batter_id, batter_guess = self.__stop_args__()
|
|
||||||
if not pitch_value:
|
if not pitch_value:
|
||||||
return await self.message.channel.send(
|
return await self.message.channel.send(
|
||||||
f"Invalid command <@{ str(self.message.author.id) }>!"
|
f"Invalid command <@{ str(self.message.author.id) }>!"
|
||||||
)
|
)
|
||||||
|
|
||||||
if has_batter:
|
|
||||||
player_id = batter_id[3:]
|
|
||||||
player_name = await self.discord.get_user(int(player_id).name)
|
|
||||||
Guess.create(
|
|
||||||
game_id=self.game.game_id,
|
|
||||||
player_id=player_id,
|
|
||||||
player_name=player_name,
|
|
||||||
guess=int(batter_guess),
|
|
||||||
).save()
|
|
||||||
|
|
||||||
# Save the pitch value
|
# Save the pitch value
|
||||||
Game.update(
|
Game.update(
|
||||||
{
|
{
|
||||||
@ -76,7 +54,7 @@ class EndGameManager(BaseGameManager):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Discard the game if there weren't enough players
|
# Discard the game if there weren't enough players
|
||||||
if guess_count < 3:
|
if guess_count < 2:
|
||||||
self.game = None
|
self.game = None
|
||||||
self.is_running = False
|
self.is_running = False
|
||||||
return await self.message.channel.send(
|
return await self.message.channel.send(
|
||||||
@ -85,7 +63,7 @@ class EndGameManager(BaseGameManager):
|
|||||||
|
|
||||||
message = (
|
message = (
|
||||||
"Closed this play! Here are the results\n"
|
"Closed this play! Here are the results\n"
|
||||||
+ "PLAYER | GUESS | DIFFERENCE | POINTS GAINED | TOTAL POINTS\n"
|
+ "__PLAYER | GUESS | DIFFERENCE | POINTS GAINED | TOTAL POINTS__\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
pitch_value = await self.update_pitch_value()
|
pitch_value = await self.update_pitch_value()
|
||||||
|
Loading…
Reference in New Issue
Block a user