Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable callbacks in ended game #45

Merged
merged 1 commit into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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