summaryrefslogtreecommitdiff
path: root/src/NeonXP/BotScript.php
diff options
context:
space:
mode:
authorAlexander NeonXP Kiryukhin <frei@neonxp.info>2016-05-27 16:02:56 +0300
committerAlexander NeonXP Kiryukhin <frei@neonxp.info>2016-05-27 16:02:56 +0300
commit7dc916517ba8574eff45e095b071ae10e8394617 (patch)
tree2007f2eb7ad7ece3ddd6f4740a7cbbf4b612d894 /src/NeonXP/BotScript.php
parent425dbf1d6a61584a785c313b579e445c01981163 (diff)
Added DB search
Diffstat (limited to 'src/NeonXP/BotScript.php')
-rw-r--r--src/NeonXP/BotScript.php76
1 files changed, 68 insertions, 8 deletions
diff --git a/src/NeonXP/BotScript.php b/src/NeonXP/BotScript.php
index 3e94d1b..6dfeb9e 100644
--- a/src/NeonXP/BotScript.php
+++ b/src/NeonXP/BotScript.php
@@ -24,26 +24,85 @@ class BotScript
$showLink = function (Message $message, Telegram $telegram) {
$link = $telegram->getCache()->fetch("link_{$message->getChat()->getId()}");
if (!$link) {
- $link = 'Ссылка не задана! Используй /setlink';
+ $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));
+ $code = trim(substr($message->getText(), 1));
$result = false;
try {
$result = $dozorApi->sendCode($message->getChat(), $code);
- }catch (\Exception $e) {
+ } catch (\Exception $e) {
$telegram->getMethods()->sendMessage($message->getChat(), 'Ошибка сети', true);
}
if ($result) {
- $telegram->getMethods()->sendMessage($message->getChat(), $result, true);
+ $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 (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 ($value[0] == $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(), $result, true);
+ }
+
+ return State::INITIAL; //Set initial state
+ };
+
$goBack = function (Message $message, Telegram $telegram) {
return State::INITIAL;
};
@@ -63,15 +122,16 @@ class BotScript
'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)->
+ action(new isText('/cancel'), $goBack)->
+ action(new isAnyText(), $saveLink)->
end()->
state('STATE_PAUSE')->
- action(new isText('/resume'), ['Я вернулся!', State::INITIAL])->
- action(new isAnyText(), $pause)->
+ action(new isText('/resume'), ['Я вернулся!', State::INITIAL])->
+ action(new isAnyText(), $pause)->
end();
}
}