Skip to content

Commit

Permalink
Disable callbacks in ended game (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonkomarev authored Aug 26, 2022
1 parent 9756930 commit d7f9463
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ async def on_discussion_vote_click(chat: Chat, callback_query: CallbackQuery, ma
if game_session.phase not in GameSession.PHASE_DISCUSSION:
return await callback_query.answer(text="Can't vote not in " + GameSession.PHASE_DISCUSSION + " phase")

if not game_session.game.is_active():
return await callback_query.answer(text="Game already ended")

game_session.add_discussion_vote(callback_query.src["from"], vote)
await game_registry.update_game_session(game_session)

Expand All @@ -150,6 +153,9 @@ async def on_estimation_vote_click(chat: Chat, callback_query: CallbackQuery, ma
if game_session.phase not in GameSession.PHASE_ESTIMATION:
return await callback_query.answer(text="Can't vote not in " + GameSession.PHASE_ESTIMATION + " phase")

if not game_session.game.is_active():
return await callback_query.answer(text="Game already ended")

game_session.add_estimation_vote(callback_query.src["from"], vote)
await game_registry.update_game_session(game_session)

Expand All @@ -171,6 +177,9 @@ async def on_facilitator_operation_click(chat: Chat, callback_query: CallbackQue
if callback_query.src["from"]["id"] != game_session.facilitator.id:
return await callback_query.answer(text="Operation `{}` is available only for facilitator".format(operation))

if not game_session.game.is_active():
return await callback_query.answer(text="Game already ended")

if operation in GameSession.OPERATION_START_ESTIMATION:
await run_operation_start_estimation(chat, game_session)
elif operation in GameSession.OPERATION_END_ESTIMATION:
Expand Down
3 changes: 3 additions & 0 deletions app/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def __init__(self, chat_id: int, facilitator_message_id: int, name: str, facilit
def end(self):
self.status = self.STATUS_ENDED

def is_active(self) -> bool:
return self.status == self.STATUS_STARTED

def render_system_message(self):
return {
"text": self.render_system_message_text(),
Expand Down

0 comments on commit d7f9463

Please sign in to comment.