getCache()->save("link_{$message->getChat()->getId()}", $message->getText()); $telegram->getMethods()->sendMessage($message->getChat(), 'Ок, записал: ' . $message->getText()); return State::INITIAL; }; $showLink = function (Message $message, Telegram $telegram) { $link = $telegram->getCache()->fetch("link_{$message->getChat()->getId()}"); if (!$link) { $link = 'Ссылка не задана! Используй /setlink'; } $telegram->getMethods()->sendMessage($message->getChat(), $link); return State::INITIAL; }; $sendCode = function (Message $message, Telegram $telegram) use ($dozorApi) { $code = trim(substr($message->getText(), 1)); $result = false; try { $result = $dozorApi->sendCode($message->getChat(), $code); } catch (\Exception $e) { $telegram->getMethods()->sendMessage($message->getChat(), 'Ошибка сети', true); } if ($result) { $telegram->getMethods()->sendMessage($message->getChat(), $result, true); } return State::INITIAL; //Set initial state }; $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', '. - . -'], ]; $result = 'Непонятно :('; if ($text == '$') { $result = ''; foreach ($db as $key => $value) { $result .= sprintf('*%d* АлфЁ *%s* Алф *%s* ОбрЁ *%s* Обр *%s* Alph *%s* RvrsAlph *%s* Двоич *%s* Морз *%s*', $key, $value[0],$value[1],$value[2],$value[3], $value[4],$value[5], $value[6],$value[7] ) . PHP_EOL; } } elseif (is_numeric($text) && (isset($db[$text]))) { $result = sprintf('*%d* АлфЁ *%s* Алф *%s* ОбрЁ *%s* Обр *%s* Alph *%s* RvrsAlph *%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] ); } else { foreach ($db as $key => $value) { if (mb_strtolower($value[0], 'utf8') == mb_strtolower($text)) { $result = sprintf('*%d* АлфЁ *%s* Алф *%s* ОбрЁ *%s* Обр *%s* Alph *%s* RvrsAlph *%s* Двоич *%s* Морз *%s*', $key, $value[0],$value[1],$value[2],$value[3], $value[4],$value[5], $value[6],$value[7] ); } if (strtolower($value[4]) == strtolower($text)) { $result = sprintf('*%d* АлфЁ *%s* Алф *%s* ОбрЁ *%s* Обр *%s* Alph *%s* RvrsAlph *%s* Двоич *%s* Морз *%s*', $key, $value[0],$value[1],$value[2],$value[3], $value[4],$value[5], $value[6],$value[7] ); } } } if ($result) { $telegram->getMethods()->sendMessage($message->getChat(), '```' . PHP_EOL . $result . PHP_EOL . '```', true); } return State::INITIAL; //Set initial state }; $goBack = function (Message $message, Telegram $telegram) { return State::INITIAL; }; $pause = function (Message $message, Telegram $telegram) { return 'STATE_PAUSE'; }; return (new Script($telegram))-> state(State::INITIAL)-> //Start initial state action(new isText('/link'), $showLink)-> action(new isText('/setlink'), [ 'Пришлите ссылку с пином /cancel', 'STATE_SET_LINK' ])-> action(new isText('/pause'), [ 'Замер. /resume для возврата', 'STATE_PAUSE' ])-> action(new isMatch('/^\!.+?$/i'), $sendCode)-> action(new isMatch('/^\$.+?$/i'), $getDb)-> action(new isAnyText(), $goBack)-> end()-> state('STATE_SET_LINK')-> action(new isText('/cancel'), $goBack)-> action(new isAnyText(), $saveLink)-> end()-> state('STATE_PAUSE')-> action(new isText('/resume'), ['Я вернулся!', State::INITIAL])-> action(new isAnyText(), $pause)-> end(); } }