1 | <?php |
||
13 | class UpdateReceiver implements UpdateReceiverInterface |
||
14 | { |
||
15 | |||
16 | private $config; |
||
17 | private $telegramBotApi; |
||
18 | private $entityManager; |
||
19 | |||
20 | private $gameService; |
||
21 | private $commandPool; |
||
22 | |||
23 | public function __construct( |
||
37 | |||
38 | public function handleUpdate(Update $update) |
||
39 | { |
||
40 | $message = json_decode(json_encode($update->message), true); |
||
41 | file_put_contents('/tmp/messages.tg.bot', json_encode($message), FILE_APPEND); |
||
42 | |||
43 | $user = $this->gameService->getCurrentUser($message); |
||
44 | |||
45 | |||
46 | if (isset($message['text'])) { |
||
47 | $gameAction = $this->commandPool->setGameService($this->gameService)->findAction($message); |
||
48 | |||
49 | $msg = new Message(); |
||
50 | $msg->user = $user; |
||
51 | $msg->date = new \DateTime("now"); |
||
52 | $msg->text = $message['text']; |
||
53 | $msg->game = $this->gameService->findGame($message); |
||
54 | |||
55 | $this->gameService->em->persist($msg); |
||
56 | $this->gameService->em->flush(); |
||
57 | |||
58 | if (!$gameAction instanceof GameActionInterface) { |
||
59 | $this->gameService->checkAnswer($message); |
||
60 | return; |
||
61 | } |
||
62 | |||
63 | $gameAction->run($message, $user); |
||
64 | } else { |
||
65 | // handle possible joins/lefts |
||
66 | $this->handleJoin($message); |
||
67 | } |
||
68 | } |
||
69 | |||
70 | public function handleJoin($message) |
||
87 | } |
||
88 |