From d7f946333934164aa4899143bdbb05580e82033d Mon Sep 17 00:00:00 2001 From: Anton Komarev <1849174+antonkomarev@users.noreply.github.com> Date: Fri, 26 Aug 2022 08:52:51 +0300 Subject: [PATCH] Disable callbacks in ended game (#45) --- app/bot.py | 9 +++++++++ app/game.py | 3 +++ 2 files changed, 12 insertions(+) diff --git a/app/bot.py b/app/bot.py index 4244eb4..c5696ea 100644 --- a/app/bot.py +++ b/app/bot.py @@ -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) @@ -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) @@ -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: diff --git a/app/game.py b/app/game.py index 7c70315..08b935e 100644 --- a/app/game.py +++ b/app/game.py @@ -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(),