Skip to content

Commit

Permalink
+ Add stop command
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill Kholodilin committed Nov 21, 2016
1 parent 4766574 commit 34916ac
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/Chrl/AppBundle/GameAction/NextAction.php
Expand Up @@ -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);
}
}
}
27 changes: 27 additions & 0 deletions src/Chrl/AppBundle/GameAction/StopAction.php
@@ -0,0 +1,27 @@
<?php

namespace Chrl\AppBundle\GameAction;

use Chrl\AppBundle\Entity\Game;

class StopAction extends BaseGameAction implements GameActionInterface
{
public function run($message, $user)
{
/** @var Game $game */
$game = $this->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.'
);
}
}
}

0 comments on commit 34916ac

Please sign in to comment.