diff options
Diffstat (limited to 'src/NeonXP/BotScript.php')
-rw-r--r-- | src/NeonXP/BotScript.php | 67 |
1 files changed, 34 insertions, 33 deletions
diff --git a/src/NeonXP/BotScript.php b/src/NeonXP/BotScript.php index 9309b5a..12313d2 100644 --- a/src/NeonXP/BotScript.php +++ b/src/NeonXP/BotScript.php @@ -2,16 +2,15 @@ namespace NeonXP; -use Doctrine\Common\Cache\CacheProvider; use NeonXP\TelegramApi\Types\Location; -use \NeonXP\TelegramApi\Types\Message; -use \NeonXP\TelegramApi\Script; -use \NeonXP\TelegramApi\Script\State; -use \NeonXP\TelegramApi\Script\Conditions\isText; -use \NeonXP\TelegramApi\Script\Conditions\isLocation; -use \NeonXP\TelegramApi\Script\Conditions\isMatch; -use \NeonXP\TelegramApi\Script\Conditions\isAnyText; -use \NeonXP\TelegramApi\Telegram; +use NeonXP\TelegramApi\Types\Message; +use NeonXP\TelegramApi\Script; +use NeonXP\TelegramApi\Script\State; +use NeonXP\TelegramApi\Script\Conditions\isText; +use NeonXP\TelegramApi\Script\Conditions\isLocation; +use NeonXP\TelegramApi\Script\Conditions\isMatch; +use NeonXP\TelegramApi\Script\Conditions\isAnyText; +use NeonXP\TelegramApi\Telegram; class BotScript { @@ -19,7 +18,8 @@ class BotScript { $saveLink = function (Message $message, Telegram $telegram) { $telegram->getCache()->save("link_{$message->getChat()->getId()}", $message->getText()); - $telegram->getMethods()->sendMessage($message->getChat(), 'Ок, записал: ' . $message->getText()); + $link = $telegram->getCache()->fetch("link_{$message->getChat()->getId()}"); + $telegram->getMethods()->sendMessage($message->getChat(), 'Ок, записал: '.$link); return State::INITIAL; }; @@ -38,7 +38,7 @@ class BotScript try { $result = $dozorApi->sendCode($message->getChat(), $code); } catch (\Exception $e) { - $telegram->getMethods()->sendMessage($message->getChat(), 'Ошибка сети', true); + $telegram->getMethods()->sendMessage($message->getChat(), 'Ошибка сети: '.$e->getMessage(), true); } if ($result) { $telegram->getMethods()->sendMessage($message->getChat(), $result, true); @@ -67,15 +67,15 @@ class BotScript $getDb = function (Message $message, Telegram $telegram) { $text = trim(substr($message->getText(), 1)); $db = [ - '1' => ['А', 'Я', 'A', 'Z', '00000', '. -'], - '2' => ['Б', 'Ю', 'B', 'Y', '00001', '- . . .'], - '3' => ['В', 'Э', 'C', 'X', '00010', '. - -'], - '4' => ['Г', 'Ь', 'D', 'W', '00011', '- - .'], - '5' => ['Д', 'Ы', 'E', 'V', '00100', '- . .'], - '6' => ['Е', 'Ъ', 'F', 'U', '00101', '.'], - '7' => ['Ё', 'Щ', 'G', 'T', '00101', '.'], - '8' => ['Ж', 'Ш', 'H', 'S', '00110', '. . . -'], - '9' => ['З', 'Ч', 'I', 'R', '00111', '- - . .'], + '1' => ['А', 'Я', 'A', 'Z', '00000', '. -'], + '2' => ['Б', 'Ю', 'B', 'Y', '00001', '- . . .'], + '3' => ['В', 'Э', 'C', 'X', '00010', '. - -'], + '4' => ['Г', 'Ь', 'D', 'W', '00011', '- - .'], + '5' => ['Д', 'Ы', 'E', 'V', '00100', '- . .'], + '6' => ['Е', 'Ъ', 'F', 'U', '00101', '.'], + '7' => ['Ё', 'Щ', 'G', 'T', '00101', '.'], + '8' => ['Ж', 'Ш', 'H', 'S', '00110', '. . . -'], + '9' => ['З', 'Ч', 'I', 'R', '00111', '- - . .'], '10' => ['И', 'Ц', 'J', 'Q', '01000', '. .'], '11' => ['Й', 'Х', 'K', 'P', '01001', '. - - -'], '12' => ['К', 'Ф', 'L', 'O', '01010', '- . -'], @@ -102,48 +102,49 @@ class BotScript '33' => ['Я', 'А', ' ', ' ', '11111', '. - . -'], ]; $result = 'Непонятно :('; - $header = ' № | А | Я | A | Z | Двоичн | Морзе ' . PHP_EOL . '____________________________________'; + $header = ' № | А | Я | A | Z | Двоич | Морзе '.PHP_EOL. + '___________________________________'; if ($text == '?') { $result = ''; foreach ($db as $key => $value) { if ($key < 10) { - $result .= "0$key | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]" . PHP_EOL; + $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; + $result .= "$key | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]".PHP_EOL; } } } elseif (is_numeric($text) && (isset($db[$text]))) { $value = $db[$text]; if ($text < 10) { - $result = "0$text | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]" . PHP_EOL; + $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; + $result = "$text | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]".PHP_EOL; } } else { $result = ''; - for ($i = 0; $i < mb_strlen($text, 'utf8'); $i++) { + for ($i = 0; $i < mb_strlen($text, 'utf8'); ++$i) { $char = mb_substr($text, $i, 1, 'utf8'); foreach ($db as $key => $value) { if (mb_strtolower($value[0], 'utf8') == mb_strtolower($char)) { if ($key < 10) { - $result .= "0$key | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]" . PHP_EOL; + $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; + $result .= "$key | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]".PHP_EOL; } } if (strtolower($value[2]) == strtolower($char)) { if ($key < 10) { - $result .= "0$key | $value[0] | $value[1] | $value[2] | $value[3] | $value[4] | $value[5]" . PHP_EOL; + $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; + $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 @@ -161,11 +162,11 @@ class BotScript action(new isText('/link'), $showLink)-> action(new isText('/setlink'), [ 'Пришлите ссылку с пином /cancel', - 'STATE_SET_LINK' + 'STATE_SET_LINK', ])-> action(new isText('/pause'), [ 'Замер. /resume для возврата', - 'STATE_PAUSE' + 'STATE_PAUSE', ])-> action(new isMatch('/^\!.+?$/i'), $sendCode)-> action(new isMatch('/^\?.+?$/i'), $getDb)-> |