From 78ca15a1f84afe3969811180fe6ce643a2352a23 Mon Sep 17 00:00:00 2001 From: Alexander NeonXP Kiryukhin Date: Fri, 27 May 2016 16:30:23 +0300 Subject: Added DB search 4 --- src/NeonXP/BotScript.php | 103 ++++++++++++++++++++++++++--------------------- 1 file changed, 56 insertions(+), 47 deletions(-) diff --git a/src/NeonXP/BotScript.php b/src/NeonXP/BotScript.php index 0e7c6e0..55e16a6 100644 --- a/src/NeonXP/BotScript.php +++ b/src/NeonXP/BotScript.php @@ -48,70 +48,79 @@ class BotScript $getDb = function (Message $message, Telegram $telegram) { $text = trim(substr($message->getText(), 1)); $db = [ - '1' => ['А', 'А', 'Я', 'Я', 'A', 'Z', '1', '. -'], - '2' => ['Б', 'Б', 'Ю', 'Ю', 'B', 'Y', '10', '- . . .'], - '3' => ['В', 'В', 'Э', 'Э', 'C', 'X', '11', '. - -'], - '4' => ['Г', 'Г', 'Ь', 'Ь', 'D', 'W', '100', '- - .'], - '5' => ['Д', 'Д', 'Ы', 'Ы', 'E', 'V', '101', '- . .'], - '6' => ['Е', 'Е', 'Ъ', 'Ъ', 'F', 'U', '110', '.'], - '7' => ['Ё', 'Ж', 'Щ', 'Щ', 'G', 'T', '111', '.'], - '8' => ['Ж', 'З', 'Ш', 'Ш', 'H', 'S', '1000', '. . . -'], - '9' => ['З', 'И', 'Ч', 'Ч', 'I', 'R', '1001', '- - . .'], - '10' => ['И', 'Й', 'Ц', 'Ц', 'J', 'Q', '1010', '. .'], - '11' => ['Й', 'К', 'Х', 'Х', 'K', 'P', '1011', '. - - -'], - '12' => ['К', 'Л', 'Ф', 'Ф', 'L', 'O', '1100', '- . -'], - '13' => ['Л', 'М', 'У', 'У', 'M', 'N', '1101', '. - . .'], - '14' => ['М', 'Н', 'Т', 'Т', 'N', 'M', '1110', '- -'], - '15' => ['Н', 'О', 'С', 'С', 'O', 'L', '1111', '- .'], - '16' => ['О', 'П', 'Р', 'Р', 'P', 'K', '10000', '- - -'], - '17' => ['П', 'Р', 'П', 'П', 'Q', 'J', '10001', '. - - .'], - '18' => ['Р', 'С', 'О', 'О', 'R', 'I', '10010', '. - .'], - '19' => ['С', 'Т', 'Н', 'Н', 'S', 'H', '10011', '. . .'], - '20' => ['Т', 'У', 'М', 'М', 'T', 'G', '10100', '-'], - '21' => ['У', 'Ф', 'Л', 'Л', 'U', 'F', '10101', '. . -'], - '22' => ['Ф', 'Х', 'К', 'К', 'V', 'E', '10110', '. . - .'], - '23' => ['Х', 'Ц', 'Й', 'Й', 'W', 'D', '10111', '. . . .'], - '24' => ['Ц', 'Ч', 'И', 'И', 'X', 'C', '11000', '- . - .'], - '25' => ['Ч', 'Ш', 'З', 'З', 'Y', 'B', '11001', '- - - .'], - '26' => ['Ш', 'Щ', 'Ж', 'Ж', 'Z', 'A', '11010', '- - - -'], - '27' => ['Щ', 'Ъ', 'Ё', 'Е', ' ', ' ', '11011', '- - . -'], - '28' => ['Ъ', 'Ы', 'Е', 'Д', ' ', ' ', '11100', '- - . - -'], - '29' => ['Ы', 'Ь', 'Д', 'Г', ' ', ' ', '11101', '- . - -'], - '30' => ['Ь', 'Э', 'Г', 'В', ' ', ' ', '11110 ', '- . . -'], - '31' => ['Э', 'Ю', 'В', 'Б', ' ', ' ', '11111 ', '. . - . .'], - '32' => ['Ю', 'Я', 'Б', 'А', ' ', ' ', '100000', '. . - -'], - '33' => ['Я', 'А', ' ', ' ', ' ', ' ', '100001', '. - . -'], + '1' => ['А', 'А', 'A', 'Z', '000001', '. -'], + '2' => ['Б', 'Б', 'B', 'Y', '000010', '- . . .'], + '3' => ['В', 'В', 'C', 'X', '000011', '. - -'], + '4' => ['Г', 'Г', 'D', 'W', '000100', '- - .'], + '5' => ['Д', 'Д', 'E', 'V', '000101', '- . .'], + '6' => ['Е', 'Е', 'F', 'U', '000110', '.'], + '7' => ['Ё', 'Ж', 'G', 'T', '000111', '.'], + '8' => ['Ж', 'З', 'H', 'S', '001000', '. . . -'], + '9' => ['З', 'И', 'I', 'R', '001001', '- - . .'], + '10' => ['И', 'Й', 'J', 'Q', '001010', '. .'], + '11' => ['Й', 'К', 'K', 'P', '001011', '. - - -'], + '12' => ['К', 'Л', 'L', 'O', '001100', '- . -'], + '13' => ['Л', 'М', 'M', 'N', '001101', '. - . .'], + '14' => ['М', 'Н', 'N', 'M', '001110', '- -'], + '15' => ['Н', 'О', 'O', 'L', '001111', '- .'], + '16' => ['О', 'П', 'P', 'K', '010000', '- - -'], + '17' => ['П', 'Р', 'Q', 'J', '010001', '. - - .'], + '18' => ['Р', 'С', 'R', 'I', '010010', '. - .'], + '19' => ['С', 'Т', 'S', 'H', '010011', '. . .'], + '20' => ['Т', 'У', 'T', 'G', '010100', '-'], + '21' => ['У', 'Ф', 'U', 'F', '010101', '. . -'], + '22' => ['Ф', 'Х', 'V', 'E', '010110', '. . - .'], + '23' => ['Х', 'Ц', 'W', 'D', '010111', '. . . .'], + '24' => ['Ц', 'Ч', 'X', 'C', '011000', '- . - .'], + '25' => ['Ч', 'Ш', 'Y', 'B', '011001', '- - - .'], + '26' => ['Ш', 'Щ', 'Z', 'A', '011010', '- - - -'], + '27' => ['Щ', 'Ъ', ' ', ' ', '011011', '- - . -'], + '28' => ['Ъ', 'Ы', ' ', ' ', '011100', '- - . - -'], + '29' => ['Ы', 'Ь', ' ', ' ', '011101', '- . - -'], + '30' => ['Ь', 'Э', ' ', ' ', '011110 ', '- . . -'], + '31' => ['Э', 'Ю', ' ', ' ', '011111 ', '. . - . .'], + '32' => ['Ю', 'Я', ' ', ' ', '100000', '. . - -'], + '33' => ['Я', 'А', ' ', ' ', '100001', '. - . -'], ]; $result = 'Непонятно :('; - $header = '*№* | _АлфЁ_ | *Алф* | _ОбрЁ_ | *Обр* | _Alp_ | *Rev* | _Двоич_ | Морзе'; + $header = ' № | А | Я | A | Z | Двоичн | Морзе'; if ($text == '$') { $result = ''; foreach ($db as $key => $value) { - $result .= sprintf('*%d* | _%s_ | *%s* | _%s_ | *%s* | _%s_ | *%s* | _%s_ | *%s*', - $key, $value[0],$value[1],$value[2],$value[3], $value[4],$value[5], $value[6],$value[7] - ) . PHP_EOL; + if ($key < 10) { + $result .= "0$key | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]" . PHP_EOL; + } else { + $result .= "$key | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]" . PHP_EOL; + } } } elseif (is_numeric($text) && (isset($db[$text]))) { - $result = sprintf('*%d* | _%s_ | *%s* | _%s_ | *%s* | _%s_ | *%s* | _%s_ | *%s*', - $text, $db[$text][0],$db[$text][1],$db[$text][2],$db[$text][3], $db[$text][4],$db[$text][5], $db[$text][6],$db[$text][7] - ); + $value = $db[$text]; + if ($text < 10) { + $result = "0$text | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]" . PHP_EOL; + } else { + $result = "$text | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]" . PHP_EOL; + } } else { foreach ($db as $key => $value) { if (mb_strtolower($value[0], 'utf8') == mb_strtolower($text)) { - $result = sprintf('*%d* | _%s_ | *%s* | _%s_ | *%s* | _%s_ | *%s* | _%s_ | *%s*', - $key, $value[0],$value[1],$value[2],$value[3], $value[4],$value[5], $value[6],$value[7] - ); + if ($key < 10) { + $result = "0$key | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]" . PHP_EOL; + } else { + $result = "$key | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]" . PHP_EOL; + } } if (strtolower($value[4]) == strtolower($text)) { - $result = sprintf('*%d* | _%s_ | *%s* | _%s_ | *%s* | _%s_ | *%s* | _%s_ | *%s*', - $key, $value[0],$value[1],$value[2],$value[3], $value[4],$value[5], $value[6],$value[7] - ); + if ($key < 10) { + $result = "0$key | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]" . PHP_EOL; + } else { + $result = "$key | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]" . PHP_EOL; + } } } } if ($result) { - $telegram->getMethods()->sendMessage($message->getChat(), $header . PHP_EOL . $result, true); + $telegram->getMethods()->sendMessage($message->getChat(), '```' . $header . PHP_EOL . $result . '```', true); } return State::INITIAL; //Set initial state -- cgit v1.2.3