@@ -26,13 +26,13 @@ discard block |
||
| 26 | 26 | /** @var BuktopuhaBotApi */ |
| 27 | 27 | private $botApi; |
| 28 | 28 | |
| 29 | - private $config; |
|
| 29 | + private $config; |
|
| 30 | 30 | |
| 31 | 31 | public function __construct(BuktopuhaBotApi $telegramBotApi, $config, EntityManagerInterface $entityManager) |
| 32 | 32 | { |
| 33 | 33 | $this->em = $entityManager; |
| 34 | 34 | $this->botApi = $telegramBotApi; |
| 35 | - $this->config = $config; |
|
| 35 | + $this->config = $config; |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | |
@@ -100,11 +100,11 @@ discard block |
||
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * Checks if the answer is correct, and asks next question |
|
| 105 | - * |
|
| 106 | - * @param array $message |
|
| 107 | - */ |
|
| 103 | + /** |
|
| 104 | + * Checks if the answer is correct, and asks next question |
|
| 105 | + * |
|
| 106 | + * @param array $message |
|
| 107 | + */ |
|
| 108 | 108 | public function checkAnswer($message) |
| 109 | 109 | { |
| 110 | 110 | $game = $this->findGame($message); |
@@ -140,37 +140,37 @@ discard block |
||
| 140 | 140 | } else { |
| 141 | 141 | // Incorrect answer |
| 142 | 142 | $game->incorrectTries++; |
| 143 | - $hint = $game->hint; |
|
| 144 | - |
|
| 145 | - if (mb_substr_count($hint,'*','UTF-8') >= mb_strlen($hint,'UTF-8')/2) { |
|
| 146 | - //tell hint |
|
| 147 | - |
|
| 148 | - $tPos = rand(0,mb_strlen($question->a1,'UTF-8')); |
|
| 149 | - |
|
| 150 | - while($game->hint == $hint) { |
|
| 151 | - $hint = mb_substr($hint,0,$tPos-1,'UTF-8'). |
|
| 152 | - mb_substr($question->a1,$tPos,1,'UTF-8'). |
|
| 153 | - mb_substr($hint,$tPos+1,200,'UTF-8'); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - $game->hint = $hint; |
|
| 157 | - |
|
| 158 | - $this->botApi->sendMessage( |
|
| 159 | - $game->chatId, |
|
| 160 | - '<b>Hint</b>: '.$hint, |
|
| 161 | - 'html' |
|
| 162 | - ); |
|
| 163 | - |
|
| 164 | - } else { |
|
| 165 | - $this->botApi->sendMessage( |
|
| 166 | - $game->chatId, |
|
| 167 | - 'Noone answered, correct answer was: *'.$question->a1.'*', |
|
| 168 | - 'markdown' |
|
| 169 | - ); |
|
| 170 | - $this->em->persist($game); |
|
| 171 | - $this->em->flush(); |
|
| 172 | - $this->askQuestion($game); |
|
| 173 | - } |
|
| 143 | + $hint = $game->hint; |
|
| 144 | + |
|
| 145 | + if (mb_substr_count($hint,'*','UTF-8') >= mb_strlen($hint,'UTF-8')/2) { |
|
| 146 | + //tell hint |
|
| 147 | + |
|
| 148 | + $tPos = rand(0,mb_strlen($question->a1,'UTF-8')); |
|
| 149 | + |
|
| 150 | + while($game->hint == $hint) { |
|
| 151 | + $hint = mb_substr($hint,0,$tPos-1,'UTF-8'). |
|
| 152 | + mb_substr($question->a1,$tPos,1,'UTF-8'). |
|
| 153 | + mb_substr($hint,$tPos+1,200,'UTF-8'); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + $game->hint = $hint; |
|
| 157 | + |
|
| 158 | + $this->botApi->sendMessage( |
|
| 159 | + $game->chatId, |
|
| 160 | + '<b>Hint</b>: '.$hint, |
|
| 161 | + 'html' |
|
| 162 | + ); |
|
| 163 | + |
|
| 164 | + } else { |
|
| 165 | + $this->botApi->sendMessage( |
|
| 166 | + $game->chatId, |
|
| 167 | + 'Noone answered, correct answer was: *'.$question->a1.'*', |
|
| 168 | + 'markdown' |
|
| 169 | + ); |
|
| 170 | + $this->em->persist($game); |
|
| 171 | + $this->em->flush(); |
|
| 172 | + $this->askQuestion($game); |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | 175 | } |
| 176 | 176 | |
@@ -179,33 +179,33 @@ discard block |
||
| 179 | 179 | } |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - /** |
|
| 183 | - * Asks question in the game |
|
| 184 | - * |
|
| 185 | - * @param Game $game |
|
| 186 | - */ |
|
| 182 | + /** |
|
| 183 | + * Asks question in the game |
|
| 184 | + * |
|
| 185 | + * @param Game $game |
|
| 186 | + */ |
|
| 187 | 187 | |
| 188 | 188 | public function askQuestion(Game $game) |
| 189 | 189 | { |
| 190 | - $question = $this->getRandomQuestion(); |
|
| 190 | + $question = $this->getRandomQuestion(); |
|
| 191 | 191 | |
| 192 | - $question->played++; |
|
| 192 | + $question->played++; |
|
| 193 | 193 | |
| 194 | - $game->lastQuestion = $question->getId(); |
|
| 195 | - $game->lastQuestionTime = new \DateTime('now'); |
|
| 196 | - $game->incorrectTries = 0; |
|
| 197 | - $game->hint = str_repeat('*',mb_strlen($question->a1,'UTF-8')); |
|
| 194 | + $game->lastQuestion = $question->getId(); |
|
| 195 | + $game->lastQuestionTime = new \DateTime('now'); |
|
| 196 | + $game->incorrectTries = 0; |
|
| 197 | + $game->hint = str_repeat('*',mb_strlen($question->a1,'UTF-8')); |
|
| 198 | 198 | |
| 199 | - $this->em->persist($game); |
|
| 200 | - $this->em->persist($question); |
|
| 201 | - $this->em->flush(); |
|
| 199 | + $this->em->persist($game); |
|
| 200 | + $this->em->persist($question); |
|
| 201 | + $this->em->flush(); |
|
| 202 | 202 | |
| 203 | 203 | $this->botApi->sendMessage($game->chatId, '*[question]* '.$question->text.' _('.mb_strlen($question->a1,'UTF-8').' letters)_', 'markdown'); |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
| 207 | - * Gets random question from database |
|
| 208 | - * |
|
| 207 | + * Gets random question from database |
|
| 208 | + * |
|
| 209 | 209 | * @return Question |
| 210 | 210 | * @throws \Doctrine\ORM\NoResultException |
| 211 | 211 | * @throws \Doctrine\ORM\NonUniqueResultException |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | if (mb_strtoupper($question->a1, 'UTF-8') == mb_strtoupper($message['text'], 'UTF-8')) { |
| 122 | 122 | // Correct answer! |
| 123 | 123 | |
| 124 | - $user->setPoints($user->getPoints()+$question->price); |
|
| 124 | + $user->setPoints($user->getPoints() + $question->price); |
|
| 125 | 125 | $this->em->persist($user); |
| 126 | 126 | |
| 127 | 127 | $this->botApi->sendMessage( |
@@ -142,15 +142,15 @@ discard block |
||
| 142 | 142 | $game->incorrectTries++; |
| 143 | 143 | $hint = $game->hint; |
| 144 | 144 | |
| 145 | - if (mb_substr_count($hint,'*','UTF-8') >= mb_strlen($hint,'UTF-8')/2) { |
|
| 145 | + if (mb_substr_count($hint, '*', 'UTF-8') >= mb_strlen($hint, 'UTF-8') / 2) { |
|
| 146 | 146 | //tell hint |
| 147 | 147 | |
| 148 | - $tPos = rand(0,mb_strlen($question->a1,'UTF-8')); |
|
| 148 | + $tPos = rand(0, mb_strlen($question->a1, 'UTF-8')); |
|
| 149 | 149 | |
| 150 | - while($game->hint == $hint) { |
|
| 151 | - $hint = mb_substr($hint,0,$tPos-1,'UTF-8'). |
|
| 152 | - mb_substr($question->a1,$tPos,1,'UTF-8'). |
|
| 153 | - mb_substr($hint,$tPos+1,200,'UTF-8'); |
|
| 150 | + while ($game->hint == $hint) { |
|
| 151 | + $hint = mb_substr($hint, 0, $tPos - 1, 'UTF-8'). |
|
| 152 | + mb_substr($question->a1, $tPos, 1, 'UTF-8'). |
|
| 153 | + mb_substr($hint, $tPos + 1, 200, 'UTF-8'); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | $game->hint = $hint; |
@@ -194,13 +194,13 @@ discard block |
||
| 194 | 194 | $game->lastQuestion = $question->getId(); |
| 195 | 195 | $game->lastQuestionTime = new \DateTime('now'); |
| 196 | 196 | $game->incorrectTries = 0; |
| 197 | - $game->hint = str_repeat('*',mb_strlen($question->a1,'UTF-8')); |
|
| 197 | + $game->hint = str_repeat('*', mb_strlen($question->a1, 'UTF-8')); |
|
| 198 | 198 | |
| 199 | 199 | $this->em->persist($game); |
| 200 | 200 | $this->em->persist($question); |
| 201 | 201 | $this->em->flush(); |
| 202 | 202 | |
| 203 | - $this->botApi->sendMessage($game->chatId, '*[question]* '.$question->text.' _('.mb_strlen($question->a1,'UTF-8').' letters)_', 'markdown'); |
|
| 203 | + $this->botApi->sendMessage($game->chatId, '*[question]* '.$question->text.' _('.mb_strlen($question->a1, 'UTF-8').' letters)_', 'markdown'); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |