From 34916acaa24ade10d6124bf6eafa3f9facc1a329 Mon Sep 17 00:00:00 2001 From: Kirill Kholodilin Date: Mon, 21 Nov 2016 18:41:13 +0100 Subject: [PATCH] + Add stop command --- src/Chrl/AppBundle/GameAction/NextAction.php | 18 +++++++------ src/Chrl/AppBundle/GameAction/StopAction.php | 27 ++++++++++++++++++++ 2 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 src/Chrl/AppBundle/GameAction/StopAction.php diff --git a/src/Chrl/AppBundle/GameAction/NextAction.php b/src/Chrl/AppBundle/GameAction/NextAction.php index 7f4ffb9..e157c7f 100644 --- a/src/Chrl/AppBundle/GameAction/NextAction.php +++ b/src/Chrl/AppBundle/GameAction/NextAction.php @@ -8,13 +8,15 @@ public function run($message, $user) { $game = $this->gameService->findGame($message); - $this->botApi->sendMessage( - $game->chatId, - 'Ok, changing question.', - 'markdown' - ); - $this->gameService->em->persist($game); - $this->gameService->em->flush(); - $this->gameService->askQuestion($game); + if ($game->status == 1) { + $this->botApi->sendMessage( + $game->chatId, + 'Ok, changing question.', + 'markdown' + ); + $this->gameService->em->persist($game); + $this->gameService->em->flush(); + $this->gameService->askQuestion($game); + } } } diff --git a/src/Chrl/AppBundle/GameAction/StopAction.php b/src/Chrl/AppBundle/GameAction/StopAction.php new file mode 100644 index 0000000..e320824 --- /dev/null +++ b/src/Chrl/AppBundle/GameAction/StopAction.php @@ -0,0 +1,27 @@ +gameService->findGame($message); + + if ($game->status == 1) { + $game->status = 0; + + $this->gameService->em->persist($game); + $this->gameService->em->flush(); + $this->botApi->sendMessage($message['chat']['id'], 'The game has stopped!'); + } else { + $this->botApi->sendMessage( + $message['chat']['id'], + 'The game is not running...Use /start command to run game.' + ); + } + } +}